diff --git a/src/pages/settings/backup/SettingsBackupButtons.tsx b/src/pages/settings/backup/SettingsBackupButtons.tsx index fe34177..687cce0 100644 --- a/src/pages/settings/backup/SettingsBackupButtons.tsx +++ b/src/pages/settings/backup/SettingsBackupButtons.tsx @@ -2,12 +2,12 @@ // This file is part of KanjiSchool under AGPL-3.0. // Full details: https://github.com/Lemmmy/KanjiSchool/blob/master/LICENSE -import { AnySettingName } from "@utils"; +import { AnySettingName, OtherLocalStorageSettingName } from "@utils"; import { SettingsExportButton } from "./SettingsExportButton.tsx"; import { SettingsImportButton } from "./SettingsImportButton.tsx"; -export interface SettingsExportFile extends Partial> { +export interface SettingsExportFile extends Partial> { _exportedAt: string; _version: string; } diff --git a/src/pages/settings/backup/SettingsExportButton.tsx b/src/pages/settings/backup/SettingsExportButton.tsx index 2497c2b..cc40a62 100644 --- a/src/pages/settings/backup/SettingsExportButton.tsx +++ b/src/pages/settings/backup/SettingsExportButton.tsx @@ -10,7 +10,7 @@ import { SettingsExportFile } from "./SettingsBackupButtons.tsx"; import dayjs from "dayjs"; import { saveAs } from "file-saver"; -import { DEFAULT_SETTINGS, AnySettingName, getSettingKey } from "@utils"; +import { DEFAULT_SETTINGS, AnySettingName, getSettingKey, OTHER_LOCAL_STORAGE_SETTING_NAMES, lsGetKey } from "@utils"; import { globalNotification } from "@global/AntInterface.tsx"; import useBreakpoint from "antd/es/grid/hooks/useBreakpoint"; @@ -48,6 +48,16 @@ export function exportSettings(): void { } } + // Other settings (e.g. review presets, fonts) + for (const lsKey of OTHER_LOCAL_STORAGE_SETTING_NAMES) { + const stored = localStorage.getItem(lsGetKey(lsKey)); + + if (stored !== null) { + out[lsKey] = stored; + count++; + } + } + const outData = JSON.stringify(out); const filename = `KanjiSchool-settings-${dayjs().format("YYYY-MM-DD--HH-mm-ss")}.json`; const blob = new Blob([outData], { type: "application/json;charset=utf-8" }); diff --git a/src/pages/settings/backup/SettingsImportButton.tsx b/src/pages/settings/backup/SettingsImportButton.tsx index faa4d28..5265d9e 100644 --- a/src/pages/settings/backup/SettingsImportButton.tsx +++ b/src/pages/settings/backup/SettingsImportButton.tsx @@ -7,7 +7,7 @@ import { ImportOutlined } from "@ant-design/icons"; import { SettingsExportFile } from "./SettingsBackupButtons.tsx"; -import { AnySettingName, DEFAULT_SETTINGS, getSettingKey } from "@utils"; +import { AnySettingName, DEFAULT_SETTINGS, getSettingKey, lsGetKey, OTHER_LOCAL_STORAGE_SETTING_NAMES } from "@utils"; import { globalNotification } from "@global/AntInterface.tsx"; import { Button } from "antd"; @@ -89,6 +89,16 @@ export function importSettings(contents: string): void { } } + // Other settings (e.g. review presets, fonts) + for (const lsKey of OTHER_LOCAL_STORAGE_SETTING_NAMES) { + const stored = data[lsKey]; + + if (stored !== undefined) { + localStorage.setItem(lsGetKey(lsKey), stored); + count++; + } + } + globalNotification.success({ message: `Import ${count} settings. Site will refresh.` }); setTimeout(() => { location.reload(); }, 2000); } catch (e) { diff --git a/src/utils/settings/settings.ts b/src/utils/settings/settings.ts index 197f116..e1b02c2 100644 --- a/src/utils/settings/settings.ts +++ b/src/utils/settings/settings.ts @@ -300,6 +300,15 @@ export const DEFAULT_SETTINGS: SettingsState = { subjectInfoDebug: false }; +/** Other local storage keys that will be included in backups. */ +export const OTHER_LOCAL_STORAGE_SETTING_NAMES = [ + "lessonPresets", + "reviewPresets", + "customFonts", + "getReviewsWarning" +] as const; +export type OtherLocalStorageSettingName = typeof OTHER_LOCAL_STORAGE_SETTING_NAMES[number]; + export const SETTING_CONFIGS: Partial> = { dashboardReviewChartDays: { min: 1, max: 7 }, dashboardCriticalThreshold: { min: 1, max: 100 },