Skip to content

Commit e7402bc

Browse files
committed
1 parent 4d8c57b commit e7402bc

File tree

4 files changed

+74
-43
lines changed

4 files changed

+74
-43
lines changed

package-lock.json

Lines changed: 30 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.tsx

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import React, { useEffect, useState } from "react";
22
import "./App.css";
33
import KanbanColumn from "./components/KanbanColumn";
44
import { 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")}

src/api/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
const apiUrl = "http://localhost:3001";
22

3-
export const fetchKanbanTasks = async () => {
3+
export const fetchKanbanTasks = async () =>
4+
{
45
// TODO: Implement functionality to fetch tasks from the server
6+
const res = await fetch(`${apiUrl}/tasks`);
7+
const data = await res.json();
8+
return data;
59
};
610

7-
export const updateKanbanTasks = async (tasks: any) => {
11+
export const updateKanbanTasks = async (tasks: any) =>
12+
{
813
// TODO: Save the new order of the items when tasks are modified to the server
914
// Hint: You may want to use the fetch API with a "PUT" method
1015
};

src/components/KanbanColumn.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default function KanbanColumn({
2424
onDragOver={(e) => onTaskDragOver(e, title)}
2525
onDrop={() => onTaskDrop(title)}
2626
>
27-
<h2 className="font-bold mb-2">{title}</h2>
27+
<h2 className="mb-2 font-bold">{title}</h2>
2828
<ul>
2929
{tasks.map((task) => (
3030
<li

0 commit comments

Comments
 (0)