Commit a877ed37 authored by Andrey Azov's avatar Andrey Azov
Browse files

Add more nuance to the persistence of the unsubmitted form

parent eb2e31a7
Pipeline #195889 passed with stages
in 4 minutes and 22 seconds
......@@ -76,13 +76,20 @@ const useSavedForm: UseSavedForm = (params) => {
return isEmpty;
};
const saveFormState = () => {
// only save the form if it is not empty
if (isEmptyForm(stateRef.current)) {
const hasSavedForm = async () => {
const savedForm = await indexedDB.get(STORE_NAME, formName);
return Boolean(savedForm);
};
const saveFormState = async () => {
// do not save the form if it is currently empty and has not been saved before
// (if it has been saved, then saving an empty form to overwrite the previously saved one is fine)
const hasPreviouslySavedForm = await hasSavedForm();
if (!hasPreviouslySavedForm && isEmptyForm(stateRef.current)) {
return;
}
const formWithoutHugeFiles = withoutHugeFiles(stateRef.current);
indexedDB.set(STORE_NAME, params.formName, formWithoutHugeFiles);
indexedDB.set(STORE_NAME, formName, formWithoutHugeFiles);
};
const withoutHugeFiles = (state: Form) => {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment