From 09ea2535e0e42a20adf374fabcdb3ac44ef8316a Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Tue, 6 Jan 2026 20:08:43 +0000 Subject: [PATCH] refactor: Extract settings modal to dedicated component Co-authored-by: aider (gemini/gemini-2.5-pro) --- webclient/src/App.js | 182 ++++-------------------------------- webclient/src/Settings.js | 191 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 209 insertions(+), 164 deletions(-) diff --git a/webclient/src/App.js b/webclient/src/App.js index b3abdeb..ea16c7e 100644 --- a/webclient/src/App.js +++ b/webclient/src/App.js @@ -41,63 +41,6 @@ function App() { cache.current[key] = value; }, []); - const light = () => { - setTheme(''); - localStorage.setItem('theme', ''); - }; - - const dark = () => { - setTheme('dark'); - localStorage.setItem('theme', 'dark'); - }; - - const black = () => { - setTheme('black'); - localStorage.setItem('theme', 'black'); - }; - - const red = () => { - setTheme('red'); - localStorage.setItem('theme', 'red'); - }; - - const handleFilterChange = e => { - const isChecked = e.target.checked; - setFilterSmallweb(isChecked); - localStorage.setItem('filterSmallweb', isChecked); - }; - - const handleFeedSourceChange = (source) => { - setFeedSources(prevSources => { - const newSources = { ...prevSources, [source]: !prevSources[source] }; - localStorage.setItem('feedSources', JSON.stringify(newSources)); - return newSources; - }); - }; - - const changeBodyFont = (font) => { - setBodyFont(font); - localStorage.setItem('bodyFont', font); - }; - - const changeArticleFont = (font) => { - setArticleFont(font); - localStorage.setItem('articleFont', font); - }; - - const changeBodyFontSize = (amount) => { - const newSize = bodyFontSize + amount; - setBodyFontSize(parseFloat(newSize.toFixed(2))); - localStorage.setItem('bodyFontSize', newSize.toFixed(2)); - }; - - const resetBodyFontSize = () => { - setBodyFontSize(defaultBodyFontSize); - localStorage.removeItem('bodyFontSize'); - }; - - const bodyFontSettingsChanged = bodyFontSize !== defaultBodyFontSize; - useEffect(() => { const onSWUpdate = e => { setWaitingWorker(e.detail.waiting); @@ -116,17 +59,6 @@ function App() { } }, [updateCache]); - const goFullScreen = () => { - if ('wakeLock' in navigator) { - navigator.wakeLock.request('screen'); - } - document.body.requestFullscreen({ navigationUI: 'hide' }); - }; - - const exitFullScreen = () => { - document.exitFullscreen(); - }; - useEffect(() => { const onFullScreenChange = () => setIsFullScreen(!!document.fullscreenElement); document.addEventListener('fullscreenchange', onFullScreenChange); @@ -171,104 +103,26 @@ function App() { }, [articleFont]); - const fullScreenAvailable = document.fullscreenEnabled || - document.mozFullscreenEnabled || - document.webkitFullscreenEnabled || - document.msFullscreenEnabled; - return (
- {settingsOpen && - <> -
setSettingsOpen(false)}>
- -
e.stopPropagation()}> - -

Settings

- -
-

Theme

- - - - - {fullScreenAvailable && -
- {!isFullScreen ? - - : - - } -
- } -
- -
-

Feed

-
- - -
-
- handleFeedSourceChange('hackernews')} /> - -
-
- handleFeedSourceChange('reddit')} /> - -
-
- handleFeedSourceChange('lobsters')} /> - -
-
- handleFeedSourceChange('tildes')} /> - -
-
- -
-

Font Size

- - {bodyFontSize.toFixed(2)} - - -
- -
-

Body Font

-
- changeBodyFont('Sans Serif')} /> - -
-
- changeBodyFont('Serif')} /> - -
-
- changeBodyFont('Apparatus SIL')} /> - -
-
- -
-

Article Font

