Skip to content

Commit

Permalink
feat(Career): implement delete button
Browse files Browse the repository at this point in the history
  • Loading branch information
simonknittel committed Jan 5, 2025
1 parent 6be0893 commit 5d7b80c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/src/career/components/RoleNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import {
NodeResizer,
NodeToolbar,
Position,
useNodeId,
useReactFlow,
type Node,
type NodeProps,
} from "@xyflow/react";
import clsx from "clsx";
import Image from "next/image";
import { useState } from "react";
import { useCallback, useState } from "react";
import { FaTrash } from "react-icons/fa6";
import { IoMdResize } from "react-icons/io";

Expand All @@ -27,8 +29,15 @@ export type RoleNode = Node<
>;

export const RoleNode = (props: NodeProps<RoleNode>) => {
const nodeId = useNodeId();
const { setNodes, setEdges } = useReactFlow();
const [isResizing, setIsResizing] = useState(true);

const onDelete = useCallback(() => {
setNodes((nodes) => nodes.filter((node) => node.id !== nodeId));
setEdges((edges) => edges.filter((edge) => edge.source !== nodeId));
}, [nodeId, setNodes, setEdges]);

return (
<>
<NodeToolbar
Expand All @@ -39,13 +48,16 @@ export const RoleNode = (props: NodeProps<RoleNode>) => {
>
<button
title="Größe ändern"
type="button"
onClick={() => setIsResizing((value) => !value)}
className="bg-neutral-800 rounded p-2 text-sinister-red-500 hover:bg-neutral-700"
>
<IoMdResize />
</button>

<button
onClick={onDelete}
type="button"
title="Löschen"
className="bg-neutral-800 rounded p-2 text-sinister-red-500 hover:bg-neutral-700"
>
Expand Down

0 comments on commit 5d7b80c

Please sign in to comment.