@@ -2,8 +2,10 @@ import React, { useEffect, useState } from "react";
22import "./App.css" ;
33import KanbanColumn from "./components/KanbanColumn" ;
44import { Column , DraggableTask , DraggedTaskInfo , Task } from "./types" ;
5+ import { fetchKanbanTasks } from "./api" ;
56
6- export default function App ( ) {
7+ export default function App ( )
8+ {
79 const [ kanbanColumns , setKanbanColumns ] = useState < Record < Column , DraggableTask [ ] > > ( {
810 Backlog : [ ] ,
911 "In Progress" : [ ] ,
@@ -12,45 +14,69 @@ export default function App() {
1214 } ) ;
1315
1416 // Fetch Tasks
15- useEffect ( ( ) => {
17+ useEffect ( ( ) =>
18+ {
1619 // TODO: Pull state from json-server
20+ const fetchTasks = async ( ) =>
21+ {
22+ const data = await fetchKanbanTasks ( ) ;
23+ console . log ( "tasks" , data ) ;
24+
25+ setKanbanColumns ( data ) ;
26+ } ;
27+
28+ fetchTasks ( ) ;
1729 // Hint: You may want to use the fetchTasks function from api/index.tsx
1830 } , [ ] ) ;
1931
2032 // Hint: You will need these states for dragging and dropping tasks
2133 const [ draggedTaskInfo , setDraggedTaskInfo ] = useState < DraggedTaskInfo | null > ( null ) ;
2234 const [ hoveredColumn , setHoveredColumn ] = useState < Column | null > ( null ) ;
2335
24- const handleTaskDragStart = ( task : Task , column : Column ) => {
36+ const handleTaskDragStart = ( task : Task , column : Column ) =>
37+ {
2538 // TODO: Implement functionality for when the drag starts
2639 } ;
2740
28- const handleTaskDragOver = ( e : React . DragEvent , column : Column ) => {
41+ const handleTaskDragOver = ( e : React . DragEvent , column : Column ) =>
42+ {
2943 e . preventDefault ( ) ;
44+ console . log ( "handleTaskDragOver" , column , e . target ) ;
45+
3046 // TODO: Implement functionality for when an item is being dragged over a column
3147 // Hint: Remember to check if the item is being dragged over a new column
3248 } ;
3349
34- const handleTaskDrop = ( column : Column ) => {
50+ const handleTaskDrop = ( column : Column ) =>
51+ {
52+ console . log ( "handleTaskDrop" , column ) ;
53+
3554 // TODO: Implement functionality for when the item is dropped
3655 // Hint: Make sure to handle the cases when the item is dropped in the same column or in a new column
3756 } ;
3857
39- const getTasksForColumn = ( column : Column ) : DraggableTask [ ] => {
58+ const getTasksForColumn = ( column : Column ) : DraggableTask [ ] =>
59+ {
60+ // console.log("getTasksForColumn", column);
61+
4062 // TODO: Handle the bug where card dragged over itself shows duplicate
4163 // Hint: Consider how you can use the dragInfo and overColumn states to prevent this
42- return [ { id : "1" , name : "Task 1" , isDragging : false } ] ;
64+ return kanbanColumns [ column ] ;
65+ // return [{ id: "1", name: "Task 1", isDragging: false }];
4366 } ;
4467
45- const handleTaskDragEnd = ( ) => {
68+ const handleTaskDragEnd = ( ) =>
69+ {
70+ console . log ( "handleTaskDragEnd" ) ;
71+
4672 // TODO: Implement functionality for when the drag ends
4773 // Hint: Remember to handle the case when the item is released back to its current column
4874 } ;
4975
5076 return (
5177 < main className = "overflow-x-auto" >
52- < h1 className = "text-left text-4xl font-bold p-10 pb-0 " > Codebase Mentor Kanban Board</ h1 >
53- < div className = "flex justify-between p-10 gap-x-4 min-w-max" >
78+ < h1 className = "p-10 pb-0 text-4xl font-bold text-left " > Codebase Mentor Kanban Board</ h1 >
79+ < div className = "flex gap-x-4 justify-between p-10 min-w-max" >
5480 < KanbanColumn
5581 title = "Backlog"
5682 tasks = { getTasksForColumn ( "Backlog" ) }
0 commit comments