Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/db/todoSchemas.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ interface Todo {

interface TodoDetail {
description: string;
importance: boolean;
}
95 changes: 67 additions & 28 deletions src/todomanager/Detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,11 @@ function Detail({ id, onBack }: { id: string; onBack: () => void }) {
const { name, value, checked } = e.target;

if (selectedTodo) {
setSelectedTodo(prevTodo => {
if (!prevTodo) return prevTodo;
switch (name) {
case 'isComplete':
return {
...prevTodo,
isComplete: checked,
};
case 'dueDate':
return {
...prevTodo,
dueDate: new Date(value),
};
default:
return {
...prevTodo,
[name]: value,
};
}
setSelectedTodo({
...selectedTodo,
[name]: value,
[name]: name === 'isComplete' ? checked : value,
[name]: name === 'dueDate' ? new Date(value) : value,
});
updateTodo({
...selectedTodo,
Expand All @@ -53,15 +39,12 @@ function Detail({ id, onBack }: { id: string; onBack: () => void }) {
const { name, value } = e.target;

if (selectedTodo) {
setSelectedTodo(prevTodo => {
if (!prevTodo) return prevTodo;
return {
...prevTodo,
todoDetail: {
...prevTodo.todoDetail,
[name]: value,
},
};
setSelectedTodo({
...selectedTodo,
todoDetail: {
...selectedTodo.todoDetail,
[name]: value,
},
});
updateTodo({
...selectedTodo,
Expand All @@ -73,6 +56,25 @@ function Detail({ id, onBack }: { id: string; onBack: () => void }) {
}
};

const handleImportance = () => {
if (selectedTodo) {
const newImportance = !selectedTodo.todoDetail.importance;

setSelectedTodo({
...selectedTodo,
todoDetail: { ...selectedTodo.todoDetail, importance: newImportance },
});

updateTodo({
...selectedTodo,
todoDetail: {
...selectedTodo.todoDetail,
importance: newImportance,
},
});
}
};

useEffect(() => {
fetchTodo();
}, [id]);
Expand All @@ -91,6 +93,25 @@ function Detail({ id, onBack }: { id: string; onBack: () => void }) {
{!isModify ? (
<div className="flex justify-around items-center space-x-2 w-full">
<div className="text-lg">{selectedTodo?.title}</div>
<div className="flex items-center gap-2 h-transparent">
<button
type="button"
aria-label="importance"
className="border-none outline-none bg-transparent text-center"
onClick={() => handleImportance()}
>
{!selectedTodo?.todoDetail.importance ? (
<div className="relative w-6 h-8 bg-gray-300 text-white rounded-md shadow-md">
<div className="absolute -bottom-2 left-0 right-0 mx-auto w-0 h-0 border-t-[12px] border-t-gray-300 border-l-[12px] border-l-transparent border-r-[12px] border-r-transparent" />
</div>
) : (
<div className="relative w-6 h-8 bg-orange-500 text-white rounded-md shadow-md">
<div className="absolute -bottom-2 left-0 right-0 mx-auto w-0 h-0 border-t-[12px] border-t-orange-500 border-l-[12px] border-l-transparent border-r-[12px] border-r-transparent" />
</div>
)}
</button>
</div>

<div className="text-sm text-gray-600">
{selectedTodo?.dueDate && (
<div>{calculateDday(selectedTodo?.dueDate)}</div>
Expand All @@ -114,6 +135,24 @@ function Detail({ id, onBack }: { id: string; onBack: () => void }) {
onChange={handleInputChange}
className="border border-gray-300 focus:ring-2 focus:ring-brown-400 focus:outline-none rounded p-2 text-sm w-40"
/>
<div className="flex items-center gap-2 h-transparent">
<button
type="button"
aria-label="importance"
className="border-none outline-none bg-transparent text-center"
onClick={() => handleImportance()}
>
{!selectedTodo?.todoDetail.importance ? (
<div className="relative w-6 h-8 bg-gray-300 text-white rounded-md shadow-md">
<div className="absolute -bottom-2 left-0 right-0 mx-auto w-0 h-0 border-t-[12px] border-t-gray-300 border-l-[12px] border-l-transparent border-r-[12px] border-r-transparent" />
</div>
) : (
<div className="relative w-6 h-8 bg-orange-500 text-white rounded-md shadow-md">
<div className="absolute -bottom-2 left-0 right-0 mx-auto w-0 h-0 border-t-[12px] border-t-orange-500 border-l-[12px] border-l-transparent border-r-[12px] border-r-transparent" />
</div>
)}
</button>
</div>
<input
type="checkbox"
name="isComplete"
Expand Down
33 changes: 32 additions & 1 deletion src/todomanager/TodoList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function TodoList({ onSelectTodo }: TodoListProps) {
title: newTodo,
dueDate: undefined,
isComplete: false,
todoDetail: { description: '' },
todoDetail: { description: '', importance: false },
};
addTodo(newTodoItem);
setNewTodo('');
Expand Down Expand Up @@ -83,6 +83,19 @@ function TodoList({ onSelectTodo }: TodoListProps) {
}
};

const handleImportance = (id: string) => {
const selectedTodo = todoFromDB.find(todo => todo.id === id);
if (selectedTodo) {
updateTodo({
...selectedTodo,
todoDetail: {
...selectedTodo.todoDetail,
importance: !selectedTodo.todoDetail.importance,
},
});
}
};

useEffect(() => {
getTodosFromDB();
}, [todoFromDB]);
Expand Down Expand Up @@ -119,6 +132,24 @@ function TodoList({ onSelectTodo }: TodoListProps) {
</button>
)}

<div className="flex items-center gap-2 h-transparent">
<button
type="button"
aria-label="importance"
className="border-none outline-none bg-transparent text-center"
onClick={() => handleImportance(todo.id)}
>
{!todo.todoDetail.importance ? (
<div className="relative w-6 h-8 bg-gray-300 text-white rounded-md shadow-md">
<div className="absolute -bottom-2 left-0 right-0 mx-auto w-0 h-0 border-t-[12px] border-t-gray-300 border-l-[12px] border-l-transparent border-r-[12px] border-r-transparent" />
</div>
) : (
<div className="relative w-6 h-8 bg-orange-500 text-white rounded-md shadow-md">
<div className="absolute -bottom-2 left-0 right-0 mx-auto w-0 h-0 border-t-[12px] border-t-orange-500 border-l-[12px] border-l-transparent border-r-[12px] border-r-transparent" />
</div>
)}
</button>
</div>
<div className="flex items-center gap-2">
{editTodo?.id === todo.id ? (
<button
Expand Down