-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(form): add (auto)save and local schema repo
- Loading branch information
Showing
9 changed files
with
505 additions
and
65 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,31 @@ | ||
import schemaWizard from "./schemaWizard"; | ||
import schemaWizard, { initialState } from "./schemaWizard"; | ||
import { configureStore } from "@reduxjs/toolkit"; | ||
|
||
const preloadedState = () => { | ||
let parsedData; | ||
try { | ||
parsedData = JSON.parse(localStorage.getItem("formuleCurrent")); | ||
} catch (error) { | ||
console.error("Error parsing formuleCurrent from localStorage: ", error); | ||
} | ||
return parsedData || { schemaWizard: initialState }; | ||
}; | ||
|
||
export const persistMiddleware = ({ getState }) => { | ||
return (next) => (action) => { | ||
const result = next(action); | ||
localStorage.setItem("formuleCurrent", JSON.stringify(getState())); | ||
return result; | ||
}; | ||
}; | ||
|
||
const store = configureStore({ | ||
reducer: { | ||
schemaWizard, | ||
}, | ||
preloadedState: preloadedState(), | ||
middleware: (getDefaultMiddleware) => | ||
getDefaultMiddleware().concat(persistMiddleware), | ||
}); | ||
|
||
export default store; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters