Skip to content

Commit

Permalink
Merge pull request #275 from boostcampwm-2024/feature-fe-#15
Browse files Browse the repository at this point in the history
새로 생성된 노드 auto-focus
  • Loading branch information
yewonJin authored Nov 26, 2024
2 parents e9712d8 + 978db34 commit dca978b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
24 changes: 23 additions & 1 deletion apps/frontend/src/features/canvas/model/useCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Edge,
EdgeChange,
Connection,
useReactFlow,
} from "@xyflow/react";
import "@xyflow/react/dist/style.css";
import { SocketIOProvider } from "y-socket.io";
Expand All @@ -19,7 +20,7 @@ import { calculateBestHandles } from "@/features/canvas/model/calculateHandles";
import { createSocketIOProvider } from "@/shared/api/socketProvider";
import { useCollaborativeCursors } from "./useCollaborativeCursors";
import { getSortedNodes } from "./sortNodes";

import { usePageStore } from "@/features/pageSidebar/model/pageStore";
export interface YNode extends Node {
isHolding: boolean;
}
Expand All @@ -41,6 +42,27 @@ export const useCanvas = () => {
const existingPageIds = useRef(new Set<string>());
const holdingNodeRef = useRef<string | null>(null);

const currentPage = usePageStore((state) => state.currentPage);
const { fitView } = useReactFlow();

useEffect(() => {
if (currentPage) {
setTimeout(() => {
fitView({
nodes: [{ id: currentPage.toString() }],
duration: 500,
padding: 0.5,
});
const nodeElement = document.querySelector(
`[data-nodeid="${currentPage}"]`,
) as HTMLInputElement;
if (nodeElement) {
nodeElement.focus();
}
}, 100);
}
}, [currentPage, fitView]);

useEffect(() => {
const yTitleMap = ydoc.getMap("title");
const yEmojiMap = ydoc.getMap("emoji");
Expand Down
4 changes: 2 additions & 2 deletions apps/frontend/src/features/canvas/ui/Node/NoteNode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type NoteNodeData = { title: string; id: number; emoji: string };
export type NoteNodeType = Node<NoteNodeData, "note">;

export function NoteNode({ data }: NodeProps<NoteNodeType>) {
const { setCurrentPage } = usePageStore();
const { currentPage, setCurrentPage } = usePageStore();
const { users } = useUserStore();

const [activeUsers, setActiveUsers] = useState(users);
Expand All @@ -31,7 +31,7 @@ export function NoteNode({ data }: NodeProps<NoteNodeType>) {

return (
<div
className="h-24 w-48 rounded-lg border-[1px] border-[#eaeaea] bg-white p-3 shadow-sm"
className={`h-24 w-48 rounded-lg border-[1px] ${currentPage === data.id ? "border-[#8dbaef]" : "border-[#eaeaea]"} bg-white p-3 shadow-sm`}
onClick={handleNodeClick}
>
<Handle
Expand Down

0 comments on commit dca978b

Please sign in to comment.