From 3e17ff5e7bdbc7e3b9a281d7c268fe90af52e10e Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 19 Aug 2025 13:47:15 +0300 Subject: [PATCH] chore(react/settings): clean up options widget --- .../type_widgets/options/options_widget.ts | 77 ------------------- 1 file changed, 77 deletions(-) delete mode 100644 apps/client/src/widgets/type_widgets/options/options_widget.ts diff --git a/apps/client/src/widgets/type_widgets/options/options_widget.ts b/apps/client/src/widgets/type_widgets/options/options_widget.ts deleted file mode 100644 index 331358995..000000000 --- a/apps/client/src/widgets/type_widgets/options/options_widget.ts +++ /dev/null @@ -1,77 +0,0 @@ -import type { FilterOptionsByType, OptionMap, OptionNames } from "@triliumnext/commons"; -import type { EventData, EventListener } from "../../../components/app_context.js"; -import type FNote from "../../../entities/fnote.js"; -import { t } from "../../../services/i18n.js"; -import server from "../../../services/server.js"; -import toastService from "../../../services/toast.js"; -import NoteContextAwareWidget from "../../note_context_aware_widget.js"; - -export default class OptionsWidget extends NoteContextAwareWidget implements EventListener<"entitiesReloaded"> { - constructor() { - super(); - - this.contentSized(); - } - - async updateOption(name: T, value: string | number | string[] | undefined) { - const opts = { [name]: value }; - - await this.updateMultipleOptions(opts); - } - - async updateMultipleOptions(opts: Partial) { - await server.put("options", opts); - - this.showUpdateNotification(); - } - - showUpdateNotification() { - toastService.showPersistent({ - id: "options-change-saved", - title: t("options_widget.options_status"), - message: t("options_widget.options_change_saved"), - icon: "slider", - closeAfter: 2000 - }); - } - - async updateCheckboxOption>(name: T, $checkbox: JQuery) { - const isChecked = $checkbox.prop("checked"); - - return await this.updateOption(name, isChecked ? "true" : "false"); - } - - setCheckboxState($checkbox: JQuery, optionValue: string) { - $checkbox.prop("checked", optionValue === "true"); - } - - optionsLoaded(options: OptionMap) { } - - async refresh() { - this.toggleInt(this.isEnabled()); - try { - await this.refreshWithNote(this.note); - } catch (e) { - // Ignore errors when user is refreshing or navigating away. - if (e === "rejected by browser") { - return; - } - - throw e; - } - } - - async refreshWithNote(note: FNote | null | undefined) { - const options = await server.get("options"); - - if (options) { - this.optionsLoaded(options); - } - } - - async entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) { - if (loadResults.getOptionNames().length > 0) { - this.refresh(); - } - } -}