Skip to content

Commit

Permalink
feat: add ability to like a playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
kujo205 committed Jan 28, 2025
1 parent 0384f41 commit d860962
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
14 changes: 10 additions & 4 deletions src/features/community/components/PlaylistCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
name: string | null;
user_name: string | null;
liked: boolean;
onAddToLiked?: (id?: string) => void;
}
</script>

Expand All @@ -14,7 +15,7 @@
import { MousePointerClick, UserRound, Heart } from 'lucide-svelte';
import { Button } from '$comp/ui/button';
const { id, link, name, user_name }: PlaylistCardProps = $props();
const { id, link, name, user_name, onAddToLiked, liked }: PlaylistCardProps = $props();
</script>

<Card.Root class="flex h-36 min-w-80 max-w-[520px] overflow-hidden">
Expand All @@ -36,12 +37,17 @@
</div>

<Button
class="px-3"
onclick={() => {
alert('not implemented');
if (onAddToLiked) {
console.log('adding to liked songs');
onAddToLiked(id);
}
}}
variant="outline"><Heart /></Button
variant="outline"
>
{liked ? 'Liked' : 'Like'}
<Heart fill={liked ? 'red' : 'none'} />
</Button>
</div>

<div class="flex justify-between">
Expand Down
2 changes: 1 addition & 1 deletion src/lib/hooks/h1_locals_population.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { authService } from '$server/services/AuthService';
export const h1LocalsPopulation: Handle = async ({ event, resolve }) => {
const authInfo = await event.locals.auth();
const maybeUserEmail = authInfo?.user?.email;
console.log('authInfo', authInfo);

event.locals.info = await authService.populateUserSession(maybeUserEmail);

return resolve(event);
Expand Down
30 changes: 21 additions & 9 deletions src/routes/dashboard/community/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script lang="ts">
import type { PageData } from './$types';
import PlaylistCard from '$features/community/components/PlaylistCard.svelte';
import { trpc } from '$lib/trpc_client';
import { invalidateAll } from '$app/navigation';
interface Props {
data: PageData;
Expand All @@ -9,12 +11,22 @@
const { data }: Props = $props();
</script>

{#each data.playlists as playlist}
<PlaylistCard
liked={false}
id={playlist.id}
user_name={playlist.user_name}
name={playlist.name}
link={playlist.link}
/>
{/each}
<div class="flex flex-col gap-2">
{#each data.playlists as playlist}
<PlaylistCard
onAddToLiked={async () => {
await trpc.community.likeCommunityPlaylist.mutate({
playlist_id: playlist.id,
like: !playlist.liked
});

await invalidateAll();
}}
liked={playlist.liked}
id={playlist.id}
user_name={playlist.user_name}
name={playlist.name}
link={playlist.link}
/>
{/each}
</div>

0 comments on commit d860962

Please sign in to comment.