Skip to content

Build your personal knowledge base with Trilium Notes

client/options: make the restart button a shared component

Adorian Doranfc0c6172bf79
diff --git a/apps/client/src/widgets/type_widgets/options/appearance.css b/apps/client/src/widgets/type_widgets/options/appearance.css
index b2bc6b1df8..6862e34f52 100644
--- a/apps/client/src/widgets/type_widgets/options/appearance.css
+++ b/apps/client/src/widgets/type_widgets/options/appearance.css
@@ -20,11 +20,6 @@
}
}
-/* No card of its own, so it keeps the width of the one above and ends where its controls do. */
-.appearance-restart {
- text-align: end;
-}
-
/* Font Option Row */
.font-option {
cursor: pointer;
diff --git a/apps/client/src/widgets/type_widgets/options/appearance.tsx b/apps/client/src/widgets/type_widgets/options/appearance.tsx
index abba618664..3d306ff97d 100644
--- a/apps/client/src/widgets/type_widgets/options/appearance.tsx
+++ b/apps/client/src/widgets/type_widgets/options/appearance.tsx
@@ -10,9 +10,8 @@ import zoomService from "../../../components/zoom";
import { ColorScheme, resolveColorScheme, THEME_FAMILY_SCHEMES } from "../../../services/color_scheme";
import { t } from "../../../services/i18n";
import server from "../../../services/server";
-import { isElectron, isMobile, reloadFrontendApp, restartDesktopApp } from "../../../services/utils";
+import { isElectron, isMobile, reloadFrontendApp } from "../../../services/utils";
import { VerticalLayoutIcon } from "../../buttons/global_menu";
-import Button from "../../react/Button";
import { Card, CardOption, CardSection } from "../../react/Card";
import Dropdown from "../../react/Dropdown";
import FormList, { FormListHeader, FormListItem } from "../../react/FormList";
@@ -28,6 +27,7 @@ import OptionsPageHeader from "./components/OptionsPageHeader";
import PlatformIndicator from "./components/PlatformIndicator";
import RadioWithIllustration from "./components/RadioWithIllustration";
import RelatedSettings from "./components/RelatedSettings";
+import RestartAction from "./components/RestartAction";
const MIN_CONTENT_WIDTH = 640;
@@ -690,16 +690,7 @@ function ElectronIntegration() {
</Card>
</div>
- {/* No card of its own — an action the card above calls for rather than a setting it
- holds — but kept to the cards' width, so it ends where their controls do. */}
- <div className="options-section appearance-restart">
- <Button
- name="restart-app-button"
- text={t("electron_integration.restart-app-button")}
- icon="bx-refresh"
- onClick={restartDesktopApp}
- />
- </div>
+ <RestartAction text={t("electron_integration.restart-app-button")} icon="bx-refresh" />
</>
);
}
diff --git a/apps/client/src/widgets/type_widgets/options/components/RestartAction.css b/apps/client/src/widgets/type_widgets/options/components/RestartAction.css
new file mode 100644
index 0000000000..725131e3a3
--- /dev/null
+++ b/apps/client/src/widgets/type_widgets/options/components/RestartAction.css
@@ -0,0 +1,5 @@
+/* Where the controls of the cards above it end, rather than under the labels it has nothing to do
+ with. */
+.restart-action {
+ text-align: end;
+}
diff --git a/apps/client/src/widgets/type_widgets/options/components/RestartAction.tsx b/apps/client/src/widgets/type_widgets/options/components/RestartAction.tsx
new file mode 100644
index 0000000000..2fcbb42853
--- /dev/null
+++ b/apps/client/src/widgets/type_widgets/options/components/RestartAction.tsx
@@ -0,0 +1,32 @@
+import "./RestartAction.css";
+
+import { restartDesktopApp } from "../../../../services/utils";
+import Button from "../../../react/Button";
+
+interface RestartActionProps {
+ /** How the page asks for it — one states what a restart is for, another that it is needed now. */
+ text: string;
+ /** Icon in {@link Button} format (e.g. `bx-refresh`, without the leading `bx `). */
+ icon?: string;
+}
+
+/**
+ * The way to start the app again, offered by a page whose settings only take effect once it has.
+ *
+ * No card of its own: it acts rather than holds anything, and a framed row of one button reads as a
+ * setting that has lost its label. It keeps the cards' width all the same, so it ends where their
+ * controls do rather than at the far edge of the page.
+ */
+export default function RestartAction({ text, icon }: RestartActionProps) {
+ return (
+ <div className="options-section restart-action">
+ <Button
+ name="restart-app-button"
+ text={text}
+ icon={icon}
+ size="micro"
+ onClick={restartDesktopApp}
+ />
+ </div>
+ );
+}
diff --git a/apps/client/src/widgets/type_widgets/options/i18n.css b/apps/client/src/widgets/type_widgets/options/i18n.css
index b70b2888ad..82ba253fb9 100644
--- a/apps/client/src/widgets/type_widgets/options/i18n.css
+++ b/apps/client/src/widgets/type_widgets/options/i18n.css
@@ -15,8 +15,3 @@
.i18n-content-languages ul {
margin-block: 1em !important;
}
-
-/* No card of its own, so it keeps the width of the ones above and ends where their controls do. */
-.i18n-restart {
- text-align: end;
-}
diff --git a/apps/client/src/widgets/type_widgets/options/i18n.tsx b/apps/client/src/widgets/type_widgets/options/i18n.tsx
index cd758d9e3f..08c5497a1c 100644
--- a/apps/client/src/widgets/type_widgets/options/i18n.tsx
+++ b/apps/client/src/widgets/type_widgets/options/i18n.tsx
@@ -4,8 +4,7 @@ import type { Locale } from "@triliumnext/commons";
import { useMemo } from "preact/hooks";
import { getAvailableLocales, t } from "../../../services/i18n";
-import { isElectron, restartDesktopApp } from "../../../services/utils";
-import Button from "../../react/Button";
+import { isElectron } from "../../../services/utils";
import { Card, CardOption, CardSection } from "../../react/Card";
import FormSelect from "../../react/FormSelect";
import { useTriliumOption, useTriliumOptionJson } from "../../react/hooks";
@@ -13,6 +12,7 @@ import CheckboxList from "./components/CheckboxList";
import { LocaleSelector } from "./components/LocaleSelector";
import OptionsPageHeader from "./components/OptionsPageHeader";
import RelatedSettings from "./components/RelatedSettings";
+import RestartAction from "./components/RestartAction";
export default function InternationalizationOptions() {
return (
@@ -21,7 +21,8 @@ export default function InternationalizationOptions() {
<LocalizationOptions />
<DateSettings />
<ContentLanguages />
- <RestartAction />
+ {/* Both cards above only take effect once the app has started again. */}
+ <RestartAction text={t("electron_integration.restart-app-button")} />
{isElectron() && (
<RelatedSettings items={[
{
@@ -190,20 +191,3 @@ export function ContentLanguagesList() {
);
}
-/**
- * Both cards above only take effect once the app has started again. The way to do that carries no
- * card of its own — it is an action the page offers rather than anything it holds — but keeps the
- * cards' width, so it ends where they do.
- */
-function RestartAction() {
- return (
- <div className="options-section i18n-restart">
- <Button
- name="restart-app-button"
- text={t("electron_integration.restart-app-button")}
- size="micro"
- onClick={restartDesktopApp}
- />
- </div>
- );
-}