mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 21:27:05 +00:00
84 lines
2.6 KiB
TypeScript
84 lines
2.6 KiB
TypeScript
import { useMemo } from 'react';
|
|
import { interfaceLanguages } from 'stremio/common';
|
|
import { useServices } from 'stremio/services';
|
|
|
|
const useGeneralOptions = (profile: Profile) => {
|
|
const { core } = useServices();
|
|
|
|
const interfaceLanguageSelect = useMemo(() => ({
|
|
options: interfaceLanguages.map(({ name, codes }) => ({
|
|
value: codes[0],
|
|
label: name,
|
|
})),
|
|
value: interfaceLanguages.find(({ codes }) => codes[1] === profile.settings.interfaceLanguage)?.codes?.[0] || profile.settings.interfaceLanguage,
|
|
onSelect: (value: string) => {
|
|
core.transport.dispatch({
|
|
action: 'Ctx',
|
|
args: {
|
|
action: 'UpdateSettings',
|
|
args: {
|
|
...profile.settings,
|
|
interfaceLanguage: value
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}), [profile.settings]);
|
|
|
|
const escExitFullscreenToggle = useMemo(() => ({
|
|
checked: profile.settings.escExitFullscreen,
|
|
onClick: () => {
|
|
core.transport.dispatch({
|
|
action: 'Ctx',
|
|
args: {
|
|
action: 'UpdateSettings',
|
|
args: {
|
|
...profile.settings,
|
|
escExitFullscreen: !profile.settings.escExitFullscreen
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}), [profile.settings]);
|
|
|
|
const quitOnCloseToggle = useMemo(() => ({
|
|
checked: profile.settings.quitOnClose,
|
|
onClick: () => {
|
|
core.transport.dispatch({
|
|
action: 'Ctx',
|
|
args: {
|
|
action: 'UpdateSettings',
|
|
args: {
|
|
...profile.settings,
|
|
quitOnClose: !profile.settings.quitOnClose
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}), [profile.settings]);
|
|
|
|
const hideSpoilersToggle = useMemo(() => ({
|
|
checked: profile.settings.hideSpoilers,
|
|
onClick: () => {
|
|
core.transport.dispatch({
|
|
action: 'Ctx',
|
|
args: {
|
|
action: 'UpdateSettings',
|
|
args: {
|
|
...profile.settings,
|
|
hideSpoilers: !profile.settings.hideSpoilers
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}), [profile.settings]);
|
|
|
|
return {
|
|
interfaceLanguageSelect,
|
|
escExitFullscreenToggle,
|
|
quitOnCloseToggle,
|
|
hideSpoilersToggle,
|
|
};
|
|
};
|
|
|
|
export default useGeneralOptions;
|