mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-05-17 03:56:18 +00:00
fix: space deletion not switching to Nova Spaces and new space not appearing in dropdown (#747)
### fix: space selector state bugs on create and delete Two related bugs in the space selector caused by query cache key mismatches in `use-project-mutations.ts`: 1. New spaces not appearing in dropdown until refresh — wrong query cache was being invalidated after creation. 2. App stuck on deleted space instead of switching to Nova Spaces — delete handler was reading from an empty cache, so the selection never updated.
This commit is contained in:
parent
cda3bca0d0
commit
cc2dcaa306
1 changed files with 10 additions and 8 deletions
|
|
@ -4,7 +4,7 @@ import { $fetch } from "@lib/api"
|
|||
import { useMutation, useQueryClient } from "@tanstack/react-query"
|
||||
import { toast } from "sonner"
|
||||
import { useProject } from "@/stores"
|
||||
import type { Project } from "@repo/lib/types"
|
||||
import type { ContainerTagListType } from "@repo/lib/types"
|
||||
|
||||
export function useProjectMutations() {
|
||||
const queryClient = useQueryClient()
|
||||
|
|
@ -29,6 +29,7 @@ export function useProjectMutations() {
|
|||
onSuccess: (data) => {
|
||||
toast.success("Project created successfully!")
|
||||
queryClient.invalidateQueries({ queryKey: ["projects"] })
|
||||
queryClient.invalidateQueries({ queryKey: ["container-tags"] })
|
||||
|
||||
if (data?.containerTag) {
|
||||
setSelectedProjects([data.containerTag])
|
||||
|
|
@ -63,14 +64,12 @@ export function useProjectMutations() {
|
|||
},
|
||||
onSuccess: (_, variables) => {
|
||||
toast.success("Project deleted successfully")
|
||||
queryClient.invalidateQueries({ queryKey: ["projects"] })
|
||||
queryClient.invalidateQueries({ queryKey: ["container-tags"] })
|
||||
|
||||
const allProjects =
|
||||
queryClient.getQueryData<Project[]>(["projects"]) || []
|
||||
const deletedProject = allProjects.find(
|
||||
(p) => p.id === variables.projectId,
|
||||
)
|
||||
const allTags =
|
||||
queryClient.getQueryData<ContainerTagListType[]>(["container-tags"]) ||
|
||||
[]
|
||||
const deletedProject = allTags.find((p) => p.id === variables.projectId)
|
||||
|
||||
if (
|
||||
deletedProject?.containerTag &&
|
||||
selectedProjects.includes(deletedProject.containerTag)
|
||||
|
|
@ -79,6 +78,9 @@ export function useProjectMutations() {
|
|||
selectedProjects.filter((tag) => tag !== deletedProject.containerTag),
|
||||
)
|
||||
}
|
||||
|
||||
queryClient.invalidateQueries({ queryKey: ["projects"] })
|
||||
queryClient.invalidateQueries({ queryKey: ["container-tags"] })
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.error("Failed to delete project", {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue