0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Initial likes wire up

This commit is contained in:
Fabien O'Carroll 2024-09-05 21:51:46 +07:00
parent fb0f7d284a
commit bafe74e451

View file

@ -141,13 +141,24 @@ const FeedItem: React.FC<FeedItemProps> = ({actor, object, layout, type, last})
const date = new Date(object?.published ?? new Date());
const [isClicked, setIsClicked] = useState(false);
const [isLiked, setIsLiked] = useState(false);
const [isLiked, setIsLiked] = useState(object.liked);
const handleLikeClick = (event: React.MouseEvent<HTMLElement> | undefined) => {
const handleLikeClick = async (event: React.MouseEvent<HTMLElement> | undefined) => {
event?.stopPropagation();
setIsClicked(true);
let req;
if (!isLiked) {
req = fetch(`/.ghost/activitypub/actions/like/${encodeURIComponent(object.id)}`, {
method: 'POST'
});
} else {
req = fetch(`/.ghost/activitypub/actions/unlike/${encodeURIComponent(object.id)}`, {
method: 'POST'
});
}
await req;
setIsLiked(!isLiked);
setTimeout(() => setIsClicked(false), 300); // Reset the animation class after 300ms
setIsClicked(false); // Reset the animation class after request completed
};
let author = actor;