-
- changeArticleFont('Sans Serif')} /> - -
-
- changeArticleFont('Serif')} /> - -
-
- changeArticleFont('Apparatus SIL')} /> - -
-
-
- - } + {waitingWorker &&
diff --git a/webclient/src/Settings.js b/webclient/src/Settings.js index e69de29..383184b 100644 --- a/webclient/src/Settings.js +++ b/webclient/src/Settings.js @@ -0,0 +1,191 @@ +import React from 'react'; + +function Settings({ + settingsOpen, + setSettingsOpen, + theme, + setTheme, + isFullScreen, + filterSmallweb, + setFilterSmallweb, + feedSources, + setFeedSources, + bodyFontSize, + setBodyFontSize, + defaultBodyFontSize, + bodyFont, + setBodyFont, + articleFont, + setArticleFont, +}) { + const light = () => { + setTheme(''); + localStorage.setItem('theme', ''); + }; + + const dark = () => { + setTheme('dark'); + localStorage.setItem('theme', 'dark'); + }; + + const black = () => { + setTheme('black'); + localStorage.setItem('theme', 'black'); + }; + + const red = () => { + setTheme('red'); + localStorage.setItem('theme', 'red'); + }; + + const handleFilterChange = e => { + const isChecked = e.target.checked; + setFilterSmallweb(isChecked); + localStorage.setItem('filterSmallweb', isChecked); + }; + + const handleFeedSourceChange = (source) => { + setFeedSources(prevSources => { + const newSources = { ...prevSources, [source]: !prevSources[source] }; + localStorage.setItem('feedSources', JSON.stringify(newSources)); + return newSources; + }); + }; + + const changeBodyFont = (font) => { + setBodyFont(font); + localStorage.setItem('bodyFont', font); + }; + + const changeArticleFont = (font) => { + setArticleFont(font); + localStorage.setItem('articleFont', font); + }; + + const changeBodyFontSize = (amount) => { + const newSize = bodyFontSize + amount; + setBodyFontSize(parseFloat(newSize.toFixed(2))); + localStorage.setItem('bodyFontSize', newSize.toFixed(2)); + }; + + const resetBodyFontSize = () => { + setBodyFontSize(defaultBodyFontSize); + localStorage.removeItem('bodyFontSize'); + }; + + const bodyFontSettingsChanged = bodyFontSize !== defaultBodyFontSize; + + const goFullScreen = () => { + if ('wakeLock' in navigator) { + navigator.wakeLock.request('screen'); + } + document.body.requestFullscreen({ navigationUI: 'hide' }); + }; + + const exitFullScreen = () => { + document.exitFullscreen(); + }; + + const fullScreenAvailable = document.fullscreenEnabled || + document.mozFullscreenEnabled || + document.webkitFullscreenEnabled || + document.msFullscreenEnabled; + + if (!settingsOpen) { + return null; + } + + return ( + <> +
setSettingsOpen(false)}>
+ +
e.stopPropagation()}> + +

Settings

+ +
+

Theme

+ + + + + {fullScreenAvailable && +
+ {!isFullScreen ? + + : + + } +
+ } +
+ +
+

Feed

+
+ + +
+
+ handleFeedSourceChange('hackernews')} /> + +
+
+ handleFeedSourceChange('reddit')} /> + +
+
+ handleFeedSourceChange('lobsters')} /> + +
+
+ handleFeedSourceChange('tildes')} /> + +
+
+ +
+

Font Size

+ + {bodyFontSize.toFixed(2)} + + +
+ +
+

Body Font

+
+ changeBodyFont('Sans Serif')} /> + +
+
+ changeBodyFont('Serif')} /> + +
+
+ changeBodyFont('Apparatus SIL')} /> + +
+
+ +
+

Article Font

+
+ changeArticleFont('Sans Serif')} /> + +
+
+ changeArticleFont('Serif')} /> + +
+
+ changeArticleFont('Apparatus SIL')} /> + +
+
+
+ + ); +} + +export default Settings;