feishin/src/renderer/features/lyrics/lyrics.tsx

98 lines
2.6 KiB
TypeScript
Raw Normal View History

2023-06-03 18:03:32 -07:00
import { Center, Group } from '@mantine/core';
import { AnimatePresence, motion } from 'framer-motion';
2023-05-22 17:38:31 -07:00
import { ErrorBoundary } from 'react-error-boundary';
2023-06-02 23:54:34 -07:00
import { RiInformationFill } from 'react-icons/ri';
import styled from 'styled-components';
import { useSongLyrics } from './queries/lyric-query';
2023-06-03 18:03:32 -07:00
import { SynchronizedLyrics } from './synchronized-lyrics';
import { ScrollArea, Spinner, TextTitle } from '/@/renderer/components';
import { ErrorFallback } from '/@/renderer/features/action-required';
import { UnsynchronizedLyrics } from '/@/renderer/features/lyrics/unsynchronized-lyrics';
import { getServerById, useCurrentSong } from '/@/renderer/store';
2023-05-22 17:38:31 -07:00
const LyricsScrollContainer = styled(motion(ScrollArea))`
z-index: 1;
text-align: center;
transform: translateY(-2rem);
mask-image: linear-gradient(
180deg,
transparent 5%,
rgba(0, 0, 0, 100%) 20%,
rgba(0, 0, 0, 100%) 85%,
transparent 95%
);
&.mantine-ScrollArea-root {
height: 100%;
}
& .mantine-ScrollArea-viewport {
height: 100% !important;
}
& .mantine-ScrollArea-viewport > div {
height: 100%;
}
`;
2023-05-22 17:38:31 -07:00
export const Lyrics = () => {
const currentSong = useCurrentSong();
2023-06-03 07:15:02 -07:00
const currentServer = getServerById(currentSong?.serverId);
2023-05-22 17:38:31 -07:00
const { data, isLoading } = useSongLyrics(
{
query: { songId: currentSong?.id || '' },
serverId: currentServer?.id,
},
currentSong,
);
2023-05-22 17:38:31 -07:00
return (
<ErrorBoundary FallbackComponent={ErrorFallback}>
{isLoading ? (
<Spinner
container
size={25}
/>
) : !data?.lyrics ? (
<Center>
2023-06-02 23:54:34 -07:00
<Group>
<RiInformationFill size="2rem" />
<TextTitle
order={3}
weight={700}
>
No lyrics found
</TextTitle>
</Group>
</Center>
2023-06-04 16:20:21 -07:00
) : (
<AnimatePresence mode="sync">
<LyricsScrollContainer
animate={{ opacity: 1 }}
initial={{ opacity: 0 }}
transition={{ duration: 0.5 }}
>
{Array.isArray(data.lyrics) ? (
<SynchronizedLyrics
lyrics={data.lyrics}
override={null}
source={data.source}
onRemoveLyric={() => {}}
/>
) : (
<UnsynchronizedLyrics
lyrics={data.lyrics}
override={null}
source={data.source}
onRemoveLyric={() => {}}
/>
)}
</LyricsScrollContainer>
</AnimatePresence>
2023-06-02 23:54:34 -07:00
)}
2023-05-22 17:38:31 -07:00
</ErrorBoundary>
);
};