Skip to content

Commit

Permalink
[docs]: Update KanbanApp
Browse files Browse the repository at this point in the history
  • Loading branch information
Truong Hoang Dung authored and Truong Hoang Dung committed May 11, 2024
1 parent fe8099d commit a2db3af
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/examples/KanbanApp.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable jsx-a11y/no-autofocus */
import React from 'react';
import { StateDispatch, state$ } from '../hooks';

Expand All @@ -15,6 +16,7 @@ interface Column {

interface KanbanAppState {
columns: Column[];
focusedInput: string | null;
}

// Define messages
Expand All @@ -28,6 +30,9 @@ interface KanbanMessage {
sourceColumnId: string;
taskId: string;
};
SetFocusedInput: {
columnId: string | null;
};
}

// Kanban view component
Expand Down Expand Up @@ -59,6 +64,17 @@ function KanbanView({
});
};

const handleAddTask = (columnId: string, content: string) => {
if (content.trim() !== '') {
const newTask: Task = { id: `task${Date.now()}`, content };
dispatch('AddTask', { columnId, task: newTask });
}
};

const handleFocusInput = (columnId: string | null) => {
dispatch('SetFocusedInput', { columnId });
};

return (
<div className="kanban-board">
{state.columns.map((column) => (
Expand All @@ -80,6 +96,19 @@ function KanbanView({
</li>
))}
</ul>
<input
type="text"
placeholder="Enter new task"
onKeyDown={(e) => {
if (e.key === 'Enter') {
handleAddTask(column.id, e.currentTarget.value);
e.currentTarget.value = ''; // Clear input after adding task
}
}}
onFocus={() => handleFocusInput(column.id)}
onBlur={() => handleFocusInput(null)}
autoFocus={state.focusedInput === column.id}
/>
</div>
))}
</div>
Expand Down Expand Up @@ -110,6 +139,7 @@ export function KanbanApp() {
tasks: [],
},
],
focusedInput: null,
};

// Reducer for handling messages
Expand Down

0 comments on commit a2db3af

Please sign in to comment.