Skip to content

Commit b47bcd2

Browse files
committed
Update README.md
1 parent c857791 commit b47bcd2

File tree

6 files changed

+31
-62
lines changed

6 files changed

+31
-62
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![banner](https://og-playground.vercel.app/?share=zVRpa9wwEP0rQlA2AXt97JG1SQolLSWFQmka-sUQZFsrK5ElIct7dNn_3pF3HW8O6LcS8DXzxqOZN0_a4UKVFKf4suSrTCLU2K2gV7ud-0ao5I0WZJui0VLQzcg7eCvKWWXBGYXhh9655qWtXviI4EzeWFo3ABRUWmp66KFtLF9urxU4pcv1HHbLfeaGFpYr6VAl2lr2aE6KR2ZUK8ubmjAKuCElJ8Jn7g2JzohFh4QoV9aq2kOG5WezmYfmcC-i84MjuvBQPPXQJDk6Qg-56_z8qRAo8Jb_gTWm4dElqIXEt5oUXLIU-fFJ6O8jNRfhIXq_z-THTLrPS14z1JjiKsOVtbpJg6DVQpFyvOaPvKbQwFgZFjhLOysoVF0r2QS2aus8SIIkCe6kWi55Ab3efyMrclsYru29UEzdx-NmxYI4nC70xv9X3FhLlmEYkIVy7qTlVtDSj0I_ihfhZj5fAJgrU1IDeAhGr4vjmGPoD2lSlh0FGY5Dvcnwfh9As9DqUUwv5YSGX0YzvQFK9ZOoBgWR1qrBa-nGfnI6eqWRt3QguKTEDDpIwpKyw2iTiZt14h79-C8isMI5PGYnIz_Ney24hrSuiAEe-WuaP3LrD3F-AYGjV5EgW2Wc1xDZaGKgpB50ykCoowuhn7TRMGm-ouhHpaxCX4kQ1Gw7MgNg8_3SGs0cf5OOxGFbgRl1xE6T_03s8404O27E53s5w5NOsG-MIt-iazgSc9LQ75BVmdMZ9G_sYaXd0dTgdIc7hnG6gKXw4WzE6dQZkKZlOF0S0VAP01o98F9b7Y5bu-4syOOK-lLntMSpNS3de9iSHCIqKoRaKyNKvP8L)](https://codebasementor.com?utm_source=github&utm_medium=javascript-photo-gallery&utm_campaign=github_readmes)
1+
[![banner](https://user-images.githubusercontent.com/2349518/235016177-e315b43d-5007-4025-84c4-03b0d849c5a4.svg)](https://codebasementor.com?utm_source=github&utm_medium=react-kanban-board&utm_campaign=github_readmes)
22

33
# React Kanban Board by [CodebaseMentor](https://www.codebasementor.com?utm_source=github&utm_medium=react-kanban-board&utm_campaign=github_readmes)
44

@@ -9,9 +9,9 @@ This is an advanced project in React that allows you to create a dynamic and int
99
1. The tasks aren't fetched from the server.
1010
2. The application doesn't handle the onDragStart, onDragOver, onDrop, and onDragEnd events.
1111
1. Implement handleTaskDragStart, handleTaskDragOver, handleTaskDrop, and handleTaskDragEnd to handle the drag-and-drop events.
12-
2. Make sure the application doesn't incorrectly show duplicate tasks when dragged over themselves. ` && draggedTaskInfo.column !== column`
13-
3. Make sure the application doesn't leave a lingering task when dragged over a column but dropped elsewhere. `handleTaskDragEnd`
14-
4. Make sure the application doesn't delete a task that is dragged over it's current column. `if (column !== draggedTaskInfo.column) {`
12+
2. Make sure the application doesn't incorrectly show duplicate tasks when dragged over themselves.
13+
3. Make sure the application doesn't leave a lingering task when dragged over a column but dropped elsewhere.
14+
4. Make sure the application doesn't delete a task that is dragged over it's current column.
1515
3. Task changes aren't being sent to the server.
1616

1717
## Learning Objectives
@@ -26,7 +26,9 @@ You will learn and gain experience with:
2626
## How to start working
2727

2828
1. Fork this repo and clone it locally.
29-
1. Open index.html in your browser to see the current state of the project.
29+
1. Install the dependencies by running npm i
30+
1. Run the app locally by running `npm run dev:client` to start the frontend, and `npm run dev:server` to start the backend.
31+
1. Open `localhost:3000` in your browser to see the current state of the project.
3032
1. Fix all the issues (hints are provided as TODO comments in the code)
3133
1. Once all your solutions are complete, create a single Pull Request to this repository
3234
1. Check if your solutions passes our automated tests. You need to create an account on [CodebaseMentor](https://www.codebasementor.com?utm_source=github&utm_medium=react-kanban-board&utm_campaign=github_readmes) to do this.
@@ -39,4 +41,4 @@ The best way to ask for help is to ask our Discord community.
3941

4042
## Want more challenges?
4143

42-
Sign up to [view more challenges](https://app.codebasementor.com/?utm_source=github&utm_medium=javascript-photo-gallery&utm_campaign=github_readmes) and [join our Discord](https://discord.gg/6VsSMZaM7q) to get notified when new challenges are released.
44+
Sign up to [view more challenges](https://app.codebasementor.com/?utm_source=github&utm_medium=react-kanban-board&utm_campaign=github_readmes) and [join our Discord](https://discord.gg/6VsSMZaM7q) to get notified when new challenges are released.

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8" />
55
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>React + TypeScript Project</title>
7+
<title>React Kanban by Codebase Mentor</title>
88
</head>
99
<body>
1010
<div id="root"></div>

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "react-typescript",
2+
"name": "react-kanban-board",
33
"version": "1.0.0",
44
"type": "module",
55
"description": "React TypeScript, using Vite bundler",
@@ -10,7 +10,7 @@
1010
"preview": "vite preview"
1111
},
1212
"keywords": [],
13-
"author": "",
13+
"author": "CodebaseMentor.com",
1414
"license": "ISC",
1515
"devDependencies": {
1616
"@types/react": "^18.0.15",

src/App.tsx

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useEffect, useState } from "react";
22
import "./App.css";
3-
import { fetchTasks, updateTasks } from "./api";
43
import KanbanColumn from "./components/KanbanColumn";
54
import { Column, DraggableTask, DraggedTaskInfo, Task } from "./types";
65

@@ -14,60 +13,38 @@ export default function App() {
1413

1514
// Fetch Tasks
1615
useEffect(() => {
17-
(async () => {
18-
const tasks = await fetchTasks();
19-
setKanbanColumns(tasks);
20-
})();
16+
// TODO: Pull state from json-server
17+
// Hint: You may want to use the fetchTasks function from api/index.tsx
2118
}, []);
2219

20+
// Hint: You will need these states for dragging and dropping tasks
2321
const [draggedTaskInfo, setDraggedTaskInfo] = useState<DraggedTaskInfo | null>(null);
2422
const [hoveredColumn, setHoveredColumn] = useState<Column | null>(null);
2523

2624
const handleTaskDragStart = (task: Task, column: Column) => {
27-
setDraggedTaskInfo({ task, column });
25+
// TODO: Implement functionality for when the drag starts
2826
};
2927

3028
const handleTaskDragOver = (e: React.DragEvent, column: Column) => {
3129
e.preventDefault();
32-
if (column !== hoveredColumn) {
33-
setHoveredColumn(column);
34-
}
30+
// TODO: Implement functionality for when an item is being dragged over a column
31+
// Hint: Remember to check if the item is being dragged over a new column
3532
};
3633

3734
const handleTaskDrop = (column: Column) => {
38-
if (draggedTaskInfo) {
39-
// If the task is dropped in a different column, remove it from the old one and add it to the new one.
40-
if (column !== draggedTaskInfo.column) {
41-
const taskIndex = kanbanColumns[draggedTaskInfo.column].findIndex(
42-
(task) => task.id === draggedTaskInfo.task.id
43-
);
44-
if (taskIndex > -1) {
45-
const newColumnTasks = [...kanbanColumns[column], draggedTaskInfo.task];
46-
const oldColumnTasks = [...kanbanColumns[draggedTaskInfo.column]];
47-
oldColumnTasks.splice(taskIndex, 1);
48-
const newState = { ...kanbanColumns, [column]: newColumnTasks, [draggedTaskInfo.column]: oldColumnTasks };
49-
setKanbanColumns(newState);
50-
// Update the tasks in the db
51-
updateTasks(newState).catch((error) => console.error(error));
52-
}
53-
}
54-
}
55-
56-
setDraggedTaskInfo(null); // Reset dragInfo state
57-
setHoveredColumn(null); // Reset overColumn state
35+
// TODO: Implement functionality for when the item is dropped
36+
// Hint: Make sure to handle the cases when the item is dropped in the same column or in a new column
5837
};
5938

6039
const getTasksForColumn = (column: Column): DraggableTask[] => {
61-
let tasks = kanbanColumns[column];
62-
if (draggedTaskInfo && hoveredColumn === column) {
63-
tasks = [...tasks, { ...draggedTaskInfo.task, isDragging: true }];
64-
}
65-
return tasks;
40+
// TODO: Handle the bug where card dragged over itself shows duplicate
41+
// Hint: Consider how you can use the dragInfo and overColumn states to prevent this
42+
return [{ id: "1", name: "Task 1", isDragging: false }];
6643
};
6744

6845
const handleTaskDragEnd = () => {
69-
setDraggedTaskInfo(null); // Reset dragInfo state
70-
setHoveredColumn(null); // Reset overColumn state
46+
// TODO: Implement functionality for when the drag ends
47+
// Hint: Remember to handle the case when the item is released back to its current column
7148
};
7249

7350
return (

src/api/index.tsx

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

3-
export const fetchTasks = async () => {
4-
const response = await fetch(`${apiUrl}/tasks`);
5-
const data = await response.json();
6-
return data;
3+
export const fetchKanbanTasks = async () => {
4+
// TODO: Implement functionality to fetch tasks from the server
75
};
86

9-
export const updateTasks = async (tasks: any) => {
10-
const response = await fetch(`${apiUrl}/tasks`, {
11-
method: "PUT",
12-
headers: {
13-
"Content-Type": "application/json",
14-
},
15-
body: JSON.stringify(tasks),
16-
});
17-
18-
const data = await response.json();
19-
return data;
7+
export const updateKanbanTasks = async (tasks: any) => {
8+
// TODO: Save the new order of the items when tasks are modified to the server
9+
// Hint: You may want to use the fetch API with a "PUT" method
2010
};

0 commit comments

Comments
 (0)