Fix tag links by refreshing tags after creation (#843)
This commit is contained in:
parent
1e69ae59cf
commit
c60f140944
1 changed files with 21 additions and 9 deletions
|
|
@ -314,16 +314,28 @@ export const useStore = create<StoreState>((set: any) => ({
|
|||
);
|
||||
const tagsToAdd = newTagNames
|
||||
.filter((name) => !existingTagNames.includes(name))
|
||||
.map((name) => ({ name, id: Date.now() + Math.random() })); // Temporary ID
|
||||
// Temporary ID/optimistic tag. Backend creates the real tag on save.
|
||||
.map((name) => ({ name, id: Date.now() + Math.random() }));
|
||||
|
||||
if (tagsToAdd.length === 0) return;
|
||||
|
||||
if (tagsToAdd.length > 0) {
|
||||
set((state) => ({
|
||||
tagsStore: {
|
||||
...state.tagsStore,
|
||||
tags: [...state.tagsStore.tags, ...tagsToAdd],
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
// Important: ensure store picks up server-generated UIDs ASAP.
|
||||
// Without this, the Tags page can render links without UIDs until a refresh.
|
||||
setTimeout(() => {
|
||||
useStore
|
||||
.getState()
|
||||
.tagsStore.refreshTags()
|
||||
.catch((e) =>
|
||||
console.error('addNewTags: Failed to refresh tags:', e)
|
||||
);
|
||||
}, 0);
|
||||
},
|
||||
},
|
||||
tasksStore: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue