Add priority
This commit is contained in:
parent
33f050085c
commit
43eef83aa8
@ -28,24 +28,24 @@ public class TodosController : ApiController
|
||||
[JsonPropertyName("project")]
|
||||
public string? Project { get; init; }
|
||||
|
||||
[JsonPropertyName("priority")]
|
||||
public string? Priority { get; init; }
|
||||
|
||||
internal CreateTodoCommand To() => new(
|
||||
Title,
|
||||
Project,
|
||||
Description);
|
||||
Description,
|
||||
Priority);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<string>> CreateTodo(
|
||||
[FromBody] CreateTodoRequest request)
|
||||
{
|
||||
return Ok(await Mediator.Send(request.To()));
|
||||
}
|
||||
=> Ok(await Mediator.Send(request.To()));
|
||||
|
||||
[HttpGet("{todoId}")]
|
||||
public async Task<ActionResult<TodoViewModel>> GetTodoById([FromRoute] string todoId)
|
||||
{
|
||||
return await Mediator.Send(new GetTodoByIdQuery(todoId));
|
||||
}
|
||||
=> await Mediator.Send(new GetTodoByIdQuery(todoId));
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<TodoViewModel>>> GetTodos([FromQuery] bool onlyActive = false)
|
||||
|
@ -42,7 +42,7 @@ public record CreateTodoCommand(
|
||||
request.TodoTitle,
|
||||
request.TodoProject,
|
||||
request.TodoDescription,
|
||||
request.Priority
|
||||
request.Priority,
|
||||
userId,
|
||||
DateTimeOffset.UtcNow.ToUnixTimeMilliseconds());
|
||||
|
||||
|
@ -7,7 +7,8 @@ public record TodoViewModel(
|
||||
string AuthorId,
|
||||
string? Project,
|
||||
string? Description,
|
||||
long Created
|
||||
long Created,
|
||||
string? Priority
|
||||
)
|
||||
{
|
||||
internal static TodoViewModel From(Entities.Todo t) => new(
|
||||
@ -17,5 +18,6 @@ public record TodoViewModel(
|
||||
t.AuthorId,
|
||||
t.Project,
|
||||
t.Description,
|
||||
t.Created);
|
||||
t.Created,
|
||||
t.Priority);
|
||||
}
|
@ -21,6 +21,7 @@ public class TodoRepository : ITodoRepository
|
||||
string title,
|
||||
string? projectName,
|
||||
string? description,
|
||||
string? priority,
|
||||
string userId,
|
||||
long created)
|
||||
{
|
||||
@ -31,7 +32,8 @@ public class TodoRepository : ITodoRepository
|
||||
Status = false,
|
||||
AuthorId = userId,
|
||||
Description = description,
|
||||
Created = created
|
||||
Created = created,
|
||||
Priority = priority
|
||||
};
|
||||
await _todosCollection.InsertOneAsync(todo);
|
||||
return todo.To();
|
||||
@ -77,7 +79,8 @@ public class TodoRepository : ITodoRepository
|
||||
ProjectName = todo.Project,
|
||||
AuthorId = todo.AuthorId,
|
||||
Description = todo.Description,
|
||||
Created = todo.Created
|
||||
Created = todo.Created,
|
||||
Priority = todo.Priority
|
||||
});
|
||||
|
||||
return updatedTodo.To();
|
||||
|
@ -11,6 +11,22 @@ interface TodoItemProps {
|
||||
displayProject: boolean;
|
||||
}
|
||||
|
||||
function getColorFromPriority(priority: string) {
|
||||
switch (priority) {
|
||||
case "p3":
|
||||
return "bg-red-500";
|
||||
|
||||
case "p2":
|
||||
return "bg-yellow-500";
|
||||
|
||||
case "p1":
|
||||
return "bg-green-500";
|
||||
|
||||
default:
|
||||
throw "No priority matches";
|
||||
}
|
||||
}
|
||||
|
||||
export const TodoItem: FC<TodoItemProps> = (props) => {
|
||||
const [isHovering, setIsHovering] = useState(false);
|
||||
const [menuIsOpen, setMenuIsOpen] = useState(false);
|
||||
@ -42,6 +58,15 @@ export const TodoItem: FC<TodoItemProps> = (props) => {
|
||||
{props.todo.description && (
|
||||
<div className="h-3 w-3 bg-gray-100 dark:border-black border border-gray-300 dark:bg-gray-900 rounded-sm" />
|
||||
)}
|
||||
{props.todo.priority && (
|
||||
<div
|
||||
className={`rounded-md select-none text-xs p-1 text-white font-bold ${getColorFromPriority(
|
||||
props.todo.priority
|
||||
)}`}
|
||||
>
|
||||
{props.todo.priority}
|
||||
</div>
|
||||
)}
|
||||
{!props.todo.authorId && (
|
||||
<div className="h-3 w-3 bg-red-500 rounded-sm" />
|
||||
)}
|
||||
|
@ -2,6 +2,7 @@ import { Todo } from "@src/core/entities/todo";
|
||||
import { TodoItem } from "@src/components/todos/todoItem";
|
||||
import { AddTodo } from "@src/components/todos/addTodo";
|
||||
import { useUpdateTodo } from "@src/presentation/hooks/socketHooks";
|
||||
import { useMemo } from "react";
|
||||
|
||||
export const TodoList = (props: {
|
||||
todos: Todo[];
|
||||
@ -11,17 +12,21 @@ export const TodoList = (props: {
|
||||
}) => {
|
||||
const { updateTodo } = useUpdateTodo();
|
||||
|
||||
return (
|
||||
<>
|
||||
<ul id="inbox">
|
||||
{props.todos
|
||||
const todos: Todo[] = useMemo(() => {
|
||||
return props.todos
|
||||
.filter((t) => {
|
||||
if (!props.hideDone) return true;
|
||||
|
||||
return t.status == false;
|
||||
})
|
||||
.sort((a, b) => a.created - b.created)
|
||||
.map((t, i) => (
|
||||
.sort((a, b) => b.priority.localeCompare(a.priority));
|
||||
}, [props.todos, props.hideDone]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<ul id="inbox">
|
||||
{todos.map((t, i) => (
|
||||
<li key={i}>
|
||||
<TodoItem
|
||||
todo={t}
|
||||
|
@ -6,6 +6,12 @@ export const StatusState: { done: Done; notDone: NotDone } = {
|
||||
notDone: false,
|
||||
};
|
||||
|
||||
enum Priorities {
|
||||
p1 = "p1",
|
||||
p2 = "p2",
|
||||
p3 = "p3",
|
||||
}
|
||||
|
||||
export interface Todo {
|
||||
id: string;
|
||||
title: string;
|
||||
@ -14,7 +20,7 @@ export interface Todo {
|
||||
project?: string;
|
||||
authorId?: string;
|
||||
created: number;
|
||||
priority?: string;
|
||||
priority?: Priorities;
|
||||
}
|
||||
|
||||
export const asTodo = (item: Todo): Todo => {
|
||||
|
Loading…
Reference in New Issue
Block a user