1
0
Fork 0
freesewing/sites/shared/hooks/useGist.js
Joost De Cock f82f7de5bb fix(shared): Don't force view to measurements by default
This is a bit of an annoyance since it forces you to the measurment
view, even for designs that have no required measurments.

So I've switched it to the draft view, and it should be the useEffect
code that detects whether required measurments are lacking and then
update the view.

FYI: @eriese
2022-06-23 09:58:54 +02:00

36 lines
870 B
JavaScript

import useLocalStorage from './useLocalStorage';
import set from 'lodash.set'
import unset from 'lodash.unset'
import defaultSettings from 'shared/components/workbench/default-settings.js'
// Generates a default design gist to start from
const defaultGist = (design, locale='en') => {
const gist = {
design: design.config.name,
version: design.config.version,
...defaultSettings,
_state: {view: 'draft'}
}
if (locale) gist.locale = locale
return gist
}
function reducer(gistState, {path, value, type='set'}) {
const newGist = {... gistState};
switch(type) {
case 'replace' :
return value;
case 'unset' :
unset(newGist, path);
break;
default:
set(newGist, path, value);
}
return newGist;
}
export function useGist(design, app) {
return useLocalStorage(`${design.config.name}_gist`, defaultGist(design, app.locale), reducer);
}