2023-08-04 11:51:01 -07:00
|
|
|
import { Box, Group } from '@mantine/core';
|
2023-06-09 16:30:31 -07:00
|
|
|
import isElectron from 'is-electron';
|
2023-10-30 19:22:45 -07:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2023-06-08 03:40:58 -07:00
|
|
|
import { RiAddFill, RiSubtractFill } from 'react-icons/ri';
|
2023-06-09 02:38:04 -07:00
|
|
|
import { LyricsOverride } from '/@/renderer/api/types';
|
2023-06-09 16:39:13 -07:00
|
|
|
import { Button, NumberInput, Tooltip } from '/@/renderer/components';
|
2023-06-08 03:40:58 -07:00
|
|
|
import { openLyricSearchModal } from '/@/renderer/features/lyrics/components/lyrics-search-form';
|
2023-06-09 03:53:49 -07:00
|
|
|
import {
|
2023-07-01 19:10:05 -07:00
|
|
|
useCurrentSong,
|
|
|
|
|
useLyricsSettings,
|
|
|
|
|
useSettingsStore,
|
|
|
|
|
useSettingsStoreActions,
|
2023-06-09 03:53:49 -07:00
|
|
|
} from '/@/renderer/store';
|
2023-06-08 03:40:58 -07:00
|
|
|
|
2023-06-09 02:38:04 -07:00
|
|
|
interface LyricsActionsProps {
|
2023-07-01 19:10:05 -07:00
|
|
|
onRemoveLyric: () => void;
|
2023-08-04 11:51:01 -07:00
|
|
|
onResetLyric: () => void;
|
2023-07-01 19:10:05 -07:00
|
|
|
onSearchOverride: (params: LyricsOverride) => void;
|
2023-06-09 02:38:04 -07:00
|
|
|
}
|
|
|
|
|
|
2023-08-04 11:51:01 -07:00
|
|
|
export const LyricsActions = ({
|
|
|
|
|
onRemoveLyric,
|
|
|
|
|
onResetLyric,
|
|
|
|
|
onSearchOverride,
|
|
|
|
|
}: LyricsActionsProps) => {
|
2023-10-30 19:22:45 -07:00
|
|
|
const { t } = useTranslation();
|
2023-07-01 19:10:05 -07:00
|
|
|
const currentSong = useCurrentSong();
|
|
|
|
|
const { setSettings } = useSettingsStoreActions();
|
|
|
|
|
const { delayMs, sources } = useLyricsSettings();
|
2023-06-09 03:53:49 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const handleLyricOffset = (e: number) => {
|
|
|
|
|
setSettings({
|
|
|
|
|
lyrics: {
|
|
|
|
|
...useSettingsStore.getState().lyrics,
|
|
|
|
|
delayMs: e,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
2023-06-08 03:40:58 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const isActionsDisabled = !currentSong;
|
|
|
|
|
const isDesktop = isElectron();
|
2023-06-09 04:09:18 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
return (
|
2023-08-04 11:51:01 -07:00
|
|
|
<Box style={{ position: 'relative', width: '100%' }}>
|
|
|
|
|
<Group position="center">
|
|
|
|
|
{isDesktop && sources.length ? (
|
|
|
|
|
<Button
|
|
|
|
|
uppercase
|
|
|
|
|
disabled={isActionsDisabled}
|
|
|
|
|
variant="subtle"
|
|
|
|
|
onClick={() =>
|
|
|
|
|
openLyricSearchModal({
|
|
|
|
|
artist: currentSong?.artistName,
|
|
|
|
|
name: currentSong?.name,
|
|
|
|
|
onSearchOverride,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
>
|
2023-10-30 19:22:45 -07:00
|
|
|
{t('common.search', { postProcess: 'titleCase' })}
|
2023-08-04 11:51:01 -07:00
|
|
|
</Button>
|
|
|
|
|
) : null}
|
2023-07-01 19:10:05 -07:00
|
|
|
<Button
|
2023-08-04 11:51:01 -07:00
|
|
|
aria-label="Decrease lyric offset"
|
2023-07-01 19:10:05 -07:00
|
|
|
variant="subtle"
|
2023-08-04 11:51:01 -07:00
|
|
|
onClick={() => handleLyricOffset(delayMs - 50)}
|
2023-07-01 19:10:05 -07:00
|
|
|
>
|
2023-08-04 11:51:01 -07:00
|
|
|
<RiSubtractFill />
|
2023-07-01 19:10:05 -07:00
|
|
|
</Button>
|
2023-08-04 11:51:01 -07:00
|
|
|
<Tooltip
|
2023-10-30 19:22:45 -07:00
|
|
|
label={t('setting.lyricOffset', { postProcess: 'sentenceCase' })}
|
2023-08-04 11:51:01 -07:00
|
|
|
openDelay={500}
|
|
|
|
|
>
|
|
|
|
|
<NumberInput
|
|
|
|
|
aria-label="Lyric offset"
|
|
|
|
|
styles={{ input: { textAlign: 'center' } }}
|
|
|
|
|
value={delayMs || 0}
|
|
|
|
|
width={55}
|
|
|
|
|
onChange={handleLyricOffset}
|
|
|
|
|
/>
|
|
|
|
|
</Tooltip>
|
2023-07-01 19:10:05 -07:00
|
|
|
<Button
|
2023-08-04 11:51:01 -07:00
|
|
|
aria-label="Increase lyric offset"
|
2023-07-01 19:10:05 -07:00
|
|
|
variant="subtle"
|
2023-08-04 11:51:01 -07:00
|
|
|
onClick={() => handleLyricOffset(delayMs + 50)}
|
2023-07-01 19:10:05 -07:00
|
|
|
>
|
2023-08-04 11:51:01 -07:00
|
|
|
<RiAddFill />
|
2023-07-01 19:10:05 -07:00
|
|
|
</Button>
|
2023-08-04 11:51:01 -07:00
|
|
|
{isDesktop && sources.length ? (
|
|
|
|
|
<Button
|
|
|
|
|
uppercase
|
|
|
|
|
disabled={isActionsDisabled}
|
|
|
|
|
variant="subtle"
|
|
|
|
|
onClick={onResetLyric}
|
|
|
|
|
>
|
2023-10-30 19:22:45 -07:00
|
|
|
{t('common.reset', { postProcess: 'sentenceCase' })}
|
2023-08-04 11:51:01 -07:00
|
|
|
</Button>
|
|
|
|
|
) : null}
|
|
|
|
|
</Group>
|
|
|
|
|
|
|
|
|
|
<Box style={{ position: 'absolute', right: 0, top: 0 }}>
|
|
|
|
|
{isDesktop && sources.length ? (
|
|
|
|
|
<Button
|
|
|
|
|
uppercase
|
|
|
|
|
color="red"
|
|
|
|
|
disabled={isActionsDisabled}
|
|
|
|
|
variant="subtle"
|
|
|
|
|
onClick={onRemoveLyric}
|
|
|
|
|
>
|
2023-10-30 19:22:45 -07:00
|
|
|
{t('common.clear', { postProcess: 'sentenceCase' })}
|
2023-08-04 11:51:01 -07:00
|
|
|
</Button>
|
|
|
|
|
) : null}
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
2023-07-01 19:10:05 -07:00
|
|
|
);
|
2023-06-08 03:40:58 -07:00
|
|
|
};
|