From 562e1138c6f0b18a6e6ff0860321aba25c5e640f Mon Sep 17 00:00:00 2001 From: Kasper Date: Fri, 25 Oct 2024 12:32:56 +0200 Subject: [PATCH 1/4] Persist history --- web/src/App.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index 4cfdbcca..5d04f295 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -40,10 +40,16 @@ function NewTabLink({ children, href }: { children: ReactNode; href: string }) { ); } +const initialHistory = JSON.parse(localStorage.getItem('fend_history') || '[]'); + export default function App({ widget = false }: { widget?: boolean }) { const [currentInput, setCurrentInput] = useState(''); const [output, setOutput] = useState(widget ? <> : exampleContent); - const [history, setHistory] = useState([]); + const [history, setHistory] = useState(initialHistory); + useEffect(() => { + const history100 = history.slice(0, 100); + localStorage.setItem('fend_history', JSON.stringify(history100)); + }, [history]) const [variables, setVariables] = useState(''); const [navigation, setNavigation] = useState(0); const [hint, setHint] = useState(''); From bd7f48c7e05aeedea81f659278ed74d242f09cc1 Mon Sep 17 00:00:00 2001 From: Kasper Date: Fri, 25 Oct 2024 12:38:02 +0200 Subject: [PATCH 2/4] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0476db6..26f955b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Next * Add `text` as a synonym for `string` +* Keep history after reloading the web UI ### v1.5.3 (2024-10-06) From 28bdccb944fa909ce139267467e01788ceb33018 Mon Sep 17 00:00:00 2001 From: Kasper Date: Fri, 25 Oct 2024 12:58:53 +0200 Subject: [PATCH 3/4] Fix incorrect history saved --- web/src/App.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index 5d04f295..a10ba990 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -47,7 +47,7 @@ export default function App({ widget = false }: { widget?: boolean }) { const [output, setOutput] = useState(widget ? <> : exampleContent); const [history, setHistory] = useState(initialHistory); useEffect(() => { - const history100 = history.slice(0, 100); + const history100 = history.slice(-100); localStorage.setItem('fend_history', JSON.stringify(history100)); }, [history]) const [variables, setVariables] = useState(''); From bb012961b9208af22a6c54925d15b73dc38664a1 Mon Sep 17 00:00:00 2001 From: Kasper Date: Fri, 25 Oct 2024 13:09:52 +0200 Subject: [PATCH 4/4] Add missing semicolon --- web/src/App.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index a10ba990..c064b45b 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -49,7 +49,7 @@ export default function App({ widget = false }: { widget?: boolean }) { useEffect(() => { const history100 = history.slice(-100); localStorage.setItem('fend_history', JSON.stringify(history100)); - }, [history]) + }, [history]); const [variables, setVariables] = useState(''); const [navigation, setNavigation] = useState(0); const [hint, setHint] = useState('');