mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-20 14:37:43 +01:00
add flags to audio options
This commit is contained in:
parent
ef6b0ad1dc
commit
dbb1c19796
1 changed files with 28 additions and 4 deletions
|
@ -1,13 +1,37 @@
|
||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
|
import { FlagIcon } from "@/components/FlagIcon";
|
||||||
import { Menu } from "@/components/player/internals/ContextMenu";
|
import { Menu } from "@/components/player/internals/ContextMenu";
|
||||||
import { useOverlayRouter } from "@/hooks/useOverlayRouter";
|
import { useOverlayRouter } from "@/hooks/useOverlayRouter";
|
||||||
import { AudioTrack } from "@/stores/player/slices/source";
|
import { AudioTrack } from "@/stores/player/slices/source";
|
||||||
import { usePlayerStore } from "@/stores/player/store";
|
import { usePlayerStore } from "@/stores/player/store";
|
||||||
|
import { getPrettyLanguageNameFromLocale } from "@/utils/language";
|
||||||
|
|
||||||
import { SelectableLink } from "../../internals/ContextMenu/Links";
|
import { SelectableLink } from "../../internals/ContextMenu/Links";
|
||||||
|
|
||||||
|
export function AudioOption(props: {
|
||||||
|
langCode?: string;
|
||||||
|
children: React.ReactNode;
|
||||||
|
selected?: boolean;
|
||||||
|
onClick?: () => void;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<SelectableLink selected={props.selected} onClick={props.onClick}>
|
||||||
|
<span className="flex items-center">
|
||||||
|
<span data-code={props.langCode} className="mr-3 inline-flex">
|
||||||
|
<FlagIcon langCode={props.langCode} />
|
||||||
|
</span>
|
||||||
|
<span>{props.children}</span>
|
||||||
|
</span>
|
||||||
|
</SelectableLink>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function AudioView({ id }: { id: string }) {
|
export function AudioView({ id }: { id: string }) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const unknownChoice = t("player.menus.subtitles.unknownLanguage");
|
||||||
|
|
||||||
const router = useOverlayRouter(id);
|
const router = useOverlayRouter(id);
|
||||||
const audioTracks = usePlayerStore((s) => s.audioTracks);
|
const audioTracks = usePlayerStore((s) => s.audioTracks);
|
||||||
const currentAudioTrack = usePlayerStore((s) => s.currentAudioTrack);
|
const currentAudioTrack = usePlayerStore((s) => s.currentAudioTrack);
|
||||||
|
@ -26,14 +50,14 @@ export function AudioView({ id }: { id: string }) {
|
||||||
<Menu.BackLink onClick={() => router.navigate("/")}>Audio</Menu.BackLink>
|
<Menu.BackLink onClick={() => router.navigate("/")}>Audio</Menu.BackLink>
|
||||||
<Menu.Section className="flex flex-col pb-4">
|
<Menu.Section className="flex flex-col pb-4">
|
||||||
{audioTracks.map((v) => (
|
{audioTracks.map((v) => (
|
||||||
<SelectableLink
|
<AudioOption
|
||||||
key={v.id}
|
key={v.id}
|
||||||
selected={v.id === currentAudioTrack?.id}
|
selected={v.id === currentAudioTrack?.id}
|
||||||
|
langCode={v.language}
|
||||||
onClick={audioTracks.includes(v) ? () => change(v) : undefined}
|
onClick={audioTracks.includes(v) ? () => change(v) : undefined}
|
||||||
disabled={!audioTracks.includes(v)}
|
|
||||||
>
|
>
|
||||||
{v.label} ({v.language})
|
{getPrettyLanguageNameFromLocale(v.language) ?? unknownChoice}
|
||||||
</SelectableLink>
|
</AudioOption>
|
||||||
))}
|
))}
|
||||||
</Menu.Section>
|
</Menu.Section>
|
||||||
</>
|
</>
|
||||||
|
|
Loading…
Reference in a new issue