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:
@@ -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 ${
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
@@ -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,198 +227,139 @@ 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">
|
<RadioGroup
|
||||||
<label className="text-sm font-medium text-foreground">
|
value={formState.type}
|
||||||
Tipo de anotação
|
onValueChange={(value) =>
|
||||||
</label>
|
updateField("type", value as "nota" | "tarefa")
|
||||||
<RadioGroup
|
}
|
||||||
value={formState.type}
|
disabled={isPending}
|
||||||
onValueChange={(value) =>
|
className="flex gap-4"
|
||||||
updateField("type", value as "nota" | "tarefa")
|
>
|
||||||
}
|
<div className="flex items-center gap-2">
|
||||||
disabled={isPending}
|
<RadioGroupItem value="nota" id="tipo-nota" />
|
||||||
className="flex gap-4"
|
<label
|
||||||
>
|
htmlFor="tipo-nota"
|
||||||
<div className="flex items-center gap-2">
|
className="text-sm cursor-pointer select-none"
|
||||||
<RadioGroupItem value="nota" id="tipo-nota" />
|
>
|
||||||
<label
|
Nota
|
||||||
htmlFor="tipo-nota"
|
</label>
|
||||||
className="text-sm cursor-pointer select-none"
|
</div>
|
||||||
>
|
<div className="flex items-center gap-2">
|
||||||
Nota
|
<RadioGroupItem value="tarefa" id="tipo-tarefa" />
|
||||||
</label>
|
<label
|
||||||
</div>
|
htmlFor="tipo-tarefa"
|
||||||
<div className="flex items-center gap-2">
|
className="text-sm cursor-pointer select-none"
|
||||||
<RadioGroupItem value="tarefa" id="tipo-tarefa" />
|
>
|
||||||
<label
|
Tarefas
|
||||||
htmlFor="tipo-tarefa"
|
</label>
|
||||||
className="text-sm cursor-pointer select-none"
|
</div>
|
||||||
>
|
</RadioGroup>
|
||||||
Tarefas
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</RadioGroup>
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Título */}
|
<Input
|
||||||
<div className="space-y-2">
|
id="note-title"
|
||||||
<label
|
ref={titleRef}
|
||||||
htmlFor="note-title"
|
value={formState.title}
|
||||||
className="text-sm font-medium text-foreground"
|
onChange={(e) => updateField("title", e.target.value)}
|
||||||
>
|
placeholder="Título"
|
||||||
Título
|
maxLength={MAX_TITLE}
|
||||||
</label>
|
disabled={isPending}
|
||||||
<Input
|
required
|
||||||
id="note-title"
|
/>
|
||||||
ref={titleRef}
|
|
||||||
value={formState.title}
|
{isNote && (
|
||||||
onChange={(e) => updateField("title", e.target.value)}
|
<Textarea
|
||||||
placeholder={
|
id="note-description"
|
||||||
isNote ? "Ex.: Revisar metas do mês" : "Ex.: Tarefas da semana"
|
className="field-sizing-fixed"
|
||||||
}
|
ref={descRef}
|
||||||
maxLength={MAX_TITLE}
|
value={formState.description}
|
||||||
|
onChange={(e) => updateField("description", e.target.value)}
|
||||||
|
placeholder="Escreva sua anotação..."
|
||||||
|
rows={5}
|
||||||
|
maxLength={MAX_DESC}
|
||||||
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 && (
|
|
||||||
<div className="space-y-2">
|
|
||||||
<label
|
|
||||||
htmlFor="note-description"
|
|
||||||
className="text-sm font-medium text-foreground"
|
|
||||||
>
|
|
||||||
Conteúdo
|
|
||||||
</label>
|
|
||||||
<Textarea
|
|
||||||
id="note-description"
|
|
||||||
className="field-sizing-fixed"
|
|
||||||
ref={descRef}
|
|
||||||
value={formState.description}
|
|
||||||
onChange={(e) => updateField("description", e.target.value)}
|
|
||||||
placeholder="Detalhe sua anotação..."
|
|
||||||
rows={6}
|
|
||||||
maxLength={MAX_DESC}
|
|
||||||
disabled={isPending}
|
|
||||||
aria-describedby="note-desc-help"
|
|
||||||
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">
|
<div className="flex gap-2">
|
||||||
<label
|
<Input
|
||||||
htmlFor="new-task-input"
|
id="new-task-input"
|
||||||
className="text-sm font-medium text-foreground"
|
ref={newTaskRef}
|
||||||
|
value={newTaskText}
|
||||||
|
onChange={(e) => setNewTaskText(e.target.value)}
|
||||||
|
placeholder="Nova tarefa..."
|
||||||
|
disabled={isPending}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
handleAddTask();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={handleAddTask}
|
||||||
|
disabled={isPending || !normalize(newTaskText)}
|
||||||
|
className="shrink-0"
|
||||||
>
|
>
|
||||||
Adicionar tarefa
|
<RiAddLine className="h-4 w-4" />
|
||||||
</label>
|
</Button>
|
||||||
<div className="flex gap-2">
|
|
||||||
<Input
|
|
||||||
id="new-task-input"
|
|
||||||
ref={newTaskRef}
|
|
||||||
value={newTaskText}
|
|
||||||
onChange={(e) => setNewTaskText(e.target.value)}
|
|
||||||
placeholder="Ex.: Comprar ingredientes para o jantar"
|
|
||||||
disabled={isPending}
|
|
||||||
onKeyDown={(e) => {
|
|
||||||
if (e.key === "Enter") {
|
|
||||||
e.preventDefault();
|
|
||||||
handleAddTask();
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
onClick={handleAddTask}
|
|
||||||
disabled={isPending || !normalize(newTaskText)}
|
|
||||||
className="shrink-0"
|
|
||||||
>
|
|
||||||
<RiAddLine className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
Pressione Enter ou clique no botão + para adicionar
|
|
||||||
</p>
|
|
||||||
</div>
|
</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})
|
key={task.id}
|
||||||
</label>
|
className="flex items-center gap-3 px-3 py-1.5 rounded-md hover:bg-muted/50"
|
||||||
<div className="space-y-2 max-h-[240px] overflow-y-auto pr-1">
|
>
|
||||||
{formState.tasks.map((task) => (
|
<Checkbox
|
||||||
<Card
|
className="data-[state=checked]:bg-success data-[state=checked]:border-success"
|
||||||
key={task.id}
|
checked={task.completed}
|
||||||
className="flex items-center gap-3 px-3 py-2 flex-row mt-1"
|
onCheckedChange={() => handleToggleTask(task.id)}
|
||||||
|
disabled={isPending}
|
||||||
|
aria-label={`Marcar "${task.text}" como ${
|
||||||
|
task.completed ? "não concluída" : "concluída"
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
className={`flex-1 text-sm wrap-break-word ${
|
||||||
|
task.completed
|
||||||
|
? "text-muted-foreground line-through"
|
||||||
|
: "text-foreground"
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
<Checkbox
|
{task.text}
|
||||||
className="data-[state=checked]:bg-success data-[state=checked]:border-success"
|
</span>
|
||||||
checked={task.completed}
|
<button
|
||||||
onCheckedChange={() => handleToggleTask(task.id)}
|
type="button"
|
||||||
disabled={isPending}
|
onClick={() => handleRemoveTask(task.id)}
|
||||||
aria-label={`Marcar tarefa "${task.text}" como ${
|
disabled={isPending}
|
||||||
task.completed ? "não concluída" : "concluída"
|
className="shrink-0 text-muted-foreground/50 hover:text-destructive transition-colors"
|
||||||
}`}
|
aria-label={`Remover "${task.text}"`}
|
||||||
/>
|
>
|
||||||
<span
|
<RiDeleteBinLine className="h-3.5 w-3.5" />
|
||||||
className={`flex-1 text-sm wrap-break-word ${
|
</button>
|
||||||
task.completed
|
</div>
|
||||||
? "text-muted-foreground"
|
))}
|
||||||
: "text-foreground"
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
{task.text}
|
|
||||||
</span>
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
variant="ghost"
|
|
||||||
size="sm"
|
|
||||||
onClick={() => handleRemoveTask(task.id)}
|
|
||||||
disabled={isPending}
|
|
||||||
className="h-8 w-8 p-0 shrink-0 text-muted-foreground hover:text-destructive"
|
|
||||||
aria-label={`Remover tarefa "${task.text}"`}
|
|
||||||
>
|
|
||||||
<RiDeleteBinLine className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</Card>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -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}
|
||||||
|
|||||||
@@ -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));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user