mirror of
https://github.com/antebudimir/feishin.git
synced 2025-12-31 18:13:31 +00:00
only show translation when api key and provider are picked, and fix eslint vscode
This commit is contained in:
parent
c81bd93d04
commit
2cf0027419
4 changed files with 19 additions and 9 deletions
|
|
@ -24,7 +24,7 @@ interface LyricsActionsProps {
|
|||
onRemoveLyric: () => void;
|
||||
onResetLyric: () => void;
|
||||
onSearchOverride: (params: LyricsOverride) => void;
|
||||
onTranslateLyric: () => void;
|
||||
onTranslateLyric?: () => void;
|
||||
setIndex: (idx: number) => void;
|
||||
}
|
||||
|
||||
|
|
@ -135,7 +135,7 @@ export const LyricsActions = ({
|
|||
</div>
|
||||
|
||||
<div style={{ position: 'absolute', right: 0, top: -50 }}>
|
||||
{isDesktop && sources.length ? (
|
||||
{isDesktop && sources.length && onTranslateLyric ? (
|
||||
<Button
|
||||
disabled={isActionsDisabled}
|
||||
onClick={onTranslateLyric}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ import { FullLyricsMetadata, LyricSource, LyricsOverride } from '/@/shared/types
|
|||
|
||||
export const Lyrics = () => {
|
||||
const currentSong = useCurrentSong();
|
||||
const lyricsSettings = useLyricsSettings();
|
||||
const { translationApiKey, translationApiProvider, translationTargetLanguage } =
|
||||
useLyricsSettings();
|
||||
const { t } = useTranslation();
|
||||
const [index, setIndex] = useState(0);
|
||||
const [translatedLyrics, setTranslatedLyrics] = useState<null | string>(null);
|
||||
|
|
@ -97,8 +98,6 @@ export const Lyrics = () => {
|
|||
const originalLyrics = Array.isArray(lyrics.lyrics)
|
||||
? lyrics.lyrics.map(([, line]) => line).join('\n')
|
||||
: lyrics.lyrics;
|
||||
const { translationApiKey, translationApiProvider, translationTargetLanguage } =
|
||||
lyricsSettings;
|
||||
const TranslatedText: null | string = await translateLyrics(
|
||||
originalLyrics,
|
||||
translationApiKey,
|
||||
|
|
@ -107,7 +106,14 @@ export const Lyrics = () => {
|
|||
);
|
||||
setTranslatedLyrics(TranslatedText);
|
||||
setShowTranslation(true);
|
||||
}, [lyrics, lyricsSettings, translatedLyrics, showTranslation]);
|
||||
}, [
|
||||
translatedLyrics,
|
||||
lyrics,
|
||||
translationApiKey,
|
||||
translationApiProvider,
|
||||
translationTargetLanguage,
|
||||
showTranslation,
|
||||
]);
|
||||
|
||||
const { isInitialLoading: isOverrideLoading } = useSongLyricsByRemoteId({
|
||||
options: {
|
||||
|
|
@ -194,7 +200,11 @@ export const Lyrics = () => {
|
|||
onRemoveLyric={handleOnRemoveLyric}
|
||||
onResetLyric={handleOnResetLyric}
|
||||
onSearchOverride={handleOnSearchOverride}
|
||||
onTranslateLyric={handleOnTranslateLyric}
|
||||
onTranslateLyric={
|
||||
translationApiProvider && translationApiKey
|
||||
? handleOnTranslateLyric
|
||||
: undefined
|
||||
}
|
||||
setIndex={setIndex}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -181,6 +181,7 @@ export const LyricSettings = () => {
|
|||
{
|
||||
control: (
|
||||
<Select
|
||||
clearable
|
||||
data={['Microsoft Azure', 'Google Cloud']}
|
||||
onChange={(value) => {
|
||||
setSettings({ lyrics: { ...settings, translationApiProvider: value } });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue