Skip to content

Build your personal knowledge base with Trilium Notes

chore(react/settings): make layout switch functional

Elian Doran6685e583f235
diff --git a/apps/client/src/services/utils.ts b/apps/client/src/services/utils.ts
index c7d37e4d9a..4ae43dcb50 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 263ea313f0..c275f5a404 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<void>, interval = 1000)
return spacedUpdateRef.current;
}
-export function useTriliumOption(name: OptionNames): [string, (newValue: string) => void] {
+export function useTriliumOption(name: OptionNames): [string, (newValue: string) => Promise<void>] {
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 60b65692d2..6743c4a81c 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 (
<OptionsSection title={t("theme.layout")}>
- <FormRadioGroup
+ {!isMobile() && <FormRadioGroup
name="layout-orientation"
values={[
{
@@ -21,8 +21,11 @@ export default function AppearanceSettings() {
value: "horizontal"
}
]}
- currentValue={layoutOrientation} onChange={setLayoutOrientation}
- />
+ currentValue={layoutOrientation} onChange={async (newValue) => {
+ await setLayoutOrientation(newValue);
+ reloadFrontendApp("layout orientation change");
+ }}
+ />}
</OptionsSection>
)
}
\ 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 fb98f00e3e..66903babb3 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();