diff --git a/apps/web/src/components/SongCover/SongCover.tsx b/apps/web/src/components/SongCover/SongCover.tsx index b4734319..58c0245b 100644 --- a/apps/web/src/components/SongCover/SongCover.tsx +++ b/apps/web/src/components/SongCover/SongCover.tsx @@ -4,6 +4,9 @@ import InteractionBar from "./InteractionBar"; import useLike from "../../hooks/useLike"; import SignInModal from "../SignInModal"; import { useState } from "react"; +import { useQueryClient } from "@tanstack/react-query"; +import { useAtomValue } from "jotai"; +import { feedGeneratorUriAtom } from "../../atoms/feed"; const Cover = styled.img<{ size?: number }>` border-radius: 8px; @@ -64,6 +67,8 @@ export type SongCoverProps = { }; function SongCover(props: SongCoverProps) { + const queryClient = useQueryClient(); + const feedUri = useAtomValue(feedGeneratorUriAtom); const [isSignInOpen, setIsSignInOpen] = useState(false); const [liked, setLiked] = useState(props.liked); const { like, unlike } = useLike(); @@ -88,6 +93,10 @@ function SongCover(props: SongCoverProps) { } await like(uri); } + + await queryClient.invalidateQueries({ + queryKey: ["infiniteFeed", feedUri], + }); }; return ( e.stopPropagation()}> diff --git a/apps/web/src/components/StickyPlayer/StickyPlayerWithData.tsx b/apps/web/src/components/StickyPlayer/StickyPlayerWithData.tsx index 7c1c874e..7aa1e3aa 100644 --- a/apps/web/src/components/StickyPlayer/StickyPlayerWithData.tsx +++ b/apps/web/src/components/StickyPlayer/StickyPlayerWithData.tsx @@ -1,5 +1,5 @@ import axios from "axios"; -import { useAtom } from "jotai"; +import { useAtom, useAtomValue } from "jotai"; import _ from "lodash"; import { useCallback, useEffect, useRef, useState } from "react"; import { nowPlayingAtom } from "../../atoms/nowpaying"; @@ -9,8 +9,12 @@ import useLike from "../../hooks/useLike"; import useSpotify from "../../hooks/useSpotify"; import StickyPlayer from "./StrickyPlayer"; import { consola } from "consola"; +import { useQueryClient } from "@tanstack/react-query"; +import { feedGeneratorUriAtom } from "../../atoms/feed"; function StickyPlayerWithData() { + const queryClient = useQueryClient(); + const feedUri = useAtomValue(feedGeneratorUriAtom); const [liked, setLiked] = useState>({}); const [nowPlaying, setNowPlaying] = useAtom(nowPlayingAtom); const progressInterval = useRef(null); @@ -25,7 +29,7 @@ function StickyPlayerWithData() { const playerRef = useRef(player); const likedRef = useRef(liked); - const onLike = (uri: string) => { + const onLike = async (uri: string) => { setLiked({ ...liked, [uri]: true, @@ -40,6 +44,10 @@ function StickyPlayerWithData() { liked: true, }; }); + + await queryClient.invalidateQueries({ + queryKey: ["infiniteFeed", feedUri], + }); }; const onDislike = (uri: string) => {