diff --git a/package-lock.json b/package-lock.json index a573358..b440fbd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@digicatapult/sqnc-hyproof-client", - "version": "0.3.8", + "version": "0.3.9", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@digicatapult/sqnc-hyproof-client", - "version": "0.3.8", + "version": "0.3.9", "license": "Apache-2.0", "dependencies": { "@digicatapult/ui-component-library": "^0.19.4", diff --git a/package.json b/package.json index f0f1013..18913f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@digicatapult/sqnc-hyproof-client", - "version": "0.3.8", + "version": "0.3.9", "description": "User interface for HyProof", "homepage": "https://github.com/digicatapult/sqnc-hyproof-client", "main": "src/index.js", diff --git a/src/App.js b/src/App.js index e80397f..0b0d3a6 100644 --- a/src/App.js +++ b/src/App.js @@ -50,6 +50,7 @@ export const personas = [ export default function App() { const { + reset, update, current, currentId, @@ -65,6 +66,7 @@ export default function App() { const resetDemonstrator = (e) => { e.preventDefault() + reset() window.location.replace('/') } diff --git a/src/pages/components/Nav.js b/src/pages/components/Nav.js index 9b5eb37..ced0252 100644 --- a/src/pages/components/Nav.js +++ b/src/pages/components/Nav.js @@ -12,7 +12,6 @@ export default function Nav() { const path = window.location.pathname const dialogRef = useRef(null) - const inactive = (e) => e.preventDefault() const showPopup = (e) => { e.preventDefault() dialogRef.current?.showModal() @@ -33,14 +32,14 @@ export default function Nav() { accent: '#FFF', }} > - - what we do + + what we do - certificates + certificates @@ -71,11 +70,3 @@ const Home = styled(Grid.Panel)` padding-left: 20px; padding-right: 20px; ` - -const WhiteLink = styled(Link)` - color: white; - text-decoration: none; - &:hover { - color: #dbe9e8; - } -` diff --git a/src/utils/Context.js b/src/utils/Context.js index a9c9f6a..1cee46d 100644 --- a/src/utils/Context.js +++ b/src/utils/Context.js @@ -1,20 +1,31 @@ -import React, { createContext, useState } from 'react' +import React, { createContext, useEffect, useState } from 'react' export const Context = createContext({}) +const stateKey = 'demo-state' +const defaultState = { + current: 'heidi', + currentId: '', + currentCommitment: '', + currentCommitmentSalt: '', + currentEnergyConsumedWh: 0, + currentProductionStartTime: '', + currentProductionEndTime: '', + emma: {}, + heidi: {}, + reginald: {}, +} +let initState = defaultState +try { + initState = JSON.parse(localStorage.getItem(stateKey)) || initState +} catch (e) { + localStorage.removeItem(stateKey) +} + // this is a provider for initial and state updates export const ContextProvider = ({ children }) => { const [state, setState] = useState({ - current: 'heidi', - currentId: '', - currentCommitment: '', - currentCommitmentSalt: '', - currentEnergyConsumedWh: 0, - currentProductionStartTime: '', - currentProductionEndTime: '', - emma: {}, - heidi: {}, - reginald: {}, + ...initState, update: (val, key) => { if (!val) return state if (!key) return setState({ ...state, ...val }) @@ -27,7 +38,15 @@ export const ContextProvider = ({ children }) => { }, }) }, + reset: () => { + localStorage.removeItem(stateKey) + }, }) + useEffect(() => { + const { update, ...storedState } = state + localStorage.setItem(stateKey, JSON.stringify(storedState)) + }, [state]) + return {children} }