'use client'; import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { getLyrics, Lyrics, updateLyrics } from '../lib/api'; import { useEffect, useState } from 'react'; interface LyricsEditorProps { projectId: string; } export function LyricsEditor({ projectId }: LyricsEditorProps) { const queryClient = useQueryClient(); const { data, isLoading, isError, error } = useQuery({ queryKey: ['projects', projectId, 'lyrics'], queryFn: () => getLyrics(projectId) }); const [text, setText] = useState(''); useEffect(() => { if (data) { setText(data.raw_text ?? ''); } }, [data]); const mutation = useMutation({ mutationFn: () => updateLyrics(projectId, { raw_text: text }), onSuccess: (updated) => { queryClient.setQueryData(['projects', projectId, 'lyrics'], updated); } }); return (

Lyrics

Review and edit the current lyrics.

{isLoading &&

Loading lyrics...

} {isError &&

{error.message}

} {!isLoading && !isError && ( <>