mirror of
https://github.com/linsa-io/linsa.git
synced 2026-04-17 14:09:50 +02:00
create new task ui
This commit is contained in:
@@ -6,6 +6,8 @@ import { Input } from "@/components/ui/input"
|
|||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import { useAccount } from "@/lib/providers/jazz-provider"
|
import { useAccount } from "@/lib/providers/jazz-provider"
|
||||||
import { LaIcon } from "@/components/custom/la-icon"
|
import { LaIcon } from "@/components/custom/la-icon"
|
||||||
|
import { Checkbox } from "@/components/ui/checkbox"
|
||||||
|
import { format } from "date-fns"
|
||||||
|
|
||||||
interface TaskFormProps {}
|
interface TaskFormProps {}
|
||||||
|
|
||||||
@@ -17,8 +19,6 @@ export const TaskForm: React.FC<TaskFormProps> = ({}) => {
|
|||||||
|
|
||||||
const handleSubmit = (e: React.FormEvent) => {
|
const handleSubmit = (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
console.log(title.trim())
|
|
||||||
console.log(me, "me")
|
|
||||||
if (title.trim()) {
|
if (title.trim()) {
|
||||||
if (me?.root?.tasks === undefined) {
|
if (me?.root?.tasks === undefined) {
|
||||||
if (!me) return
|
if (!me) return
|
||||||
@@ -30,8 +30,8 @@ export const TaskForm: React.FC<TaskFormProps> = ({}) => {
|
|||||||
title,
|
title,
|
||||||
description: "",
|
description: "",
|
||||||
status: "todo",
|
status: "todo",
|
||||||
createdAt: new Date(),
|
createdAt: new Date()
|
||||||
updatedAt: new Date()
|
// updatedAt: new Date()
|
||||||
},
|
},
|
||||||
{ owner: me._owner }
|
{ owner: me._owner }
|
||||||
)
|
)
|
||||||
@@ -48,6 +48,8 @@ export const TaskForm: React.FC<TaskFormProps> = ({}) => {
|
|||||||
const handleKeyDown = (e: React.KeyboardEvent) => {
|
const handleKeyDown = (e: React.KeyboardEvent) => {
|
||||||
if (e.key === "Escape") {
|
if (e.key === "Escape") {
|
||||||
resetForm()
|
resetForm()
|
||||||
|
} else if (e.key === "Backspace" && title.trim() === "") {
|
||||||
|
resetForm()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,8 +59,10 @@ export const TaskForm: React.FC<TaskFormProps> = ({}) => {
|
|||||||
}
|
}
|
||||||
}, [inputVisible])
|
}, [inputVisible])
|
||||||
|
|
||||||
|
const formattedDate = format(new Date(), "EEE, MMMM do, yyyy")
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center space-x-2 p-4">
|
<div className="flex items-center space-x-2">
|
||||||
<AnimatePresence mode="wait">
|
<AnimatePresence mode="wait">
|
||||||
{!inputVisible ? (
|
{!inputVisible ? (
|
||||||
<motion.div
|
<motion.div
|
||||||
@@ -68,7 +72,12 @@ export const TaskForm: React.FC<TaskFormProps> = ({}) => {
|
|||||||
exit={{ opacity: 0, width: 0 }}
|
exit={{ opacity: 0, width: 0 }}
|
||||||
transition={{ duration: 0.3 }}
|
transition={{ duration: 0.3 }}
|
||||||
>
|
>
|
||||||
<Button onClick={() => setInputVisible(true)} variant="outline">
|
<Button
|
||||||
|
className="flex flex-row items-center gap-1"
|
||||||
|
onClick={() => setInputVisible(true)}
|
||||||
|
variant="outline"
|
||||||
|
>
|
||||||
|
<LaIcon name="Plus" />
|
||||||
Add task
|
Add task
|
||||||
</Button>
|
</Button>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
@@ -76,24 +85,27 @@ export const TaskForm: React.FC<TaskFormProps> = ({}) => {
|
|||||||
<motion.form
|
<motion.form
|
||||||
key="input-form"
|
key="input-form"
|
||||||
initial={{ width: 0, opacity: 0 }}
|
initial={{ width: 0, opacity: 0 }}
|
||||||
animate={{ width: "60%", opacity: 1 }}
|
animate={{ width: "100%", opacity: 1 }}
|
||||||
exit={{ width: 0, opacity: 0 }}
|
exit={{ width: 0, opacity: 0 }}
|
||||||
transition={{ duration: 0.3 }}
|
transition={{ duration: 0.3 }}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
className="flex items-center space-x-2"
|
className="bg-result flex w-full items-center justify-between rounded-lg p-2 px-3"
|
||||||
>
|
>
|
||||||
<Input
|
<div className="flex flex-row items-center gap-3">
|
||||||
autoFocus
|
<Checkbox checked={false} onCheckedChange={() => {}} />
|
||||||
ref={inputRef}
|
<Input
|
||||||
value={title}
|
autoFocus
|
||||||
className="flex-grow"
|
ref={inputRef}
|
||||||
onChange={e => setTitle(e.target.value)}
|
value={title}
|
||||||
onKeyDown={handleKeyDown}
|
className="flex-grow border-none bg-transparent p-0 focus-visible:ring-0"
|
||||||
placeholder="Enter task title"
|
onChange={e => setTitle(e.target.value)}
|
||||||
/>
|
onKeyDown={handleKeyDown}
|
||||||
<Button type="button" variant="ghost" size="icon" onClick={resetForm}>
|
// placeholder="Task title"
|
||||||
<LaIcon name="X" className="h-4 w-4" />
|
/>
|
||||||
</Button>
|
</div>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<span className="text-muted-foreground text-xs">{formattedDate}</span>
|
||||||
|
</div>
|
||||||
</motion.form>
|
</motion.form>
|
||||||
)}
|
)}
|
||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React from "react"
|
|
||||||
import { Task } from "@/lib/schema/tasks"
|
import { Task } from "@/lib/schema/tasks"
|
||||||
import { Checkbox } from "@/components/ui/checkbox"
|
import { Checkbox } from "@/components/ui/checkbox"
|
||||||
|
import { format } from "date-fns"
|
||||||
|
|
||||||
interface TaskItemProps {
|
interface TaskItemProps {
|
||||||
task: Task
|
task: Task
|
||||||
@@ -12,10 +12,15 @@ export const TaskItem: React.FC<TaskItemProps> = ({ task, onUpdateTask }) => {
|
|||||||
onUpdateTask(task.id, { status: checked ? "done" : "todo" })
|
onUpdateTask(task.id, { status: checked ? "done" : "todo" })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const formattedDate = format(new Date(task.createdAt), "EEE, MMMM do, yyyy")
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li className="flex items-center space-x-2">
|
<li className="bg-result transitiion-opacity flex items-center justify-between rounded-lg p-2 px-3 hover:opacity-60">
|
||||||
<Checkbox checked={task.status === "done"} onCheckedChange={statusChange} />
|
<div className="flex flex-row items-center gap-3">
|
||||||
<span className={task.status === "done" ? "text-foreground line-through" : ""}>{task.title}</span>
|
<Checkbox checked={task.status === "done"} onCheckedChange={statusChange} />
|
||||||
|
<p className={task.status === "done" ? "text-foreground line-through" : ""}>{task.title}</p>
|
||||||
|
</div>
|
||||||
|
<span className="text-muted-foreground text-xs">{formattedDate}</span>
|
||||||
</li>
|
</li>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,15 @@ interface TaskListProps {
|
|||||||
|
|
||||||
export const TaskList: React.FC<TaskListProps> = ({ tasks, onUpdateTask }) => {
|
export const TaskList: React.FC<TaskListProps> = ({ tasks, onUpdateTask }) => {
|
||||||
return (
|
return (
|
||||||
<ul className="space-y-2">
|
<ul className="flex flex-col gap-y-2">
|
||||||
{tasks?.map(task => task?.id && <TaskItem key={task.id} task={task} onUpdateTask={onUpdateTask} />)}
|
{tasks?.map(
|
||||||
|
task =>
|
||||||
|
task?.id && (
|
||||||
|
<li key={task.id}>
|
||||||
|
<TaskItem task={task} onUpdateTask={onUpdateTask} />
|
||||||
|
</li>
|
||||||
|
)
|
||||||
|
)}
|
||||||
</ul>
|
</ul>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useAccount } from "@/lib/providers/jazz-provider"
|
|||||||
import { Task } from "@/lib/schema/tasks"
|
import { Task } from "@/lib/schema/tasks"
|
||||||
import { TaskList } from "./TaskList"
|
import { TaskList } from "./TaskList"
|
||||||
import { TaskForm } from "./TaskForm"
|
import { TaskForm } from "./TaskForm"
|
||||||
|
import { LaIcon } from "@/components/custom/la-icon"
|
||||||
|
|
||||||
export const TaskRoute: React.FC = () => {
|
export const TaskRoute: React.FC = () => {
|
||||||
const { me } = useAccount({ root: { tasks: [] } })
|
const { me } = useAccount({ root: { tasks: [] } })
|
||||||
@@ -21,7 +22,10 @@ export const TaskRoute: React.FC = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col space-y-4 p-4">
|
<div className="flex flex-col space-y-4 p-4">
|
||||||
<h1 className="text-2xl font-bold">Tasks</h1>
|
<div className="flex flex-row items-center gap-1">
|
||||||
|
<LaIcon name="ListTodo" className="size-6" />
|
||||||
|
<h1 className="text-xl font-bold">Current Tasks</h1>
|
||||||
|
</div>
|
||||||
<TaskForm />
|
<TaskForm />
|
||||||
<TaskList tasks={tasks} onUpdateTask={updateTask} />
|
<TaskList tasks={tasks} onUpdateTask={updateTask} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ export class Task extends CoMap {
|
|||||||
description = co.optional.string
|
description = co.optional.string
|
||||||
status = co.literal("todo", "in_progress", "done")
|
status = co.literal("todo", "in_progress", "done")
|
||||||
createdAt = co.encoded(Encoders.Date)
|
createdAt = co.encoded(Encoders.Date)
|
||||||
updatedAt = co.encoded(Encoders.Date)
|
// updatedAt = co.encoded(Encoders.Date)
|
||||||
completedAt = co.optional.encoded(Encoders.Date)
|
completedAt = co.optional.encoded(Encoders.Date)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user