Skip to content

Commit

Permalink
feat: 노드 생성 시 노트 생성 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
heegenie committed Nov 27, 2024
1 parent 2e806fd commit 15c9a88
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
19 changes: 19 additions & 0 deletions packages/frontend/src/api/note.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { API_V1_URL } from "./constants";
import http from "./http";

type CreateNoteRequestBody = {
userId: string;
noteName: string;
};

type CreateNoteResponseBody = {
urlPath: [string];
};

export async function createNote(body: CreateNoteRequestBody) {
const response = await http.post<CreateNoteResponseBody>(
`${API_V1_URL}/note`,
{ body: JSON.stringify(body) },
);
return response.data;
}
28 changes: 17 additions & 11 deletions packages/frontend/src/components/space/SpaceView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Html } from "react-konva-utils";
import Konva from "konva";
import type { Node } from "shared/types";

import { createNote } from "@/api/note";
import { createSpace } from "@/api/space";
import Edge from "@/components/Edge";
import { HeadNode, NoteNode, SubspaceNode } from "@/components/Node";
Expand Down Expand Up @@ -37,18 +38,23 @@ export default function SpaceView({ spaceId, autofitTo }: SpaceViewProps) {
const { drag, dropPosition, handlePaletteSelect } = useDragNode(nodesArray, {
createNode: (type, parentNode, position, name = "New Note") => {
if (type === "note") {
let src = "";
// FIXME: note 생성 후 id 입력
defineNode(
{
type,
x: position.x,
y: position.y,
name,
src,
},
parentNode.id,
);
createNote({
userId: "honeyflow",
noteName: name,
}).then((res) => {
const [urlPath] = res.urlPath;
defineNode(
{
type,
x: position.x,
y: position.y,
name,
src: urlPath,
},
parentNode.id,
);
});

return;
}
Expand Down

0 comments on commit 15c9a88

Please sign in to comment.