localstorage started

This commit is contained in:
Seth Trowbridge 2023-06-04 14:54:46 -04:00
parent 54d8928d11
commit 6c6220e5db

View File

@ -132,6 +132,7 @@ export function Reducer(inState, inAction)
clone.Live.Mark = Data !== null ? {Stim:clone.Stim.Value, Resp:Data} : undefined;
clone.Live.Freq[key] = clone.Live.Mark;
clone.Draw[key] = Redraw(clone.Live.Test, clone.Chan.Value, clone.Stim, true);
SaveTests(clone);
}
}
else if( Name=="Stim" || Name=="Chan" || Name=="Freq")
@ -159,32 +160,9 @@ export function Reducer(inState, inAction)
return clone;
}
/** @type {Store.State} */
export const Initial = Reducer(
{
Chan: { Min:0, Max:1, Value:0, Step:1 },
Freq: { Min:2, Max:8, Value:3, Step:1 },
Stim: { Min:-10, Max:120, Value:30, Step:5 },
Live:
{
Test: undefined,
Freq: undefined,
Mark: undefined
},
Draw:
{
UserL:{Points:[], Paths:[]},
UserR:{Points:[], Paths:[]},
TestL:{Points:[], Paths:[]},
TestR:{Points:[], Paths:[]}
},
Show:
{
Cursor:true,
Answer:false
},
TestIndex: 0,
Test: [
/** @type {Store.Test[]} */
const TestDefault = [
{
Name: "Patient A Asymmetric Notch",
Plot:
@ -237,7 +215,56 @@ export const Initial = Reducer(
{ Hz: 8000, TestL: { Stim: 0, Resp: true }, TestR: { Stim: 5, Resp: true } }
]
}
]
];
/** @type {Store.Test[] | string | null } */
let TestSaved = localStorage.getItem("app-tests");
if(TestSaved)
{
TestSaved = JSON.parse(TestSaved);
}
/**@type {(inState:Store.State)=>void} */
const SaveTests =(inState)=> localStorage.setItem("app-tests", JSON.stringify(inState.Test));
/**@type {(inState:Store.State)=>void} */
const SaveSettings =(inState)=> localStorage.setItem("app-settings", JSON.stringify({
Chan:inState.Chan,
Freq:inState.Freq,
Stim:inState.Stim,
Show:inState.Show,
TestIndex:inState.TestIndex,
}));
/** @type {Store.Test[]} */
const TestActual = Array.isArray(TestSaved) ? TestSaved : TestDefault
export const Initial = Reducer(
{
Chan: { Min:0, Max:1, Value:0, Step:1 },
Freq: { Min:2, Max:8, Value:3, Step:1 },
Stim: { Min:-10, Max:120, Value:30, Step:5 },
Live:
{
Test: undefined,
Freq: undefined,
Mark: undefined
},
Draw:
{
UserL:{Points:[], Paths:[]},
UserR:{Points:[], Paths:[]},
TestL:{Points:[], Paths:[]},
TestR:{Points:[], Paths:[]}
},
Show:
{
Cursor:true,
Answer:false
},
TestIndex: 0,
Test: TestActual
}, {Name:"Test", Data:0});