Prevent duplicate user presets

This commit is contained in:
rijkvanzanten
2021-01-28 17:51:07 -05:00
parent 6d00de6b67
commit d90d06e91b
2 changed files with 3 additions and 2 deletions

View File

@@ -30,6 +30,7 @@ export function usePreset(collection: Ref<string>, bookmark: Ref<number | null>
localPreset.value = {
...localPreset.value,
id: updatedValues.id,
user: updatedValues.user,
};
busy.value = false;
return updatedValues;

View File

@@ -3,7 +3,7 @@ import { Preset } from '@/types';
import { useUserStore } from '@/stores/';
import api from '@/api';
import { nanoid } from 'nanoid';
import { merge } from 'lodash';
import { merge, cloneDeep } from 'lodash';
const defaultPreset: Omit<Preset, 'collection'> = {
bookmark: null,
@@ -246,7 +246,7 @@ export const usePresetsStore = createStore({
const { id: userID } = userStore.state.currentUser;
// Clone the preset to make sure the future deletes don't affect the original object
preset = { ...preset };
preset = cloneDeep(preset);
if (preset.id === undefined || preset.id === null) {
return await this.create({