diff --git a/apps/client/src/services/utils.ts b/apps/client/src/services/utils.ts index c7d37e4d9..4ae43dcb5 100644 --- a/apps/client/src/services/utils.ts +++ b/apps/client/src/services/utils.ts @@ -5,7 +5,7 @@ const SVG_MIME = "image/svg+xml"; export const isShare = !window.glob; -function reloadFrontendApp(reason?: string) { +export function reloadFrontendApp(reason?: string) { if (reason) { logInfo(`Frontend app reload: ${reason}`); } @@ -218,7 +218,7 @@ function randomString(len: number) { return text; } -function isMobile() { +export function isMobile() { return ( window.glob?.device === "mobile" || // window.glob.device is not available in setup diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx index 263ea313f..c275f5a40 100644 --- a/apps/client/src/widgets/react/hooks.tsx +++ b/apps/client/src/widgets/react/hooks.tsx @@ -68,12 +68,12 @@ export function useSpacedUpdate(callback: () => Promise, interval = 1000) return spacedUpdateRef.current; } -export function useTriliumOption(name: OptionNames): [string, (newValue: string) => void] { +export function useTriliumOption(name: OptionNames): [string, (newValue: string) => Promise] { const initialValue = options.get(name); const [ value, setValue ] = useState(initialValue); - function wrappedSetValue(newValue: string) { - options.save(name, newValue); + async function wrappedSetValue(newValue: string) { + await options.save(name, newValue); }; useTriliumEvent("entitiesReloaded", ({ loadResults }) => { diff --git a/apps/client/src/widgets/type_widgets/options/appearance.tsx b/apps/client/src/widgets/type_widgets/options/appearance.tsx index 60b65692d..6743c4a81 100644 --- a/apps/client/src/widgets/type_widgets/options/appearance.tsx +++ b/apps/client/src/widgets/type_widgets/options/appearance.tsx @@ -1,15 +1,15 @@ import { t } from "../../../services/i18n"; +import { isMobile, reloadFrontendApp } from "../../../services/utils"; import FormRadioGroup from "../../react/FormRadioGroup"; import { useTriliumOption } from "../../react/hooks"; import OptionsSection from "./components/OptionsSection"; export default function AppearanceSettings() { const [ layoutOrientation, setLayoutOrientation ] = useTriliumOption("layoutOrientation"); - console.log("Render with ", layoutOrientation); return ( - + currentValue={layoutOrientation} onChange={async (newValue) => { + await setLayoutOrientation(newValue); + reloadFrontendApp("layout orientation change"); + }} + />} ) } \ No newline at end of file diff --git a/apps/client/src/widgets/type_widgets/options/appearance/theme.ts b/apps/client/src/widgets/type_widgets/options/appearance/theme.ts index fb98f00e3..66903babb 100644 --- a/apps/client/src/widgets/type_widgets/options/appearance/theme.ts +++ b/apps/client/src/widgets/type_widgets/options/appearance/theme.ts @@ -40,14 +40,6 @@ export default class ThemeOptions extends OptionsWidget { this.$widget = $(TPL); this.$themeSelect = this.$widget.find(".theme-select"); this.$overrideThemeFonts = this.$widget.find(".override-theme-fonts"); - this.$layoutOrientation = this.$widget.find(`input[name="layout-orientation"]`).on("change", async () => { - const newLayoutOrientation = String(this.$widget.find(`input[name="layout-orientation"]:checked`).val()); - await this.updateOption("layoutOrientation", newLayoutOrientation); - utils.reloadFrontendApp("layout orientation change"); - }); - - const $layoutOrientationSection = $(this.$widget[0]); - $layoutOrientationSection.toggleClass("hidden-ext", utils.isMobile()); this.$themeSelect.on("change", async () => { const newTheme = this.$themeSelect.val();