refactor: ordenar tarefas por status e simplificar note dialog

Tarefas pendentes agora aparecem primeiro, concluídas por último,
tanto nos cards quanto nos modais (details e edit).

Note dialog mais minimalista: remove labels redundantes, contadores
de caracteres, descriptions verbosas. Tarefas com line-through
quando concluídas, botão de remover mais sutil.

Cards de anotação agora usam grid responsivo (1/2/3 colunas)
igual aos cards de cartões, em vez de largura fixa 440px.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Felipe Coutinho
2026-02-26 17:44:02 +00:00
parent 283dfd70a8
commit 29b3bc1086
5 changed files with 139 additions and 186 deletions

View File

@@ -11,7 +11,7 @@ import {
import { useMemo } from "react"; import { useMemo } from "react";
import { Badge } from "@/components/ui/badge"; import { Badge } from "@/components/ui/badge";
import { Card, CardContent, CardFooter } from "@/components/ui/card"; import { Card, CardContent, CardFooter } from "@/components/ui/card";
import type { Note } from "./types"; import { type Note, sortTasksByStatus } from "./types";
const DATE_FORMATTER = new Intl.DateTimeFormat("pt-BR", { const DATE_FORMATTER = new Intl.DateTimeFormat("pt-BR", {
dateStyle: "medium", dateStyle: "medium",
@@ -47,6 +47,7 @@ export function NoteCard({
const isTask = note.type === "tarefa"; const isTask = note.type === "tarefa";
const tasks = note.tasks || []; const tasks = note.tasks || [];
const sortedTasks = useMemo(() => sortTasksByStatus(tasks), [tasks]);
const completedCount = tasks.filter((t) => t.completed).length; const completedCount = tasks.filter((t) => t.completed).length;
const totalCount = tasks.length; const totalCount = tasks.length;
@@ -82,7 +83,7 @@ export function NoteCard({
].filter((action) => typeof action.onClick === "function"); ].filter((action) => typeof action.onClick === "function");
return ( return (
<Card className="flex h-[300px] w-[440px] flex-col gap-0"> <Card className="flex h-[300px] w-full flex-col gap-0">
<CardContent className="flex min-h-0 flex-1 flex-col gap-4"> <CardContent className="flex min-h-0 flex-1 flex-col gap-4">
<div className="flex shrink-0 items-start justify-between gap-3"> <div className="flex shrink-0 items-start justify-between gap-3">
<div className="flex flex-col gap-2"> <div className="flex flex-col gap-2">
@@ -99,7 +100,7 @@ export function NoteCard({
{isTask ? ( {isTask ? (
<div className="min-h-0 flex-1 space-y-2 overflow-hidden"> <div className="min-h-0 flex-1 space-y-2 overflow-hidden">
{tasks.slice(0, 5).map((task) => ( {sortedTasks.slice(0, 5).map((task) => (
<div key={task.id} className="flex items-start gap-2 text-sm"> <div key={task.id} className="flex items-start gap-2 text-sm">
<div <div
className={`mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded-sm border ${ className={`mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded-sm border ${

View File

@@ -14,7 +14,7 @@ import {
DialogTitle, DialogTitle,
} from "@/components/ui/dialog"; } from "@/components/ui/dialog";
import { Card } from "../ui/card"; import { Card } from "../ui/card";
import type { Note } from "./types"; import { type Note, sortTasksByStatus } from "./types";
const DATE_FORMATTER = new Intl.DateTimeFormat("pt-BR", { const DATE_FORMATTER = new Intl.DateTimeFormat("pt-BR", {
dateStyle: "long", dateStyle: "long",
@@ -51,6 +51,7 @@ export function NoteDetailsDialog({
const isTask = note.type === "tarefa"; const isTask = note.type === "tarefa";
const tasks = note.tasks || []; const tasks = note.tasks || [];
const sortedTasks = useMemo(() => sortTasksByStatus(tasks), [tasks]);
const completedCount = tasks.filter((t) => t.completed).length; const completedCount = tasks.filter((t) => t.completed).length;
const totalCount = tasks.length; const totalCount = tasks.length;
@@ -71,7 +72,7 @@ export function NoteDetailsDialog({
{isTask ? ( {isTask ? (
<div className="max-h-[320px] overflow-auto space-y-3"> <div className="max-h-[320px] overflow-auto space-y-3">
{tasks.map((task) => ( {sortedTasks.map((task) => (
<Card <Card
key={task.id} key={task.id}
className="flex gap-3 p-3 flex-row items-center" className="flex gap-3 p-3 flex-row items-center"

View File

@@ -4,6 +4,7 @@ import { RiAddLine, RiDeleteBinLine } from "@remixicon/react";
import { import {
type ReactNode, type ReactNode,
useEffect, useEffect,
useMemo,
useRef, useRef,
useState, useState,
useTransition, useTransition,
@@ -29,8 +30,12 @@ import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
import { Textarea } from "@/components/ui/textarea"; import { Textarea } from "@/components/ui/textarea";
import { useControlledState } from "@/hooks/use-controlled-state"; import { useControlledState } from "@/hooks/use-controlled-state";
import { useFormState } from "@/hooks/use-form-state"; import { useFormState } from "@/hooks/use-form-state";
import { Card } from "../ui/card"; import {
import type { Note, NoteFormValues, Task } from "./types"; type Note,
type NoteFormValues,
sortTasksByStatus,
type Task,
} from "./types";
type NoteDialogMode = "create" | "update"; type NoteDialogMode = "create" | "update";
interface NoteDialogProps { interface NoteDialogProps {
@@ -94,17 +99,17 @@ export function NoteDialog({
}, [dialogOpen, note, setFormState]); }, [dialogOpen, note, setFormState]);
const title = mode === "create" ? "Nova anotação" : "Editar anotação"; const title = mode === "create" ? "Nova anotação" : "Editar anotação";
const description = const submitLabel = mode === "create" ? "Salvar" : "Atualizar";
mode === "create"
? "Escolha entre uma nota simples ou uma lista de tarefas."
: "Altere o título e/ou conteúdo desta anotação.";
const submitLabel =
mode === "create" ? "Salvar anotação" : "Atualizar anotação";
const titleCount = formState.title.length; const titleCount = formState.title.length;
const descCount = formState.description.length; const descCount = formState.description.length;
const isNote = formState.type === "nota"; const isNote = formState.type === "nota";
const sortedTasks = useMemo(
() => sortTasksByStatus(formState.tasks || []),
[formState.tasks],
);
const onlySpaces = const onlySpaces =
normalize(formState.title).length === 0 || normalize(formState.title).length === 0 ||
(isNote && formState.description.trim().length === 0) || (isNote && formState.description.trim().length === 0) ||
@@ -222,21 +227,20 @@ export function NoteDialog({
<DialogContent className="max-h-[90vh] overflow-y-auto"> <DialogContent className="max-h-[90vh] overflow-y-auto">
<DialogHeader> <DialogHeader>
<DialogTitle>{title}</DialogTitle> <DialogTitle>{title}</DialogTitle>
<DialogDescription>{description}</DialogDescription> <DialogDescription className="sr-only">
{mode === "create"
? "Criar nova anotação"
: "Editar anotação existente"}
</DialogDescription>
</DialogHeader> </DialogHeader>
<form <form
className="space-y-4" className="space-y-3"
onSubmit={handleSubmit} onSubmit={handleSubmit}
onKeyDown={handleKeyDown} onKeyDown={handleKeyDown}
noValidate noValidate
> >
{/* Seletor de Tipo - apenas no modo de criação */}
{mode === "create" && ( {mode === "create" && (
<div className="space-y-3">
<label className="text-sm font-medium text-foreground">
Tipo de anotação
</label>
<RadioGroup <RadioGroup
value={formState.type} value={formState.type}
onValueChange={(value) => onValueChange={(value) =>
@@ -264,90 +268,43 @@ export function NoteDialog({
</label> </label>
</div> </div>
</RadioGroup> </RadioGroup>
</div>
)} )}
{/* Título */}
<div className="space-y-2">
<label
htmlFor="note-title"
className="text-sm font-medium text-foreground"
>
Título
</label>
<Input <Input
id="note-title" id="note-title"
ref={titleRef} ref={titleRef}
value={formState.title} value={formState.title}
onChange={(e) => updateField("title", e.target.value)} onChange={(e) => updateField("title", e.target.value)}
placeholder={ placeholder="Título"
isNote ? "Ex.: Revisar metas do mês" : "Ex.: Tarefas da semana"
}
maxLength={MAX_TITLE} maxLength={MAX_TITLE}
disabled={isPending} disabled={isPending}
aria-describedby="note-title-help"
required required
/> />
<p
id="note-title-help"
className="text-xs text-muted-foreground"
aria-live="polite"
>
Até {MAX_TITLE} caracteres. Restantes:{" "}
{Math.max(0, MAX_TITLE - titleCount)}.
</p>
</div>
{/* Conteúdo - apenas para Notas */}
{isNote && ( {isNote && (
<div className="space-y-2">
<label
htmlFor="note-description"
className="text-sm font-medium text-foreground"
>
Conteúdo
</label>
<Textarea <Textarea
id="note-description" id="note-description"
className="field-sizing-fixed" className="field-sizing-fixed"
ref={descRef} ref={descRef}
value={formState.description} value={formState.description}
onChange={(e) => updateField("description", e.target.value)} onChange={(e) => updateField("description", e.target.value)}
placeholder="Detalhe sua anotação..." placeholder="Escreva sua anotação..."
rows={6} rows={5}
maxLength={MAX_DESC} maxLength={MAX_DESC}
disabled={isPending} disabled={isPending}
aria-describedby="note-desc-help"
required required
/> />
<p
id="note-desc-help"
className="text-xs text-muted-foreground"
aria-live="polite"
>
Até {MAX_DESC} caracteres. Restantes:{" "}
{Math.max(0, MAX_DESC - descCount)}.
</p>
</div>
)} )}
{/* Lista de Tarefas - apenas para Tarefas */}
{!isNote && ( {!isNote && (
<div className="space-y-4">
<div className="space-y-2"> <div className="space-y-2">
<label
htmlFor="new-task-input"
className="text-sm font-medium text-foreground"
>
Adicionar tarefa
</label>
<div className="flex gap-2"> <div className="flex gap-2">
<Input <Input
id="new-task-input" id="new-task-input"
ref={newTaskRef} ref={newTaskRef}
value={newTaskText} value={newTaskText}
onChange={(e) => setNewTaskText(e.target.value)} onChange={(e) => setNewTaskText(e.target.value)}
placeholder="Ex.: Comprar ingredientes para o jantar" placeholder="Nova tarefa..."
disabled={isPending} disabled={isPending}
onKeyDown={(e) => { onKeyDown={(e) => {
if (e.key === "Enter") { if (e.key === "Enter") {
@@ -358,6 +315,7 @@ export function NoteDialog({
/> />
<Button <Button
type="button" type="button"
variant="outline"
onClick={handleAddTask} onClick={handleAddTask}
disabled={isPending || !normalize(newTaskText)} disabled={isPending || !normalize(newTaskText)}
className="shrink-0" className="shrink-0"
@@ -365,55 +323,43 @@ export function NoteDialog({
<RiAddLine className="h-4 w-4" /> <RiAddLine className="h-4 w-4" />
</Button> </Button>
</div> </div>
<p className="text-xs text-muted-foreground">
Pressione Enter ou clique no botão + para adicionar
</p>
</div>
{/* Lista de tarefas existentes */} {sortedTasks.length > 0 && (
{formState.tasks && formState.tasks.length > 0 && ( <div className="space-y-1 max-h-[240px] overflow-y-auto pr-1">
<div className="space-y-2"> {sortedTasks.map((task) => (
<label className="text-sm font-medium text-foreground"> <div
Tarefas ({formState.tasks.length})
</label>
<div className="space-y-2 max-h-[240px] overflow-y-auto pr-1">
{formState.tasks.map((task) => (
<Card
key={task.id} key={task.id}
className="flex items-center gap-3 px-3 py-2 flex-row mt-1" className="flex items-center gap-3 px-3 py-1.5 rounded-md hover:bg-muted/50"
> >
<Checkbox <Checkbox
className="data-[state=checked]:bg-success data-[state=checked]:border-success" className="data-[state=checked]:bg-success data-[state=checked]:border-success"
checked={task.completed} checked={task.completed}
onCheckedChange={() => handleToggleTask(task.id)} onCheckedChange={() => handleToggleTask(task.id)}
disabled={isPending} disabled={isPending}
aria-label={`Marcar tarefa "${task.text}" como ${ aria-label={`Marcar "${task.text}" como ${
task.completed ? "não concluída" : "concluída" task.completed ? "não concluída" : "concluída"
}`} }`}
/> />
<span <span
className={`flex-1 text-sm wrap-break-word ${ className={`flex-1 text-sm wrap-break-word ${
task.completed task.completed
? "text-muted-foreground" ? "text-muted-foreground line-through"
: "text-foreground" : "text-foreground"
}`} }`}
> >
{task.text} {task.text}
</span> </span>
<Button <button
type="button" type="button"
variant="ghost"
size="sm"
onClick={() => handleRemoveTask(task.id)} onClick={() => handleRemoveTask(task.id)}
disabled={isPending} disabled={isPending}
className="h-8 w-8 p-0 shrink-0 text-muted-foreground hover:text-destructive" className="shrink-0 text-muted-foreground/50 hover:text-destructive transition-colors"
aria-label={`Remover tarefa "${task.text}"`} aria-label={`Remover "${task.text}"`}
> >
<RiDeleteBinLine className="h-4 w-4" /> <RiDeleteBinLine className="h-3.5 w-3.5" />
</Button> </button>
</Card>
))}
</div> </div>
))}
</div> </div>
)} )}
</div> </div>

View File

@@ -178,7 +178,7 @@ export function NotesPage({ notes, archivedNotes }: NotesPageProps) {
} }
return ( return (
<div className="flex flex-wrap gap-4"> <div className="grid gap-4 grid-cols-1 sm:grid-cols-2 xl:grid-cols-3">
{list.map((note) => ( {list.map((note) => (
<NoteCard <NoteCard
key={note.id} key={note.id}

View File

@@ -22,3 +22,8 @@ export interface NoteFormValues {
type: NoteType; type: NoteType;
tasks?: Task[]; tasks?: Task[];
} }
/** Ordena tarefas: pendentes primeiro, concluídas por último. */
export function sortTasksByStatus(tasks: Task[]): Task[] {
return [...tasks].sort((a, b) => Number(a.completed) - Number(b.completed));
}