Add project to edit
Some checks failed
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is failing

This commit is contained in:
Kasper Juul Hermansen 2021-11-15 22:46:14 +01:00
parent 1865425d38
commit 56711f5b59
Signed by: kjuulh
GPG Key ID: 0F95C140730F2F23
2 changed files with 20 additions and 13 deletions

View File

@ -4,7 +4,7 @@ import {
useUpdateTodo, useUpdateTodo,
} from "@src/presentation/hooks/socketHooks"; } from "@src/presentation/hooks/socketHooks";
import { Todo } from "@src/core/entities/todo"; import { Todo } from "@src/core/entities/todo";
import { FC, useEffect, useState } from "react"; import { FC, useState } from "react";
import { PageHeading } from "@src/components/common/headings/pageHeading"; import { PageHeading } from "@src/components/common/headings/pageHeading";
import { TodoCheckmark } from "@src/components/todos/todoCheckmark"; import { TodoCheckmark } from "@src/components/todos/todoCheckmark";
@ -15,6 +15,7 @@ interface EditTodoProps {
} }
const EditTodo: FC<EditTodoProps> = ({ todo, onCancel, onSave }) => { const EditTodo: FC<EditTodoProps> = ({ todo, onCancel, onSave }) => {
const [todoTitle, setTodoTitle] = useState(todo.title); const [todoTitle, setTodoTitle] = useState(todo.title);
const [project, setProject] = useState(todo.project);
return ( return (
<div className="space-y-4 flex-grow"> <div className="space-y-4 flex-grow">
@ -26,11 +27,22 @@ const EditTodo: FC<EditTodoProps> = ({ todo, onCancel, onSave }) => {
type="text" type="text"
/> />
</div> </div>
<div className="todo-project py-2 px-4 bg-gray-700 border border-gray-500 rounded-lg ">
<input
type="text"
placeholder="Project name"
className="text-sm w-full placeholder-gray-400"
value={project}
tabIndex={2}
onChange={(e) => setProject(e.target.value)}
/>
</div>
<div className="space-x-4"> <div className="space-x-4">
<button <button
className="base-button dark:bg-accent-500 disabled:bg-accent-800 active:bg-accent-400" className="base-button dark:bg-accent-500 disabled:bg-accent-800 active:bg-accent-400"
onClick={() => { onClick={() => {
onSave({ ...todo, title: todoTitle }); onSave({ ...todo, title: todoTitle, project });
}} }}
> >
Save Save
@ -48,24 +60,19 @@ interface TodoDetailsProps {
} }
const TodoDetails: FC<TodoDetailsProps> = ({ todo }) => { const TodoDetails: FC<TodoDetailsProps> = ({ todo }) => {
const [updatedTodo, setUpdatedTodo] = useState(todo);
const { updateTodo } = useUpdateTodo(); const { updateTodo } = useUpdateTodo();
const [editMode, setEditMode] = useState(false); const [editMode, setEditMode] = useState(false);
useEffect(() => {
updateTodo(updatedTodo);
}, [updatedTodo]);
return ( return (
<div className="bg-gray-800 rounded-xl p-8 shadow-lg space-y-4"> <div className="bg-gray-800 rounded-xl p-8 shadow-lg space-y-4">
<PageHeading title={updatedTodo.project || "Inbox"} /> <PageHeading title={todo.project || "Inbox"} />
<div className="flex flex-row items-center gap-4"> <div className="flex flex-row items-center gap-4">
{editMode ? ( {editMode ? (
<EditTodo <EditTodo
todo={todo} todo={todo}
onCancel={() => setEditMode(false)} onCancel={() => setEditMode(false)}
onSave={(todo) => { onSave={(todo) => {
setUpdatedTodo(todo); updateTodo(todo);
setEditMode(false); setEditMode(false);
}} }}
/> />
@ -73,12 +80,12 @@ const TodoDetails: FC<TodoDetailsProps> = ({ todo }) => {
<> <>
<TodoCheckmark <TodoCheckmark
updateTodo={(t) => { updateTodo={(t) => {
setUpdatedTodo(t); updateTodo(t);
}} }}
todo={updatedTodo} todo={todo}
/> />
<h4 className="flex-grow" onClick={() => setEditMode(true)}> <h4 className="flex-grow" onClick={() => setEditMode(true)}>
{updatedTodo.title} {todo.title}
</h4> </h4>
</> </>
)} )}

View File

@ -63,7 +63,7 @@ export const SocketProvider: FC = (props) => {
const newTodo = JSON.parse(todo) as Todo; const newTodo = JSON.parse(todo) as Todo;
const validatedTodo = asTodo(newTodo); const validatedTodo = asTodo(newTodo);
setTodos([ setTodos([
...todos.filter((t) => t.id != validatedTodo.id), ...todos.filter((t) => t.id !== validatedTodo.id),
validatedTodo, validatedTodo,
]); ]);
}); });