2023-06-03 18:03:32 -07:00
|
|
|
import { Center, Group } from '@mantine/core';
|
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';
|
2023-06-05 02:57:20 -07:00
|
|
|
import styled from 'styled-components';
|
2023-06-05 02:50:01 -07:00
|
|
|
import { useSongLyrics } from './queries/lyric-query';
|
2023-06-03 18:03:32 -07:00
|
|
|
import { SynchronizedLyrics } from './synchronized-lyrics';
|
2023-06-05 02:57:20 -07:00
|
|
|
import { ScrollArea, Spinner, TextTitle } from '/@/renderer/components';
|
2023-06-05 02:50:01 -07:00
|
|
|
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
|
|
|
|
2023-06-05 02:57:20 -07:00
|
|
|
const LyricsScrollContainer = styled(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
|
|
|
|
2023-06-05 02:50:01 -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}>
|
2023-06-05 02:50:01 -07:00
|
|
|
{isLoading ? (
|
|
|
|
|
<Spinner
|
|
|
|
|
container
|
|
|
|
|
size={25}
|
|
|
|
|
/>
|
|
|
|
|
) : !data?.lyrics ? (
|
2023-06-05 02:57:20 -07:00
|
|
|
<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
|
|
|
) : (
|
2023-06-05 02:57:20 -07:00
|
|
|
<LyricsScrollContainer>
|
2023-06-05 02:50:01 -07:00
|
|
|
{Array.isArray(data.lyrics) ? (
|
2023-06-04 16:20:21 -07:00
|
|
|
<SynchronizedLyrics
|
2023-06-05 02:50:01 -07:00
|
|
|
lyrics={data.lyrics}
|
|
|
|
|
override={null}
|
|
|
|
|
source={data.source}
|
|
|
|
|
onRemoveLyric={() => {}}
|
2023-06-04 16:20:21 -07:00
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<UnsynchronizedLyrics
|
2023-06-05 02:50:01 -07:00
|
|
|
lyrics={data.lyrics}
|
|
|
|
|
override={null}
|
|
|
|
|
source={data.source}
|
|
|
|
|
onRemoveLyric={() => {}}
|
2023-06-04 16:20:21 -07:00
|
|
|
/>
|
|
|
|
|
)}
|
2023-06-05 02:57:20 -07:00
|
|
|
</LyricsScrollContainer>
|
2023-06-02 23:54:34 -07:00
|
|
|
)}
|
2023-05-22 17:38:31 -07:00
|
|
|
</ErrorBoundary>
|
|
|
|
|
);
|
|
|
|
|
};
|