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

92 lines
2.9 KiB
TypeScript
Raw Normal View History

2023-06-09 16:30:31 -07:00
import isElectron from 'is-electron';
2023-06-08 03:40:58 -07:00
import { RiAddFill, RiSubtractFill } from 'react-icons/ri';
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';
import {
2023-07-01 19:10:05 -07:00
useCurrentSong,
useLyricsSettings,
useSettingsStore,
useSettingsStoreActions,
} from '/@/renderer/store';
2023-06-08 03:40:58 -07:00
interface LyricsActionsProps {
2023-07-01 19:10:05 -07:00
onRemoveLyric: () => void;
onSearchOverride: (params: LyricsOverride) => void;
}
export const LyricsActions = ({ onRemoveLyric, onSearchOverride }: LyricsActionsProps) => {
2023-07-01 19:10:05 -07:00
const currentSong = useCurrentSong();
const { setSettings } = useSettingsStoreActions();
const { delayMs, sources } = useLyricsSettings();
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-07-01 19:10:05 -07:00
return (
<>
{isDesktop && sources.length ? (
<Button
uppercase
disabled={isActionsDisabled}
variant="subtle"
onClick={() =>
openLyricSearchModal({
artist: currentSong?.artistName,
name: currentSong?.name,
onSearchOverride,
})
}
>
Search
</Button>
) : null}
<Button
aria-label="Decrease lyric offset"
variant="subtle"
onClick={() => handleLyricOffset(delayMs - 50)}
>
<RiSubtractFill />
</Button>
<Tooltip
label="Offset (ms)"
openDelay={500}
>
<NumberInput
aria-label="Lyric offset"
styles={{ input: { textAlign: 'center' } }}
value={delayMs || 0}
width={55}
onChange={handleLyricOffset}
/>
</Tooltip>
<Button
aria-label="Increase lyric offset"
variant="subtle"
onClick={() => handleLyricOffset(delayMs + 50)}
>
<RiAddFill />
</Button>
{isDesktop && sources.length ? (
<Button
uppercase
disabled={isActionsDisabled}
variant="subtle"
onClick={onRemoveLyric}
>
Clear
</Button>
) : null}
</>
);
2023-06-08 03:40:58 -07:00
};