diff options
| author | Dhravya Shah <[email protected]> | 2025-02-14 15:53:44 -0800 |
|---|---|---|
| committer | Dhravya Shah <[email protected]> | 2025-02-14 15:53:44 -0800 |
| commit | af1093d4aab6d5654364e7cd9df76fd766bbee03 (patch) | |
| tree | f128bdb8cac4b44ed41289dc9a158c33fe86c5ec /apps/web/app | |
| parent | twitter import fix (diff) | |
| download | supermemory-af1093d4aab6d5654364e7cd9df76fd766bbee03.tar.xz supermemory-af1093d4aab6d5654364e7cd9df76fd766bbee03.zip | |
intuitive memory movement, avoid duplicates in home
Diffstat (limited to 'apps/web/app')
| -rw-r--r-- | apps/web/app/components/memories/SharedCard.tsx | 12 | ||||
| -rw-r--r-- | apps/web/app/lib/hooks/use-spaces.tsx | 22 | ||||
| -rw-r--r-- | apps/web/app/routes/content.$contentid.tsx | 10 |
3 files changed, 37 insertions, 7 deletions
diff --git a/apps/web/app/components/memories/SharedCard.tsx b/apps/web/app/components/memories/SharedCard.tsx index d80b848a..8e4c69b1 100644 --- a/apps/web/app/components/memories/SharedCard.tsx +++ b/apps/web/app/components/memories/SharedCard.tsx @@ -41,6 +41,7 @@ import { ExtraSpaceMetaData, fetchSpaces } from "~/lib/hooks/use-spaces"; import { useTextOverflow } from "~/lib/hooks/use-text-overflow"; import { Memory, WebsiteMetadata } from "~/lib/types/memory"; import { cn } from "~/lib/utils"; +import { useNavigate } from "@remix-run/react"; const { useTweet } = ReactTweet; @@ -616,6 +617,7 @@ export function FetchAndRenderContent({ content }: { content: string }) { function SharedCard({ data }: { data: Memory }) { const queryClient = useQueryClient(); + const navigate = useNavigate(); // Delete mutation const deleteMutation = useMutation({ @@ -657,7 +659,7 @@ function SharedCard({ data }: { data: Memory }) { // Move to space mutation const moveToSpaceMutation = useMutation({ mutationFn: async ({ spaceId, documentId }: { spaceId: string; documentId: string }) => { - const response = await fetch("/backend/v1/spaces/addContent", { + const response = await fetch("/backend/v1/spaces/moveContent", { method: "POST", headers: { "Content-Type": "application/json", @@ -668,15 +670,19 @@ function SharedCard({ data }: { data: Memory }) { if (!response.ok) { throw new Error("Failed to move memory"); } - return response.json(); + return response.json() as Promise<{ spaceId: string }>; }, onError: (err) => { toast.error("Failed to move memory to space"); }, - onSuccess: () => { + onSuccess: ({ spaceId }: { spaceId: string }) => { toast.success("Memory moved successfully"); queryClient.invalidateQueries({ queryKey: ["memories"] }); queryClient.invalidateQueries({ queryKey: ["spaces"] }); + if (spaceId === "<HOME>") { + return navigate("/"); + } + return navigate(`/space/${spaceId}`); }, }); diff --git a/apps/web/app/lib/hooks/use-spaces.tsx b/apps/web/app/lib/hooks/use-spaces.tsx index 14ffb56c..1654fd47 100644 --- a/apps/web/app/lib/hooks/use-spaces.tsx +++ b/apps/web/app/lib/hooks/use-spaces.tsx @@ -44,7 +44,27 @@ export async function fetchSpaces(): Promise<SpaceResponse> { throw new Error("Failed to fetch spaces"); } - return response.json(); + const resp = (await response.json()) as SpaceResponse; + + resp.spaces.push({ + id: 0, + uuid: "<HOME>", + name: "Home", + createdAt: new Date(), + updatedAt: new Date(), + ownerId: 0, + isPublic: false, + permissions: { + canRead: false, + canEdit: false, + isOwner: false, + isPublic: false, + }, + owner: null, + favorited: false, + }); + + return resp; } async function createSpace(data: { diff --git a/apps/web/app/routes/content.$contentid.tsx b/apps/web/app/routes/content.$contentid.tsx index ca81d039..da7e23d7 100644 --- a/apps/web/app/routes/content.$contentid.tsx +++ b/apps/web/app/routes/content.$contentid.tsx @@ -94,7 +94,7 @@ export default function Content() { // Move to space mutation const moveToSpaceMutation = useMutation({ mutationFn: async ({ spaceId, documentId }: { spaceId: string; documentId: string }) => { - const response = await fetch("/backend/v1/spaces/addContent", { + const response = await fetch("/backend/v1/spaces/moveContent", { method: "POST", headers: { "Content-Type": "application/json", @@ -105,12 +105,16 @@ export default function Content() { if (!response.ok) { throw new Error("Failed to move memory"); } - return response.json(); + return response.json() as Promise<{ spaceId: string }>; }, - onSuccess: () => { + onSuccess: ({ spaceId }: {spaceId: string}) => { toast.success("Memory moved successfully"); queryClient.invalidateQueries({ queryKey: ["memories"] }); queryClient.invalidateQueries({ queryKey: ["spaces"] }); + if (spaceId === "<HOME>") { + return navigate("/"); + } + return navigate(`/space/${spaceId}`); }, onError: () => { toast.error("Failed to move memory to space"); |