Skip to content

Commit

Permalink
autosave doesn't remove error messages anymore, while still only trig…
Browse files Browse the repository at this point in the history
…gering once
  • Loading branch information
qhanson55 committed Jan 15, 2025
1 parent 12fe61e commit 43eece7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
1 change: 0 additions & 1 deletion frontend/src/components/file/AdvancedFileUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const { getConfig } = storeToRefs(useConfigStore());
const submissionStore = useSubmissionStore();
// State
// const curActivityId: Ref<string | undefined> = ref(undefined);
const fileInput: Ref<any> = ref(null);
const uploading: Ref<Boolean> = ref(false);
Expand Down
31 changes: 23 additions & 8 deletions frontend/src/components/form/FormAutosave.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { useFormValues, useIsFormDirty } from 'vee-validate';
import { useField, useFormValues, useIsFormDirty } from 'vee-validate';
import { onBeforeUnmount, ref, watch } from 'vue';
import type { Ref } from 'vue';
Expand All @@ -17,6 +17,7 @@ const { callback, delay = DEFAULT_DELAY } = defineProps<{
const isDirty = useIsFormDirty();
const timeoutId: Ref<ReturnType<typeof setTimeout> | null> = ref(null);
const values = useFormValues();
const { value: activityId } = useField('activityId');
// Actions
defineExpose({ stopAutoSave });
Expand All @@ -32,18 +33,32 @@ onBeforeUnmount(() => {
stopAutoSave();
});
watch(values.value, () => {
if (timeoutId.value) {
clearTimeout(timeoutId.value);
}
watch(
[() => values.value, activityId],
([newVals, newActId], [oldVals, oldActId]) => {
if (!isDirty.value) {
return;
}
// check to see if only activity id was changed, then skip autosave
if (
newActId !== oldActId &&
JSON.stringify({ ...newVals, activityId: undefined }) === JSON.stringify({ ...oldVals, activityId: undefined })
) {
return;
}
if (timeoutId.value) {
clearTimeout(timeoutId.value);
}
if (isDirty.value) {
timeoutId.value = setTimeout(async () => {
await callback();
timeoutId.value = null;
}, delay);
}
});
},
{ deep: true }
);
</script>

<template><div /></template>
Original file line number Diff line number Diff line change
Expand Up @@ -429,12 +429,7 @@ function syncFormAndRoute(actId: string, drftId: string) {
}
if (actId) {
formRef.value?.resetForm({
values: {
...formRef.value?.values,
activityId: actId
}
});
formRef.value?.setFieldValue('activityId', actId);
}
}
Expand Down

0 comments on commit 43eece7

Please sign in to comment.