feat(artists): mark as favorite#90
Conversation
| export function useFavoriteState(initialFavorites: string[]) { | ||
| const router = useRouter(); | ||
| const defaultValue = initialFavorites ? JSON.stringify(initialFavorites) : '[]'; | ||
| const [cookieValue, setCookieValue] = useCookie('relisten_favorites:artists', defaultValue); |
There was a problem hiding this comment.
Had a really hard time DRYing the relisten_favorites:artists variable to reuse in src/lib/serverFavoriteCookies.ts. It kept saying the export was a function?
Also open to changing naming convention. Figure it was worth scoping to artist so a different cookie name can be used for tracks.
| const cookieStore = await cookies(); | ||
|
|
||
| try { | ||
| const value = cookieStore.get('relisten_favorites:artists')?.value; |
There was a problem hiding this comment.
can you export the cookie key so its declared once and imported?
There was a problem hiding this comment.
Yup. I added to src/lib/constants.ts b/c was getting some weird behavior importing/exporting between client and server components.
|
Is there any way we can make this work without calling router.refresh? |
|
Also might be better to use a Set here: |
Good call, just updated.
I can mess around with it for sure. I was doing router.refresh based on this comment in the original issue. |
|
yeah that's my bad, didn't think to realize it would also refetch the random shows. |
closes #77