From d8bfa10b43dbc233989bd57116cfab58532e006f Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 13 Nov 2025 16:10:19 -0600 Subject: [PATCH] Indicate non-default System Settings, allow clicking to restore to default --- src/components/AppProvider.tsx | 1 + src/components/SentryProvider.test.tsx | 8 +- src/contexts/AppContext.ts | 2 + src/hooks/useAIProjectId.test.ts | 44 +- src/locales/en.json | 5 +- src/locales/ha.json | 5 +- src/locales/ig.json | 5 +- src/locales/pt.json | 5 +- src/locales/yo.json | 5 +- src/locales/zh.json | 5 +- src/pages/SystemSettings.tsx | 701 ++++++++++++++++++------- 11 files changed, 561 insertions(+), 225 deletions(-) diff --git a/src/components/AppProvider.tsx b/src/components/AppProvider.tsx index 5de70a95..0db9c91c 100644 --- a/src/components/AppProvider.tsx +++ b/src/components/AppProvider.tsx @@ -79,6 +79,7 @@ export function AppProvider(props: AppProviderProps) { const appContextValue: AppContextType = { config, + defaultConfig, updateConfig, }; diff --git a/src/components/SentryProvider.test.tsx b/src/components/SentryProvider.test.tsx index 31b0e487..70369f04 100644 --- a/src/components/SentryProvider.test.tsx +++ b/src/components/SentryProvider.test.tsx @@ -42,7 +42,7 @@ describe('SentryProvider', () => { }; render( - +
Test
@@ -78,7 +78,7 @@ describe('SentryProvider', () => { }; render( - +
Test
@@ -115,7 +115,7 @@ describe('SentryProvider', () => { }; render( - +
Test
@@ -155,7 +155,7 @@ describe('SentryProvider', () => { }; render( - +
Test
diff --git a/src/contexts/AppContext.ts b/src/contexts/AppContext.ts index de186fe5..8577602d 100644 --- a/src/contexts/AppContext.ts +++ b/src/contexts/AppContext.ts @@ -49,6 +49,8 @@ export interface AppConfig { export interface AppContextType { /** Current application configuration */ config: AppConfig; + /** Default application configuration */ + defaultConfig: AppConfig; /** Update configuration using a callback that receives current config and returns new config */ updateConfig: (updater: (currentConfig: Partial) => Partial) => void; } diff --git a/src/hooks/useAIProjectId.test.ts b/src/hooks/useAIProjectId.test.ts index 42b5eb19..26026962 100644 --- a/src/hooks/useAIProjectId.test.ts +++ b/src/hooks/useAIProjectId.test.ts @@ -38,28 +38,30 @@ describe('useAIProjectId', () => { }); // Mock useAppContext - mockUseAppContext.mockReturnValue({ - config: { - theme: 'dark', - relayMetadata: { - relays: [{ url: 'wss://relay.damus.io', read: true, write: true }], - updatedAt: 0, - }, - projectTemplate: 'https://github.com/example/template', - esmUrl: 'https://esm.sh', - corsProxy: 'https://proxy.example.com/{href}', - faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico', - previewDomain: 'local-shakespeare.dev', - showcaseEnabled: true, - showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc', - ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'], - fsPathProjects: '/projects', - fsPathConfig: '/config', - fsPathTmp: '/tmp', - fsPathPlugins: '/plugins', - sentryDsn: '', - sentryEnabled: false, + const config = { + theme: 'dark' as const, + relayMetadata: { + relays: [{ url: 'wss://relay.damus.io', read: true, write: true }], + updatedAt: 0, }, + projectTemplate: 'https://github.com/example/template', + esmUrl: 'https://esm.sh', + corsProxy: 'https://proxy.example.com/{href}', + faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico', + previewDomain: 'local-shakespeare.dev', + showcaseEnabled: true, + showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc', + ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'], + fsPathProjects: '/projects', + fsPathConfig: '/config', + fsPathTmp: '/tmp', + fsPathPlugins: '/plugins', + sentryDsn: '', + sentryEnabled: false, + }; + mockUseAppContext.mockReturnValue({ + config, + defaultConfig: config, updateConfig: vi.fn(), }); diff --git a/src/locales/en.json b/src/locales/en.json index 2ff60d9d..ea5788e0 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -483,5 +483,8 @@ "configDirectoryDescription": "Directory where configuration files are stored in the virtual filesystem.", "temporaryDirectory": "Temporary Directory", "temporaryDirectoryDescription": "Directory for temporary files in the virtual filesystem.", - "deleting": "Deleting..." + "deleting": "Deleting...", + "modified": "Modified", + "restoreToDefault": "Restore to default", + "restoredToDefault": "Restored to Default" } diff --git a/src/locales/ha.json b/src/locales/ha.json index 95a3ccb7..3f476d43 100644 --- a/src/locales/ha.json +++ b/src/locales/ha.json @@ -422,5 +422,8 @@ "invalidGiftCard": "Katin Kyauta Ba Daidai Ba", "giftCardNotFound": "Ba a iya samun wannan katin kyauta.", "alreadyRedeemed": "An riga an Fanshi", - "giftCardAlreadyRedeemed": "An riga an fanshi wannan katin kyauta." + "giftCardAlreadyRedeemed": "An riga an fanshi wannan katin kyauta.", + "modified": "An Canza", + "restoreToDefault": "Mayar da asali", + "restoredToDefault": "An Mayar da Asali" } diff --git a/src/locales/ig.json b/src/locales/ig.json index 7db02e97..8a88cd31 100644 --- a/src/locales/ig.json +++ b/src/locales/ig.json @@ -419,5 +419,8 @@ "invalidGiftCard": "Kaadị Onyinye Na-ezighị Ezi", "giftCardNotFound": "Achọtaghị kaadị onyinye a.", "alreadyRedeemed": "Egbapụtalarị", - "giftCardAlreadyRedeemed": "Egbapụtalarị kaadị onyinye a." + "giftCardAlreadyRedeemed": "Egbapụtalarị kaadị onyinye a.", + "modified": "Gbanwere", + "restoreToDefault": "Weghachi na nke mbụ", + "restoredToDefault": "Weghachiri na Nke Mbụ" } diff --git a/src/locales/pt.json b/src/locales/pt.json index 8c3d3023..5fc8017a 100644 --- a/src/locales/pt.json +++ b/src/locales/pt.json @@ -432,5 +432,8 @@ "invalidGiftCard": "Cartão Presente Inválido", "giftCardNotFound": "Este cartão presente não pôde ser encontrado.", "alreadyRedeemed": "Já Resgatado", - "giftCardAlreadyRedeemed": "Este cartão presente já foi resgatado." + "giftCardAlreadyRedeemed": "Este cartão presente já foi resgatado.", + "modified": "Modificado", + "restoreToDefault": "Restaurar para padrão", + "restoredToDefault": "Restaurado para Padrão" } diff --git a/src/locales/yo.json b/src/locales/yo.json index 440db1f9..79277e8e 100644 --- a/src/locales/yo.json +++ b/src/locales/yo.json @@ -419,5 +419,8 @@ "invalidGiftCard": "Kaadi Ẹbun Ti ko Tọ", "giftCardNotFound": "A ko le ri kaadi ẹbun yii.", "alreadyRedeemed": "Ti ra Tẹlẹ", - "giftCardAlreadyRedeemed": "A ti ra kaadi ẹbun yii tẹlẹ." + "giftCardAlreadyRedeemed": "A ti ra kaadi ẹbun yii tẹlẹ.", + "modified": "Ti Yipada", + "restoreToDefault": "Pada si atilẹwa", + "restoredToDefault": "Ti Pada si Atilẹwa" } diff --git a/src/locales/zh.json b/src/locales/zh.json index 71f75dc8..d81fb551 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -432,5 +432,8 @@ "invalidGiftCard": "无效的礼品卡", "giftCardNotFound": "找不到此礼品卡。", "alreadyRedeemed": "已兑换", - "giftCardAlreadyRedeemed": "此礼品卡已被兑换。" + "giftCardAlreadyRedeemed": "此礼品卡已被兑换。", + "modified": "已修改", + "restoreToDefault": "恢复默认值", + "restoredToDefault": "已恢复默认值" } diff --git a/src/pages/SystemSettings.tsx b/src/pages/SystemSettings.tsx index cf55b98d..f441602f 100644 --- a/src/pages/SystemSettings.tsx +++ b/src/pages/SystemSettings.tsx @@ -1,6 +1,6 @@ -import { Settings, ArrowLeft, RefreshCw, Trash2, XCircle, Loader2 } from "lucide-react"; +import { Settings, ArrowLeft, RefreshCw, Trash2, XCircle, Loader2, RotateCcw } from "lucide-react"; import { useTranslation } from 'react-i18next'; -import { useState, useEffect } from "react"; +import { useState, useEffect, useMemo } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Switch } from "@/components/ui/switch"; @@ -16,7 +16,7 @@ export function SystemSettings() { const { t } = useTranslation(); const isMobile = useIsMobile(); const navigate = useNavigate(); - const { config, updateConfig } = useAppContext(); + const { config, defaultConfig, updateConfig } = useAppContext(); const { toast } = useToast(); const { serviceWorkerRegistration, updateServiceWorker, clearCache } = useOffline(); @@ -32,6 +32,94 @@ export function SystemSettings() { const [fsPathPluginsInput, setFsPathPluginsInput] = useState(config.fsPathPlugins); const [sentryDsnInput, setSentryDsnInput] = useState(config.sentryDsn); + // Check which settings differ from defaults + const isModified = useMemo(() => ({ + projectTemplate: config.projectTemplate !== defaultConfig.projectTemplate, + esmUrl: config.esmUrl !== defaultConfig.esmUrl, + corsProxy: config.corsProxy !== defaultConfig.corsProxy, + faviconUrl: config.faviconUrl !== defaultConfig.faviconUrl, + previewDomain: config.previewDomain !== defaultConfig.previewDomain, + showcaseEnabled: config.showcaseEnabled !== defaultConfig.showcaseEnabled, + showcaseModerator: config.showcaseModerator !== defaultConfig.showcaseModerator, + fsPathProjects: config.fsPathProjects !== defaultConfig.fsPathProjects, + fsPathConfig: config.fsPathConfig !== defaultConfig.fsPathConfig, + fsPathTmp: config.fsPathTmp !== defaultConfig.fsPathTmp, + fsPathPlugins: config.fsPathPlugins !== defaultConfig.fsPathPlugins, + sentryDsn: config.sentryDsn !== defaultConfig.sentryDsn, + }), [config, defaultConfig]); + + // Restore functions + const restoreProjectTemplate = () => { + const defaultValue = defaultConfig.projectTemplate; + setProjectTemplateInput(defaultValue); + updateConfig((current) => ({ ...current, projectTemplate: defaultValue })); + }; + + const restoreEsmUrl = () => { + const defaultValue = defaultConfig.esmUrl; + setEsmUrlInput(defaultValue); + updateConfig((current) => ({ ...current, esmUrl: defaultValue })); + }; + + const restoreCorsProxy = () => { + const defaultValue = defaultConfig.corsProxy; + setCorsProxyInput(defaultValue); + updateConfig((current) => ({ ...current, corsProxy: defaultValue })); + }; + + const restoreFaviconUrl = () => { + const defaultValue = defaultConfig.faviconUrl; + setFaviconUrlInput(defaultValue); + updateConfig((current) => ({ ...current, faviconUrl: defaultValue })); + }; + + const restorePreviewDomain = () => { + const defaultValue = defaultConfig.previewDomain; + setPreviewDomainInput(defaultValue); + updateConfig((current) => ({ ...current, previewDomain: defaultValue })); + }; + + const restoreShowcaseEnabled = () => { + const defaultValue = defaultConfig.showcaseEnabled; + updateConfig((current) => ({ ...current, showcaseEnabled: defaultValue })); + }; + + const restoreShowcaseModerator = () => { + const defaultValue = defaultConfig.showcaseModerator; + setShowcaseModeratorInput(defaultValue); + updateConfig((current) => ({ ...current, showcaseModerator: defaultValue })); + }; + + const restoreFsPathProjects = () => { + const defaultValue = defaultConfig.fsPathProjects; + setFsPathProjectsInput(defaultValue); + updateConfig((current) => ({ ...current, fsPathProjects: defaultValue })); + }; + + const restoreFsPathConfig = () => { + const defaultValue = defaultConfig.fsPathConfig; + setFsPathConfigInput(defaultValue); + updateConfig((current) => ({ ...current, fsPathConfig: defaultValue })); + }; + + const restoreFsPathTmp = () => { + const defaultValue = defaultConfig.fsPathTmp; + setFsPathTmpInput(defaultValue); + updateConfig((current) => ({ ...current, fsPathTmp: defaultValue })); + }; + + const restoreFsPathPlugins = () => { + const defaultValue = defaultConfig.fsPathPlugins; + setFsPathPluginsInput(defaultValue); + updateConfig((current) => ({ ...current, fsPathPlugins: defaultValue })); + }; + + const restoreSentryDsn = () => { + const defaultValue = defaultConfig.sentryDsn; + setSentryDsnInput(defaultValue); + updateConfig((current) => ({ ...current, sentryDsn: defaultValue })); + }; + // Service Worker state const [swState, setSwState] = useState(''); const [isUpdatingSW, setIsUpdatingSW] = useState(false); @@ -265,24 +353,42 @@ export function SystemSettings() { -

{t('projectTemplate')}

+
+

{t('projectTemplate')}

+ {isModified.projectTemplate && ( +
+ )} +
- { - const value = e.target.value; - setProjectTemplateInput(value); - updateConfig((current) => ({ - ...current, - projectTemplate: value, - })); - }} - /> +
+ { + const value = e.target.value; + setProjectTemplateInput(value); + updateConfig((current) => ({ + ...current, + projectTemplate: value, + })); + }} + className="flex-1" + /> + {isModified.projectTemplate && ( + + )} +

{t('projectTemplateDescription')}

@@ -295,24 +401,42 @@ export function SystemSettings() { -

{t('corsProxy')}

+
+

{t('corsProxy')}

+ {isModified.corsProxy && ( +
+ )} +
- { - const value = e.target.value; - setCorsProxyInput(value); - updateConfig((current) => ({ - ...current, - corsProxy: value, - })); - }} - /> +
+ { + const value = e.target.value; + setCorsProxyInput(value); + updateConfig((current) => ({ + ...current, + corsProxy: value, + })); + }} + className="flex-1" + /> + {isModified.corsProxy && ( + + )} +

{t('corsProxyDescription')}

@@ -325,24 +449,42 @@ export function SystemSettings() { -

{t('faviconUrl')}

+
+

{t('faviconUrl')}

+ {isModified.faviconUrl && ( +
+ )} +
- { - const value = e.target.value; - setFaviconUrlInput(value); - updateConfig((current) => ({ - ...current, - faviconUrl: value, - })); - }} - /> +
+ { + const value = e.target.value; + setFaviconUrlInput(value); + updateConfig((current) => ({ + ...current, + faviconUrl: value, + })); + }} + className="flex-1" + /> + {isModified.faviconUrl && ( + + )} +

{t('faviconUrlDescription')}

@@ -355,25 +497,43 @@ export function SystemSettings() { -

{t('esmUrl')}

+
+

{t('esmUrl')}

+ {isModified.esmUrl && ( +
+ )} +
- { - // Strip trailing slash on save. - const value = e.target.value; - setEsmUrlInput(value); - updateConfig((current) => ({ - ...current, - esmUrl: value.replace(/\/+$/, ''), - })); - }} - /> +
+ { + // Strip trailing slash on save. + const value = e.target.value; + setEsmUrlInput(value); + updateConfig((current) => ({ + ...current, + esmUrl: value.replace(/\/+$/, ''), + })); + }} + className="flex-1" + /> + {isModified.esmUrl && ( + + )} +

{t('esmUrlDescription')}

@@ -386,24 +546,42 @@ export function SystemSettings() { -

{t('previewDomain')}

+
+

{t('previewDomain')}

+ {isModified.previewDomain && ( +
+ )} +
- { - const value = e.target.value; - setPreviewDomainInput(value); - updateConfig((current) => ({ - ...current, - previewDomain: value, - })); - }} - /> +
+ { + const value = e.target.value; + setPreviewDomainInput(value); + updateConfig((current) => ({ + ...current, + previewDomain: value, + })); + }} + className="flex-1" + /> + {isModified.previewDomain && ( + + )} +

{t('previewDomainDescription')}

@@ -416,47 +594,87 @@ export function SystemSettings() { -

{t('showcase')}

+
+

{t('showcase')}

+ {(isModified.showcaseEnabled || isModified.showcaseModerator) && ( +
+ )} +
- - { - updateConfig((current) => ({ - ...current, - showcaseEnabled: checked, - })); - }} - /> +
+ + {isModified.showcaseEnabled && ( +
+ )} +
+
+ { + updateConfig((current) => ({ + ...current, + showcaseEnabled: checked, + })); + }} + /> + {isModified.showcaseEnabled && ( + + )} +

{t('showcaseEnabledDescription')}

- - { - const value = e.target.value; - setShowcaseModeratorInput(value); - updateConfig((current) => ({ - ...current, - showcaseModerator: value, - })); - }} - /> +
+ + {isModified.showcaseModerator && ( +
+ )} +
+
+ { + const value = e.target.value; + setShowcaseModeratorInput(value); + updateConfig((current) => ({ + ...current, + showcaseModerator: value, + })); + }} + className="flex-1" + /> + {isModified.showcaseModerator && ( + + )} +

{t('showcaseModeratorDescription')}

@@ -470,24 +688,42 @@ export function SystemSettings() { -

{t('sentryDsn')}

+
+

{t('sentryDsn')}

+ {isModified.sentryDsn && ( +
+ )} +
- { - const value = e.target.value; - setSentryDsnInput(value); - updateConfig((current) => ({ - ...current, - sentryDsn: value, - })); - }} - /> +
+ { + const value = e.target.value; + setSentryDsnInput(value); + updateConfig((current) => ({ + ...current, + sentryDsn: value, + })); + }} + className="flex-1" + /> + {isModified.sentryDsn && ( + + )} +

{t('sentryDsnDescription')}

@@ -500,97 +736,174 @@ export function SystemSettings() { -

{t('filesystemPaths')}

+
+

{t('filesystemPaths')}

+ {(isModified.fsPathProjects || isModified.fsPathConfig || isModified.fsPathTmp || isModified.fsPathPlugins) && ( +
+ )} +
- - { - const value = e.target.value; - setFsPathProjectsInput(value); - updateConfig((current) => ({ - ...current, - fsPathProjects: value, - })); - }} - /> +
+ + {isModified.fsPathProjects && ( +
+ )} +
+
+ { + const value = e.target.value; + setFsPathProjectsInput(value); + updateConfig((current) => ({ + ...current, + fsPathProjects: value, + })); + }} + className="flex-1" + /> + {isModified.fsPathProjects && ( + + )} +

{t('projectsDirectoryDescription')}

- - { - const value = e.target.value; - setFsPathConfigInput(value); - updateConfig((current) => ({ - ...current, - fsPathConfig: value, - })); - }} - /> +
+ + {isModified.fsPathConfig && ( +
+ )} +
+
+ { + const value = e.target.value; + setFsPathConfigInput(value); + updateConfig((current) => ({ + ...current, + fsPathConfig: value, + })); + }} + className="flex-1" + /> + {isModified.fsPathConfig && ( + + )} +

{t('configDirectoryDescription')}

- - { - const value = e.target.value; - setFsPathTmpInput(value); - updateConfig((current) => ({ - ...current, - fsPathTmp: value, - })); - }} - /> +
+ + {isModified.fsPathTmp && ( +
+ )} +
+
+ { + const value = e.target.value; + setFsPathTmpInput(value); + updateConfig((current) => ({ + ...current, + fsPathTmp: value, + })); + }} + className="flex-1" + /> + {isModified.fsPathTmp && ( + + )} +

{t('temporaryDirectoryDescription')}

- - { - const value = e.target.value; - setFsPathPluginsInput(value); - updateConfig((current) => ({ - ...current, - fsPathPlugins: value, - })); - }} - /> +
+ + {isModified.fsPathPlugins && ( +
+ )} +
+
+ { + const value = e.target.value; + setFsPathPluginsInput(value); + updateConfig((current) => ({ + ...current, + fsPathPlugins: value, + })); + }} + className="flex-1" + /> + {isModified.fsPathPlugins && ( + + )} +

{t('pluginsDirectoryDescription')}