mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-05-19 07:42:43 +00:00
### Add user display name functionality and enhance space management with emoji support and deletion capabilities. ### What changed? - Added support for user display names, which are now stored and displayed throughout the app - Implemented emoji support for spaces (projects), allowing users to customize their space icons - Created a new `AddSpaceModal` component with emoji picker for creating spaces - Added space deletion functionality with options to move content to another space or delete everything - Enhanced the space selector UI to show emojis and delete options
92 lines
2.4 KiB
TypeScript
92 lines
2.4 KiB
TypeScript
"use client"
|
|
|
|
import { $fetch } from "@lib/api"
|
|
import { useMutation, useQueryClient } from "@tanstack/react-query"
|
|
import { toast } from "sonner"
|
|
import { useProject } from "@/stores"
|
|
|
|
export function useProjectMutations() {
|
|
const queryClient = useQueryClient()
|
|
const { selectedProject, setSelectedProject } = useProject()
|
|
|
|
const createProjectMutation = useMutation({
|
|
mutationFn: async (input: string | { name: string; emoji?: string }) => {
|
|
const { name, emoji } =
|
|
typeof input === "string" ? { name: input, emoji: undefined } : input
|
|
|
|
const response = await $fetch("@post/projects", {
|
|
body: { name, emoji },
|
|
})
|
|
|
|
if (response.error) {
|
|
throw new Error(response.error?.message || "Failed to create project")
|
|
}
|
|
|
|
return response.data
|
|
},
|
|
onSuccess: (data) => {
|
|
toast.success("Project created successfully!")
|
|
queryClient.invalidateQueries({ queryKey: ["projects"] })
|
|
|
|
// Automatically switch to the newly created project
|
|
if (data?.containerTag) {
|
|
setSelectedProject(data.containerTag)
|
|
}
|
|
},
|
|
onError: (error) => {
|
|
toast.error("Failed to create project", {
|
|
description: error instanceof Error ? error.message : "Unknown error",
|
|
})
|
|
},
|
|
})
|
|
|
|
const deleteProjectMutation = useMutation({
|
|
mutationFn: async ({
|
|
projectId,
|
|
action,
|
|
targetProjectId,
|
|
}: {
|
|
projectId: string
|
|
action: "move" | "delete"
|
|
targetProjectId?: string
|
|
}) => {
|
|
const response = await $fetch(`@delete/projects/${projectId}`, {
|
|
body: { action, targetProjectId },
|
|
})
|
|
|
|
if (response.error) {
|
|
throw new Error(response.error?.message || "Failed to delete project")
|
|
}
|
|
|
|
return response.data
|
|
},
|
|
onSuccess: (_, variables) => {
|
|
toast.success("Project deleted successfully")
|
|
queryClient.invalidateQueries({ queryKey: ["projects"] })
|
|
|
|
// If we deleted the selected project, switch to default
|
|
const deletedProject = queryClient
|
|
.getQueryData<any[]>(["projects"])
|
|
?.find((p) => p.id === variables.projectId)
|
|
if (deletedProject?.containerTag === selectedProject) {
|
|
setSelectedProject("sm_project_default")
|
|
}
|
|
},
|
|
onError: (error) => {
|
|
toast.error("Failed to delete project", {
|
|
description: error instanceof Error ? error.message : "Unknown error",
|
|
})
|
|
},
|
|
})
|
|
|
|
const switchProject = (containerTag: string) => {
|
|
setSelectedProject(containerTag)
|
|
toast.success("Project switched successfully")
|
|
}
|
|
|
|
return {
|
|
createProjectMutation,
|
|
deleteProjectMutation,
|
|
switchProject,
|
|
}
|
|
}
|