diff --git a/webclient/src/App.js b/webclient/src/App.js index 9c5e192..0600e08 100644 --- a/webclient/src/App.js +++ b/webclient/src/App.js @@ -20,6 +20,11 @@ function App() { const cache = useRef({}); const [isFullScreen, setIsFullScreen] = useState(!!document.fullscreenElement); const [waitingWorker, setWaitingWorker] = useState(null); + const [settingsOpen, setSettingsOpen] = useState(false); + const defaultBodyFontSize = 16; + const defaultStoryFontSize = 1.2; + const [bodyFontSize, setBodyFontSize] = useState(Number(localStorage.getItem('bodyFontSize')) || defaultBodyFontSize); + const [storyFontSize, setStoryFontSize] = useState(Number(localStorage.getItem('storyFontSize')) || defaultStoryFontSize); const updateCache = useCallback((key, value) => { cache.current[key] = value; @@ -45,6 +50,27 @@ function App() { localStorage.setItem('theme', 'red'); }; + const changeBodyFontSize = (amount) => { + const newSize = bodyFontSize + amount; + setBodyFontSize(newSize); + localStorage.setItem('bodyFontSize', newSize); + }; + + const changeStoryFontSize = (amount) => { + const newSize = storyFontSize + amount; + setStoryFontSize(parseFloat(newSize.toFixed(1))); + localStorage.setItem('storyFontSize', newSize.toFixed(1)); + }; + + const resetFontSettings = () => { + setBodyFontSize(defaultBodyFontSize); + localStorage.removeItem('bodyFontSize'); + setStoryFontSize(defaultStoryFontSize); + localStorage.removeItem('storyFontSize'); + }; + + const fontSettingsChanged = bodyFontSize !== defaultBodyFontSize || storyFontSize !== defaultStoryFontSize; + useEffect(() => { const onSWUpdate = e => { setWaitingWorker(e.detail.waiting); @@ -92,6 +118,21 @@ function App() { } }, [theme]); + useEffect(() => { + document.documentElement.style.fontSize = `${bodyFontSize}px`; + }, [bodyFontSize]); + + useEffect(() => { + const styleId = 'story-font-size-style'; + let style = document.getElementById(styleId); + if (!style) { + style = document.createElement('style'); + style.id = styleId; + document.head.appendChild(style); + } + style.innerHTML = `.story-text { font-size: ${storyFontSize}rem !important; }`; + }, [storyFontSize]); + const fullScreenAvailable = document.fullscreenEnabled || document.mozFullscreenEnabled || document.webkitFullscreenEnabled || @@ -99,6 +140,33 @@ function App() { return (
QotNews
- light()}>Light - dark()}>Dark - black()}>Black - red()}>Red
+
Hacker News, Reddit, Lobsters, and Tildes articles rendered in reader mode.