"use client"; import { useParams } from "next/navigation"; import { HiOutlinePlusSmall } from "react-icons/hi2"; import { DragDropContext, Droppable, type DropResult, Draggable, } from "react-beautiful-dnd"; import { api } from "~/trpc/react"; interface List { publicId: string; name: string; cards?: Card[]; } interface Card { publicId: string; title: string; } export default function BoardPage() { const params = useParams(); const utils = api.useUtils(); const boardId = params?.id?.length && params.id[0]; if (!boardId) return <>; const { data } = api.board.byId.useQuery({ id: boardId }); const refetchBoard = () => utils.board.byId.refetch({ id: boardId }); const updateCard = api.card.update.useMutation({ onSuccess: async () => { try { await refetchBoard(); } catch (e) { console.log(e); } }, }); const onDragEnd = ({ source, destination, draggableId, }: DropResult): void => { if (!destination) { return; } updateCard.mutate({ cardId: draggableId, currentListId: source.droppableId, newListId: destination.droppableId, currentIndex: source.index, newIndex: destination.index, }); }; return (

{data?.name}

{data?.lists.map((list: List) => ( {(provided) => (

{list.name}

{list.cards?.map((card, index) => ( {(provided) => (

{card.title}

)}
))}
)}
))}
); }