Skip to content

Commit

Permalink
Merge pull request #589 from bounswe/FRONTEND-588
Browse files Browse the repository at this point in the history
feat(frontend): persist is_liked information on refresh
  • Loading branch information
yunusemreozdemir authored Nov 23, 2024
2 parents 036ce67 + f2cb5cc commit 1a0e9e6
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions frontend/src/components/common/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const convertPostResponseToPost = (postResponse: PostResponse): Post => {
engagement: {
likes: postResponse.like_count,
comments: 0,
is_liked: postResponse.is_liked,
},
comments: [],
};
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/post/compose-post-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export default function ComposePostForm() {
tags={[...selectedTags, ...(diffTag ? [diffTag] : [])]}
likeCount={0}
timePassed="Just now"
initialIsLiked={false}
/>
</ModalContent>
</Modal>
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/post/post-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Props = {
timePassed: string;
likeCount: number;
tags?: string[];
initialIsLiked: boolean;
};

export default function PostCard({
Expand All @@ -48,9 +49,10 @@ export default function PostCard({
timePassed,
likeCount,
tags,
initialIsLiked,
}: Props) {
const [isExpanded, setIsExpanded] = useState(false);
const [isLiked, setIsLiked] = useState(false);
const [isLiked, setIsLiked] = useState(initialIsLiked);
const [likes, setLikes] = useState(likeCount);
const [isBookmarked, setIsBookmarked] = useState(false); // Example state for bookmark
const navigate = useNavigate();
Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/forum.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export default function Forum() {
timePassed={post.post.timestamp}
likeCount={post.engagement.likes}
tags={post.post.tags}
initialIsLiked={post.engagement.is_liked}
/>
</Suspense>
))}
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/pages/post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default function Post() {
timePassed={post.post.timestamp}
likeCount={post.engagement.likes}
tags={post.post.tags}
initialIsLiked={post.engagement.is_liked}
/>
</Suspense>
)}
Expand All @@ -69,6 +70,7 @@ export default function Post() {
content={comment.comment}
timePassed={comment.timestamp}
likeCount={comment.likes}
initialIsLiked={comment.is_liked}
/>
</Suspense>
))}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export default function Profile() {
timePassed={post.post.timestamp}
likeCount={post.engagement.likes}
tags={post.post.tags}
initialIsLiked={post.engagement.is_liked}
/>
</Suspense>
);
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type Comment = {
comment: string;
timestamp: string;
likes: number;
is_liked: boolean;
};

export type Post = {
Expand All @@ -25,6 +26,7 @@ export type Comment = {
engagement: {
likes: number;
comments: number;
is_liked: boolean;
};
comments: Comment[];
};
Expand All @@ -37,6 +39,7 @@ export type Comment = {
like_count: number;
tags: string[];
title: string;
is_liked: boolean;
};

export type Quiz = {
Expand Down

0 comments on commit 1a0e9e6

Please sign in to comment.