@@ -2,8 +2,10 @@ import React, { useEffect, useState } from "react";
2
2
import "./App.css" ;
3
3
import KanbanColumn from "./components/KanbanColumn" ;
4
4
import { Column , DraggableTask , DraggedTaskInfo , Task } from "./types" ;
5
+ import { fetchKanbanTasks } from "./api" ;
5
6
6
- export default function App ( ) {
7
+ export default function App ( )
8
+ {
7
9
const [ kanbanColumns , setKanbanColumns ] = useState < Record < Column , DraggableTask [ ] > > ( {
8
10
Backlog : [ ] ,
9
11
"In Progress" : [ ] ,
@@ -12,45 +14,69 @@ export default function App() {
12
14
} ) ;
13
15
14
16
// Fetch Tasks
15
- useEffect ( ( ) => {
17
+ useEffect ( ( ) =>
18
+ {
16
19
// 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 ( ) ;
17
29
// Hint: You may want to use the fetchTasks function from api/index.tsx
18
30
} , [ ] ) ;
19
31
20
32
// Hint: You will need these states for dragging and dropping tasks
21
33
const [ draggedTaskInfo , setDraggedTaskInfo ] = useState < DraggedTaskInfo | null > ( null ) ;
22
34
const [ hoveredColumn , setHoveredColumn ] = useState < Column | null > ( null ) ;
23
35
24
- const handleTaskDragStart = ( task : Task , column : Column ) => {
36
+ const handleTaskDragStart = ( task : Task , column : Column ) =>
37
+ {
25
38
// TODO: Implement functionality for when the drag starts
26
39
} ;
27
40
28
- const handleTaskDragOver = ( e : React . DragEvent , column : Column ) => {
41
+ const handleTaskDragOver = ( e : React . DragEvent , column : Column ) =>
42
+ {
29
43
e . preventDefault ( ) ;
44
+ console . log ( "handleTaskDragOver" , column , e . target ) ;
45
+
30
46
// TODO: Implement functionality for when an item is being dragged over a column
31
47
// Hint: Remember to check if the item is being dragged over a new column
32
48
} ;
33
49
34
- const handleTaskDrop = ( column : Column ) => {
50
+ const handleTaskDrop = ( column : Column ) =>
51
+ {
52
+ console . log ( "handleTaskDrop" , column ) ;
53
+
35
54
// TODO: Implement functionality for when the item is dropped
36
55
// Hint: Make sure to handle the cases when the item is dropped in the same column or in a new column
37
56
} ;
38
57
39
- const getTasksForColumn = ( column : Column ) : DraggableTask [ ] => {
58
+ const getTasksForColumn = ( column : Column ) : DraggableTask [ ] =>
59
+ {
60
+ // console.log("getTasksForColumn", column);
61
+
40
62
// TODO: Handle the bug where card dragged over itself shows duplicate
41
63
// 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 }];
43
66
} ;
44
67
45
- const handleTaskDragEnd = ( ) => {
68
+ const handleTaskDragEnd = ( ) =>
69
+ {
70
+ console . log ( "handleTaskDragEnd" ) ;
71
+
46
72
// TODO: Implement functionality for when the drag ends
47
73
// Hint: Remember to handle the case when the item is released back to its current column
48
74
} ;
49
75
50
76
return (
51
77
< 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" >
54
80
< KanbanColumn
55
81
title = "Backlog"
56
82
tasks = { getTasksForColumn ( "Backlog" ) }
0 commit comments