Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 8
fix:like-not-working#675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
fix:like-not-working #675
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7e5fcc0
fix:like-not-working
grv-saini-20 8071f71
fix:code rabbit suggestion
grv-saini-20 3ab6d87
fix: added small button interaction for like button
grv-saini-20 3e91348
fix: removed comment icon because there is not handler attched to it …
grv-saini-20 f27086f
fix: code rabbit suggestion
grv-saini-20 85df461
fix: code rabbit suggestion
grv-saini-20 20267c3
fix: show comments and send comment
grv-saini-20 fefebb9
fix: added a try catch block for create comments
grv-saini-20 042e9d8
fix: removed deprecated code
grv-saini-20 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
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
40 changes: 30 additions & 10 deletions
40 platforms/pictique/src/lib/fragments/PostModal/PostModal.svelte
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -9,6 +9,7 @@ | ||
| import { HugeiconsIcon } from '@hugeicons/svelte'; | ||
| import type { HTMLAttributes } from 'svelte/elements'; | ||
| import { MessageInput } from '..'; | ||
| import { Spring } from 'svelte/motion'; | ||
| interface IPostProps extends HTMLAttributes<HTMLElement> { | ||
| avatar: string; | ||
| @@ -115,6 +116,20 @@ | ||
| await callback.comment(commentValue); | ||
| commentValue = ''; | ||
| }; | ||
| const scale = new Spring(1, { | ||
| stiffness: 0.15, | ||
| damping: 0.25 | ||
| }); | ||
| async function handleLikeWithInteraction() { | ||
| scale.target = 1.4; | ||
| try { | ||
| await callback.like(); | ||
| } finally { | ||
| setTimeout(() => (scale.target = 1), 150); | ||
| } | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| </script> | ||
| <article {...restProps} class={cn(['flex w-full gap-10', restProps.class])}> | ||
| @@ -195,7 +210,7 @@ | ||
| <div class="flex w-full items-center justify-between md:hidden"> | ||
| <div class="flex gap-4"> | ||
| <button | ||
| class="cursor-pointer rounded-2xl bg-gray-100 px-4 py-3 hover:bg-gray-200" | ||
| class="group cursor-pointer rounded-2xl bg-gray-100 px-4 py-3 transition-colors hover:bg-gray-200 active:bg-gray-300" | ||
| onclick={callback.like} | ||
| > | ||
| <Like | ||
| @@ -289,18 +304,23 @@ | ||
| <div class="flex w-full flex-col justify-between gap-3"> | ||
| <div class="flex gap-4"> | ||
| <button | ||
| class="cursor-pointer rounded-2xl bg-gray-100 px-4 py-3 hover:bg-gray-200" | ||
| onclick={callback.like} | ||
| class="group cursor-pointer rounded-2xl bg-gray-100 px-4 py-3 transition-colors hover:bg-gray-200 active:bg-gray-300" | ||
| onclick={handleLikeWithInteraction} | ||
| > | ||
| <Like | ||
| size="24px" | ||
| color="var(--color-red-500" | ||
| fill={isLiked ? 'var(--color-red-500)' : 'white'} | ||
| /> | ||
| <div | ||
| style="transform: scale({scale.current}); display: flex; align-items: center; justify-content: center;" | ||
| > | ||
| <Like | ||
| size="24px" | ||
| color={'var(--color-red-500)'} | ||
| fill={isLiked ? 'var(--color-red-500)' : 'transparent'} | ||
| class="transition-all duration-300" | ||
| /> | ||
| </div> | ||
| </button> | ||
| <button class="cursor-pointer rounded-2xl bg-gray-100 px-4 py-3 hover:bg-gray-200"> | ||
| <!-- <button class="cursor-pointer rounded-2xl bg-gray-100 px-4 py-3 hover:bg-gray-200"> | ||
| <CommentIcon size="24px" color="black" fill="transparent" /> | ||
| </button> | ||
| </button> --> | ||
| </div> | ||
| <p class="text-black/60"> | ||
| {new Date(time).toLocaleDateString()} | ||
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
8 changes: 4 additions & 4 deletions
8 platforms/pictique/src/routes/(protected)/group/[id]/+page.svelte
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
47 changes: 40 additions & 7 deletions
47 platforms/pictique/src/routes/(protected)/profile/[id]/+page.svelte
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,13 +3,25 @@ | ||
| import { page } from '$app/state'; | ||
| import { PostModal, Profile } from '$lib/fragments'; | ||
| import { selectedPost } from '$lib/store/store.svelte'; | ||
| import { createComment } from '$lib/stores/comments'; | ||
| import { comments as commentsStore, createComment, fetchComments } from '$lib/stores/comments'; | ||
| import { toggleLike } from '$lib/stores/posts'; | ||
| import type { PostData, userProfile } from '$lib/types'; | ||
| import { Modal } from '$lib/ui'; | ||
| import { apiClient, getAuthId } from '$lib/utils/axios'; | ||
| import { onMount } from 'svelte'; | ||
| interface Comment { | ||
| id: string; | ||
| text: string; | ||
| createdAt: string; | ||
| author: { | ||
| id: string; | ||
| handle: string; | ||
| name: string; | ||
| avatarUrl: string; | ||
| }; | ||
| } | ||
| let profileId = $derived(page.params.id); | ||
| let profile = $state<userProfile | null>(null); | ||
| let error = $state<string | null>(null); | ||
| @@ -22,7 +34,6 @@ | ||
| return response.data; | ||
| } | ||
| }); | ||
| async function fetchProfile() { | ||
| try { | ||
| loading = true; | ||
| @@ -59,10 +70,14 @@ | ||
| } | ||
| } | ||
| function handlePostClick(post: PostData) { | ||
| console.log(post); | ||
| async function handlePostClick(post: PostData) { | ||
| selectedPost.value = post; | ||
| // goto("/profile/post"); | ||
| try { | ||
| // Trigger the store to fetch comments for this specific post | ||
| await fetchComments(post.id); | ||
| } catch (err) { | ||
| console.error('Error loading comments:', err); | ||
| } | ||
| } | ||
| onMount(fetchProfile); | ||
| @@ -130,15 +145,33 @@ | ||
| text={selectedPost.value?.caption ?? ''} | ||
| count={selectedPost.value?.count ?? { likes: 0, comments: 0 }} | ||
| {ownerProfile} | ||
| isLiked={ownerProfile | ||
| ? ((selectedPost.value as any)?.likedBy?.some( | ||
| (user: any) => user.id === ownerProfile.id | ||
| ) ?? false) | ||
| : false} | ||
| callback={{ | ||
| like: async () => { | ||
| await toggleLike(selectedPost.value?.id ?? ''); | ||
| if (!selectedPost.value?.id) return; | ||
| try { | ||
| const result = await toggleLike(selectedPost.value.id); | ||
| if (selectedPost.value && result?.likedBy) { | ||
| (selectedPost.value as any).likedBy = result.likedBy; | ||
| } | ||
| } catch (err) { | ||
| console.error('Failed to toggle like:', err); | ||
| } | ||
| }, | ||
coderabbitai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| comment: async (comment) => { | ||
| if (!selectedPost.value) return; | ||
| await createComment(selectedPost.value?.id, comment); | ||
| try { | ||
| await createComment(selectedPost.value.id, comment); | ||
| } catch (err) { | ||
| console.error('Failed to create comment:', err); | ||
| } | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| }} | ||
| comments={$commentsStore} | ||
| time={selectedPost.value?.time ?? ''} | ||
| /> | ||
| </Modal> | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.