From 59181a4de9cea578ea4a2e471ab6fad3ab6890f6 Mon Sep 17 00:00:00 2001
From: Antonio De Lucreziis
Date: Mon, 20 Jan 2025 18:36:37 +0100
Subject: [PATCH] added stored problems
---
src/main.tsx | 66 ++++++++++++++++++++++++++++++++++++++++++
src/parser-problem.tsx | 8 +++++
src/style.css | 49 +++++++++++++++++++++++++++++++
3 files changed, 123 insertions(+)
diff --git a/src/main.tsx b/src/main.tsx
index 08136df..ccc3ee5 100644
--- a/src/main.tsx
+++ b/src/main.tsx
@@ -22,7 +22,26 @@ b = 4
B = 2 3;
`.trim()
+const useLocalStorage = (key: string, initialValue: T) => {
+ const [value, setValue] = useState(() => {
+ const item = window.localStorage.getItem(key)
+ return item ? JSON.parse(item) : initialValue
+ })
+
+ const setItem = (newValue: T) => {
+ setValue(newValue)
+ window.localStorage.setItem(key, JSON.stringify(newValue))
+ }
+
+ return [value, setItem] as const
+}
+
const App = () => {
+ const [currentProblemName, setCurrentProblemName] = useState('Pintel')
+ const [savedProblems, setSavedProblems] = useLocalStorage<{ name: string; source: string }[]>('savedProblems', [
+ { name: 'Pintel', source: INITIAL_PROBLEM_INPUT },
+ ])
+
const [problemInput, setProblemInput] = useState(INITIAL_PROBLEM_INPUT)
const problemValuesResult = parseSafeProblemInput(problemInput)
@@ -36,6 +55,53 @@ const App = () => {
Visualizzazione
I dati del problema vanno inseriti nel seguente campo di testo nel formato:
+
+
+
+
+
{
+ const name = e.currentTarget.value
+ setCurrentProblemName(name)
+ }}
+ value={currentProblemName}
+ />
+
+
+