Feat: 프로젝트 타입에 따라 캔버스에 사각형, 다각형 중 하나만 그릴 수 있도록 변경

This commit is contained in:
jhynsoo 2024-09-25 13:48:41 +09:00
parent 0de67e7f94
commit 807bf970ae
2 changed files with 14 additions and 5 deletions

View File

@ -2,16 +2,22 @@ import useCanvasStore from '@/stores/useCanvasStore';
import { LucideIcon, MousePointer2, PenTool, Save, Square } from 'lucide-react'; import { LucideIcon, MousePointer2, PenTool, Save, Square } from 'lucide-react';
import { cn } from '@/lib/utils'; import { cn } from '@/lib/utils';
export default function CanvasControlBar({ saveJson }: { saveJson: () => void }) { export default function CanvasControlBar({
saveJson,
projectType,
}: {
saveJson: () => void;
projectType: 'classification' | 'detection' | 'segmentation';
}) {
const drawState = useCanvasStore((state) => state.drawState); const drawState = useCanvasStore((state) => state.drawState);
const setDrawState = useCanvasStore((state) => state.setDrawState); const setDrawState = useCanvasStore((state) => state.setDrawState);
const buttonBaseClassName = 'rounded-lg p-2 transition-colors '; const buttonBaseClassName = 'rounded-lg p-2 transition-colors ';
const buttonClassName = 'hover:bg-gray-100'; const buttonClassName = 'hover:bg-gray-100';
const activeButtonClassName = 'bg-primary stroke-white'; const activeButtonClassName = 'bg-primary stroke-white';
const controls: { [key: string]: LucideIcon } = { const controls: { [key: string]: LucideIcon } = {
pointer: MousePointer2, pointer: MousePointer2,
rect: Square, ...(projectType === 'segmentation' ? { pen: PenTool } : { rect: Square }),
pen: PenTool,
}; };
return ( return (
@ -31,7 +37,7 @@ export default function CanvasControlBar({ saveJson }: { saveJson: () => void })
</button> </button>
); );
})} })}
<div className="h-5 w-0.5 rounded bg-gray-400" />
<button <button
className={cn(buttonClassName, buttonBaseClassName)} className={cn(buttonClassName, buttonBaseClassName)}
onClick={saveJson} onClick={saveJson}

View File

@ -345,7 +345,10 @@ export default function ImageCanvas() {
<Layer ref={dragLayerRef} /> <Layer ref={dragLayerRef} />
</Stage> </Stage>
<CanvasControlBar saveJson={saveJson} /> <CanvasControlBar
saveJson={saveJson}
projectType={project.type}
/>
</div> </div>
) : ( ) : (
<div></div> <div></div>