From 66951af066490179adefe6cdc2f2444573dd95df Mon Sep 17 00:00:00 2001 From: Ryan Freeman Date: Fri, 27 Sep 2024 21:02:51 +0100 Subject: [PATCH] Update SpotifyPlayer --- components/ui/SpotifyPlayer.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/components/ui/SpotifyPlayer.tsx b/components/ui/SpotifyPlayer.tsx index 63b69f5..2f0e83c 100644 --- a/components/ui/SpotifyPlayer.tsx +++ b/components/ui/SpotifyPlayer.tsx @@ -1,11 +1,11 @@ 'use client' -import useSWR from 'swr' +import useSWR, {useSWRConfig} from 'swr' import fetcher from '@/lib/fetcher' import Image from 'next/image' import Link from 'next/link' import clsx from 'clsx' -import {useEffect, ReactElement, ElementType} from 'react' +import {ElementType, ReactElement, useEffect} from 'react' import {animate} from 'motion' type Status = { @@ -110,8 +110,11 @@ type PlayerStateResponse = { } function usePlayerState(path: string) { + const {mutate} = useSWRConfig() const {data, error, isLoading} = useSWR(`/api/spotify/${path}`, fetcher) as PlayerStateResponse + mutate(`/api/spotify/${path}`, data).then(r => r) + return { song: data, isLoading,