Created
January 7, 2021 21:15
-
-
Save tfiechowski/9692d6196d9f3f9ea64ac1e8d3edd0c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function PhotosList() { | |
const onUpdate = useCallback(() => { | |
return new Promise((resolve) => | |
setTimeout(resolve, getRandomBetween(1500, 2000)) | |
); | |
}, []); | |
const { photos, updatePhotos } = usePhotos({ | |
photos: DEFAULT_PHOTOS, | |
onUpdate, | |
}); | |
function handleLike(photoId) { | |
updatePhotos([{ id: photoId, liked: true }]); | |
} | |
function handleUnlike(photoId) { | |
updatePhotos([{ id: photoId, liked: false }]); | |
} | |
return ( | |
<PhotoGrid> | |
{photos.map((photo) => ( | |
<PhotoWrapper key={photo.id}> | |
<Photo src={photo.src}></Photo> | |
{photo.locked ? ( | |
<UpdatingButton /> | |
) : photo.liked ? ( | |
<UnlikeButton onUnlike={() => handleUnlike(photo.id)} /> | |
) : ( | |
<LikeButton onLike={() => handleLike(photo.id)}>Like</LikeButton> | |
)} | |
</PhotoWrapper> | |
))} | |
</PhotoGrid> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment