From e4a22f2bc65aa3f9593edb1bea3f1ce1eaf2266d Mon Sep 17 00:00:00 2001
From: 4121nnn <4121nnn@gmail.com>
Date: Fri, 3 May 2024 00:19:24 +0300
Subject: [PATCH 1/2] Use local storage to remember user choices
---
.../src/components/common/builder/Fields.js | 33 +++++++++++++------
1 file changed, 23 insertions(+), 10 deletions(-)
diff --git a/start-client/src/components/common/builder/Fields.js b/start-client/src/components/common/builder/Fields.js
index 9b94940eca..6ed7c6ed17 100644
--- a/start-client/src/components/common/builder/Fields.js
+++ b/start-client/src/components/common/builder/Fields.js
@@ -30,8 +30,18 @@ function Fields({
dispatch: dispatchInitializr,
errors,
} = useContext(InitializrContext)
- const update = args => {
+ const update = (args, storageKey) => {
dispatchInitializr({ type: 'UPDATE', payload: args })
+ if(storageKey){
+ localStorage.setItem('spring' + storageKey, args[storageKey]);
+ }
+ }
+ function getValue(array, key) {
+ const localStorageValue = localStorage.getItem('spring' + key);
+ if(array.find(item => item && item.key === localStorageValue)){
+ return localStorageValue;
+ }
+ return get(values, key);
}
return (
@@ -45,10 +55,10 @@ function Fields({
{
- update({ project: value })
+ update({project: value}, 'project')
}}
/>
@@ -57,10 +67,10 @@ function Fields({
{
- update({ language: value })
+ update({language: value}, 'language')
}}
/>
@@ -70,7 +80,7 @@ function Fields({
{
@@ -83,6 +93,7 @@ function Fields({
type: 'UPDATE_DEPENDENCIES',
payload: { boot: value },
})
+ localStorage.setItem('springboot', value)
}}
/>
{get(errors, 'boot') && (
@@ -135,20 +146,22 @@ function Fields({
/>
{
- update({ meta: { packaging: value } })
+ update({meta: {packaging: value}})
+ localStorage.setItem('springmeta.packaging', value)
}}
/>
{
- update({ meta: { java: value } })
+ update({meta: {java: value}})
+ localStorage.setItem('springmeta.java', value)
}}
/>
From 05d85c7859a2738546a0be25ee3607160c04bf08 Mon Sep 17 00:00:00 2001
From: Moritz Halbritter
Date: Fri, 3 May 2024 10:09:27 +0200
Subject: [PATCH 2/2] Polish
---
.../src/components/common/builder/Fields.js | 45 ++++++++++---------
1 file changed, 23 insertions(+), 22 deletions(-)
diff --git a/start-client/src/components/common/builder/Fields.js b/start-client/src/components/common/builder/Fields.js
index 6ed7c6ed17..10c411b86b 100644
--- a/start-client/src/components/common/builder/Fields.js
+++ b/start-client/src/components/common/builder/Fields.js
@@ -30,19 +30,19 @@ function Fields({
dispatch: dispatchInitializr,
errors,
} = useContext(InitializrContext)
- const update = (args, storageKey) => {
+ const update = args => {
dispatchInitializr({ type: 'UPDATE', payload: args })
- if(storageKey){
- localStorage.setItem('spring' + storageKey, args[storageKey]);
- }
}
- function getValue(array, key) {
- const localStorageValue = localStorage.getItem('spring' + key);
- if(array.find(item => item && item.key === localStorageValue)){
+ 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 (
<>
@@ -55,10 +55,11 @@ function Fields({
{
- update({project: value}, 'project')
+ update({project: value})
+ localStorage.setItem('project', value)
}}
/>
@@ -67,10 +68,11 @@ function Fields({
{
- update({language: value}, 'language')
+ update({language: value})
+ localStorage.setItem('language', value)
}}
/>
@@ -80,9 +82,9 @@ function Fields({
{
dispatchInitializr({
type: 'UPDATE',
@@ -93,7 +95,6 @@ function Fields({
type: 'UPDATE_DEPENDENCIES',
payload: { boot: value },
})
- localStorage.setItem('springboot', value)
}}
/>
{get(errors, 'boot') && (
@@ -146,22 +147,22 @@ function Fields({
/>
{
update({meta: {packaging: value}})
- localStorage.setItem('springmeta.packaging', value)
+ localStorage.setItem('packaging', value)
}}
/>
{
update({meta: {java: value}})
- localStorage.setItem('springmeta.java', value)
+ localStorage.setItem('java', value)
}}
/>