@ -1,5 +1,7 @@
@@ -1,5 +1,7 @@
import { useTranslation } from "react-i18next" ;
import { useAsync } from "react-use" ;
import { isExtensionActive } from "@/backend/extension/messaging" ;
import { Toggle } from "@/components/buttons/Toggle" ;
import { FlagIcon } from "@/components/FlagIcon" ;
import { Dropdown } from "@/components/form/Dropdown" ;
@ -7,14 +9,31 @@ import { Heading1 } from "@/components/utils/Text";
@@ -7,14 +9,31 @@ import { Heading1 } from "@/components/utils/Text";
import { appLanguageOptions } from "@/setup/i18n" ;
import { getLocaleInfo , sortLangCodes } from "@/utils/language" ;
function useIsExtensionActive() {
const { loading , value } = useAsync ( async ( ) = > {
const extensionStatus = ( await isExtensionActive ( ) ) ? "success" : "unset" ;
return extensionStatus === "success" ;
} , [ ] ) ;
return {
loading ,
active : value ,
} ;
}
export function PreferencesPart ( props : {
language : string ;
setLanguage : ( l : string ) = > void ;
enableThumbnails : boolean ;
setEnableThumbnails : ( v : boolean ) = > void ;
enableAutoplay : boolean ;
setEnableAutoplay : ( v : boolean ) = > void ;
} ) {
const { t } = useTranslation ( ) ;
const sorted = sortLangCodes ( appLanguageOptions . map ( ( item ) = > item . code ) ) ;
const { loading , active } = useIsExtensionActive ( ) ;
const extensionActive = active && ! loading ;
const options = appLanguageOptions
. sort ( ( a , b ) = > sorted . indexOf ( a . code ) - sorted . indexOf ( b . code ) )
@ -62,6 +81,32 @@ export function PreferencesPart(props: {
@@ -62,6 +81,32 @@ export function PreferencesPart(props: {
< / p >
< / div >
< / div >
< div >
< p className = "text-white font-bold mb-3" >
{ t ( "settings.preferences.autoplay" ) }
< / p >
< p className = "max-w-[25rem] font-medium" >
{ t ( "settings.preferences.autoplayDescription" ) }
< / p >
< div
onClick = { ( ) = >
extensionActive
? props . setEnableAutoplay ( ! props . enableAutoplay )
: null
}
className = "bg-dropdown-background hover:bg-dropdown-hoverBackground select-none my-4 cursor-pointer space-x-3 flex items-center max-w-[25rem] py-3 px-4 rounded-lg"
style = { {
pointerEvents : extensionActive ? "auto" : "none" ,
opacity : extensionActive ? 1 : 0.5 ,
cursor : extensionActive ? "pointer" : "not-allowed" ,
} }
>
< Toggle enabled = { props . enableAutoplay && extensionActive } / >
< p className = "flex-1 text-white font-bold" >
{ t ( "settings.preferences.autoplayLabel" ) }
< / p >
< / div >
< / div >
< / div >
) ;
}