Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use local storage to remember user choices #1459

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions start-client/src/components/common/builder/Fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ function Fields({
const update = args => {
dispatchInitializr({ type: 'UPDATE', payload: args })
}
const getSelection = (options, key, localStorageKey) => {
const localStorageValue = localStorage.getItem(localStorageKey);
if(localStorageValue && options.find(item => item && item.key === localStorageValue)){
return localStorageValue;
}
return get(values, key);
}
const getOptions = name => {
return get(config, name)
}

return (
<>
Expand All @@ -45,10 +55,11 @@ function Fields({
<Control text='Project'>
<Radio
name='project'
selected={get(values, 'project')}
options={get(config, 'lists.project')}
selected={getSelection(getOptions('lists.project'), 'project', 'project')}
options={getOptions('lists.project')}
onChange={value => {
update({ project: value })
update({project: value})
localStorage.setItem('project', value)
}}
/>
</Control>
Expand All @@ -57,10 +68,11 @@ function Fields({
<Control text='Language'>
<Radio
name='language'
selected={get(values, 'language')}
options={get(config, 'lists.language')}
selected={getSelection(getOptions('lists.language'), 'language', 'language')}
options={getOptions('lists.language')}
onChange={value => {
update({ language: value })
update({language: value})
localStorage.setItem('language', value)
}}
/>
</Control>
Expand All @@ -72,7 +84,7 @@ function Fields({
name='boot'
selected={get(values, 'boot')}
error={get(errors, 'boot.value', '')}
options={get(config, 'lists.boot')}
options={getOptions('lists.boot')}
onChange={value => {
dispatchInitializr({
type: 'UPDATE',
Expand Down Expand Up @@ -135,20 +147,22 @@ function Fields({
/>
<FieldRadio
id='input-packaging'
value={get(values, 'meta.packaging')}
value={getSelection(getOptions('lists.meta.packaging'), 'meta.packaging', 'packaging')}
text='Packaging'
options={get(config, 'lists.meta.packaging')}
options={getOptions('lists.meta.packaging')}
onChange={value => {
update({ meta: { packaging: value } })
update({meta: {packaging: value}})
localStorage.setItem('packaging', value)
}}
/>
<FieldRadio
id='input-java'
value={get(values, 'meta.java')}
value={getSelection(getOptions('lists.meta.java'), 'meta.java', 'java')}
text='Java'
options={get(config, 'lists.meta.java')}
options={getOptions('lists.meta.java')}
onChange={value => {
update({ meta: { java: value } })
update({meta: {java: value}})
localStorage.setItem('java', value)
}}
/>
</Control>
Expand Down