mirror of
https://github.com/linsa-io/linsa.git
synced 2026-04-24 09:18:37 +02:00
tasks logic
This commit is contained in:
@@ -71,11 +71,6 @@ export const TaskSection: React.FC<{ pathname: string }> = ({ pathname }) => {
|
|||||||
count={upcomingTasks.length}
|
count={upcomingTasks.length}
|
||||||
isActive={pathname === "/tasks/upcoming"}
|
isActive={pathname === "/tasks/upcoming"}
|
||||||
/>
|
/>
|
||||||
{isFetching ? (
|
|
||||||
<div className="py-2 text-center text-gray-500">Fetching tasks...</div>
|
|
||||||
) : (
|
|
||||||
<List tasks={me.root.tasks as ListOfTasks} />
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -105,13 +100,3 @@ const TaskSectionHeader: React.FC<TaskSectionHeaderProps> = ({ title, href, coun
|
|||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
||||||
interface ListProps {
|
|
||||||
tasks: (Task | null)[] | undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
const List: React.FC<ListProps> = ({ tasks }) => {
|
|
||||||
return (
|
|
||||||
<div>{tasks?.filter((task): task is Task => task !== null).map(task => <div key={task.id}>{task.title}</div>)}</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,126 +1,3 @@
|
|||||||
// import { useState, useEffect, useRef } from "react"
|
|
||||||
// import { motion, AnimatePresence } from "framer-motion"
|
|
||||||
// import { ListOfTasks, Task } from "@/lib/schema/tasks"
|
|
||||||
// import { Input } from "@/components/ui/input"
|
|
||||||
// import { Button } from "@/components/ui/button"
|
|
||||||
// import { useAccount } from "@/lib/providers/jazz-provider"
|
|
||||||
// import { LaIcon } from "@/components/custom/la-icon"
|
|
||||||
// import { Checkbox } from "@/components/ui/checkbox"
|
|
||||||
// import { format } from "date-fns"
|
|
||||||
// import { DatePicker } from "@/components/ui/date-picker"
|
|
||||||
|
|
||||||
// interface TaskFormProps {
|
|
||||||
// filter?: "today" | "upcoming"
|
|
||||||
// }
|
|
||||||
|
|
||||||
// export const TaskForm: React.FC<TaskFormProps> = ({ filter }) => {
|
|
||||||
// const [title, setTitle] = useState("")
|
|
||||||
// const [dueDate, setDueDate] = useState<Date | undefined>(filter === "today" ? new Date() : undefined)
|
|
||||||
// const [inputVisible, setInputVisible] = useState(false)
|
|
||||||
// const { me } = useAccount({ root: {} })
|
|
||||||
// const inputRef = useRef<HTMLInputElement>(null)
|
|
||||||
|
|
||||||
// const handleSubmit = (e: React.FormEvent) => {
|
|
||||||
// e.preventDefault()
|
|
||||||
// if (title.trim() && (filter !== "upcoming" || dueDate)) {
|
|
||||||
// if (me?.root?.tasks === undefined) {
|
|
||||||
// if (!me) return
|
|
||||||
// me.root.tasks = ListOfTasks.create([], { owner: me })
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const newTask = Task.create(
|
|
||||||
// {
|
|
||||||
// title,
|
|
||||||
// description: "",
|
|
||||||
// status: "todo",
|
|
||||||
// createdAt: new Date(),
|
|
||||||
// updatedAt: new Date(),
|
|
||||||
// dueDate: dueDate || null
|
|
||||||
// },
|
|
||||||
// { owner: me._owner }
|
|
||||||
// )
|
|
||||||
// me.root.tasks?.push(newTask)
|
|
||||||
// resetForm()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const resetForm = () => {
|
|
||||||
// setTitle("")
|
|
||||||
// setDueDate(filter === "today" ? new Date() : undefined)
|
|
||||||
// setInputVisible(false)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const handleKeyDown = (e: React.KeyboardEvent) => {
|
|
||||||
// if (e.key === "Escape") {
|
|
||||||
// resetForm()
|
|
||||||
// } else if (e.key === "Backspace" && title.trim() === "") {
|
|
||||||
// resetForm()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// useEffect(() => {
|
|
||||||
// if (inputVisible && inputRef.current) {
|
|
||||||
// inputRef.current.focus()
|
|
||||||
// }
|
|
||||||
// }, [inputVisible])
|
|
||||||
|
|
||||||
// const formattedDate = dueDate ? format(dueDate, "EEE, MMMM do, yyyy") : "Select a date"
|
|
||||||
|
|
||||||
// return (
|
|
||||||
// <div className="flex items-center space-x-2">
|
|
||||||
// <AnimatePresence mode="wait">
|
|
||||||
// {!inputVisible ? (
|
|
||||||
// <motion.div
|
|
||||||
// key="add-button"
|
|
||||||
// initial={{ opacity: 0, width: 0 }}
|
|
||||||
// animate={{ opacity: 1, width: "auto" }}
|
|
||||||
// exit={{ opacity: 0, width: 0 }}
|
|
||||||
// transition={{ duration: 0.3 }}
|
|
||||||
// >
|
|
||||||
// <Button
|
|
||||||
// className="flex flex-row items-center gap-1"
|
|
||||||
// onClick={() => setInputVisible(true)}
|
|
||||||
// variant="outline"
|
|
||||||
// >
|
|
||||||
// <LaIcon name="Plus" />
|
|
||||||
// Add task
|
|
||||||
// </Button>
|
|
||||||
// </motion.div>
|
|
||||||
// ) : (
|
|
||||||
// <motion.form
|
|
||||||
// key="input-form"
|
|
||||||
// initial={{ width: 0, opacity: 0 }}
|
|
||||||
// animate={{ width: "100%", opacity: 1 }}
|
|
||||||
// exit={{ width: 0, opacity: 0 }}
|
|
||||||
// transition={{ duration: 0.3 }}
|
|
||||||
// onSubmit={handleSubmit}
|
|
||||||
// className="bg-result flex w-full items-center justify-between rounded-lg p-2 px-3"
|
|
||||||
// >
|
|
||||||
// <div className="flex flex-row items-center gap-3">
|
|
||||||
// <Checkbox checked={false} onCheckedChange={() => {}} />
|
|
||||||
// <Input
|
|
||||||
// autoFocus
|
|
||||||
// ref={inputRef}
|
|
||||||
// value={title}
|
|
||||||
// className="flex-grow border-none bg-transparent p-0 focus-visible:ring-0"
|
|
||||||
// onChange={e => setTitle(e.target.value)}
|
|
||||||
// onKeyDown={handleKeyDown}
|
|
||||||
// placeholder="Task title"
|
|
||||||
// />
|
|
||||||
// </div>
|
|
||||||
// <div className="flex items-center space-x-2">
|
|
||||||
// {filter === "upcoming" && (
|
|
||||||
// <DatePicker date={dueDate} onDateChange={(date: Date | undefined) => setDueDate(date)} />
|
|
||||||
// )}
|
|
||||||
// <span className="text-muted-foreground text-xs">{formattedDate}</span>
|
|
||||||
// </div>
|
|
||||||
// </motion.form>
|
|
||||||
// )}
|
|
||||||
// </AnimatePresence>
|
|
||||||
// </div>
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
|
|
||||||
import { useState, useEffect, useRef } from "react"
|
import { useState, useEffect, useRef } from "react"
|
||||||
import { motion, AnimatePresence } from "framer-motion"
|
import { motion, AnimatePresence } from "framer-motion"
|
||||||
import { ListOfTasks, Task } from "@/lib/schema/tasks"
|
import { ListOfTasks, Task } from "@/lib/schema/tasks"
|
||||||
@@ -145,7 +22,7 @@ export const TaskForm: React.FC<TaskFormProps> = ({ filter }) => {
|
|||||||
|
|
||||||
const handleSubmit = (e: React.FormEvent) => {
|
const handleSubmit = (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
if (title.trim() && (filter === "today" || (filter === "upcoming" && dueDate))) {
|
if (title.trim() && (filter !== "upcoming" || dueDate)) {
|
||||||
if (me?.root?.tasks === undefined) {
|
if (me?.root?.tasks === undefined) {
|
||||||
if (!me) return
|
if (!me) return
|
||||||
me.root.tasks = ListOfTasks.create([], { owner: me })
|
me.root.tasks = ListOfTasks.create([], { owner: me })
|
||||||
@@ -158,7 +35,7 @@ export const TaskForm: React.FC<TaskFormProps> = ({ filter }) => {
|
|||||||
status: "todo",
|
status: "todo",
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
dueDate: dueDate || (filter === "today" ? new Date() : null)
|
dueDate: filter === "upcoming" ? dueDate : filter === "today" ? new Date() : null
|
||||||
},
|
},
|
||||||
{ owner: me._owner }
|
{ owner: me._owner }
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { Task } from "@/lib/schema/tasks"
|
|||||||
import { Checkbox } from "@/components/ui/checkbox"
|
import { Checkbox } from "@/components/ui/checkbox"
|
||||||
import { format } from "date-fns"
|
import { format } from "date-fns"
|
||||||
import { useState, useRef, useEffect } from "react"
|
import { useState, useRef, useEffect } from "react"
|
||||||
import { Input } from "@/components/ui/input"
|
|
||||||
|
|
||||||
interface TaskItemProps {
|
interface TaskItemProps {
|
||||||
task: Task
|
task: Task
|
||||||
@@ -50,7 +49,7 @@ export const TaskItem: React.FC<TaskItemProps> = ({ task, onUpdateTask, onDelete
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const formattedDate = format(new Date(task.createdAt), "EEE, MMMM do, yyyy")
|
const formattedDate = task.dueDate ? format(new Date(task.dueDate), "EEE, MMMM do, yyyy") : "No due date"
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li className="bg-result transitiion-opacity flex items-center justify-between rounded-lg p-2 px-3 hover:opacity-60">
|
<li className="bg-result transitiion-opacity flex items-center justify-between rounded-lg p-2 px-3 hover:opacity-60">
|
||||||
|
|||||||
@@ -46,7 +46,10 @@ export const TaskRoute: React.FC<TaskRouteProps> = ({ filter }) => {
|
|||||||
return (
|
return (
|
||||||
<div className="flex flex-col space-y-4 p-4">
|
<div className="flex flex-col space-y-4 p-4">
|
||||||
<div className="flex flex-row items-center gap-1">
|
<div className="flex flex-row items-center gap-1">
|
||||||
<LaIcon name="ListTodo" className="size-6" />
|
<LaIcon
|
||||||
|
name={filter === "today" ? "BookOpenCheck" : filter === "upcoming" ? "History" : "ListTodo"}
|
||||||
|
className="size-6"
|
||||||
|
/>
|
||||||
<h1 className="text-xl font-bold">
|
<h1 className="text-xl font-bold">
|
||||||
{filter === "today" ? "Today's Tasks" : filter === "upcoming" ? "Upcoming Tasks" : "All Tasks"}
|
{filter === "today" ? "Today's Tasks" : filter === "upcoming" ? "Upcoming Tasks" : "All Tasks"}
|
||||||
</h1>
|
</h1>
|
||||||
|
|||||||
@@ -48,9 +48,8 @@ export const useTaskActions = () => {
|
|||||||
try {
|
try {
|
||||||
me.root.tasks.splice(index, 1)
|
me.root.tasks.splice(index, 1)
|
||||||
|
|
||||||
toast.success("Task deleted", {
|
toast.success("Task completed", {
|
||||||
position: "bottom-right",
|
position: "bottom-right"
|
||||||
description: `${task.title} has been deleted.`
|
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to delete task", error)
|
console.error("Failed to delete task", error)
|
||||||
|
|||||||
@@ -13,8 +13,15 @@ interface DatePickerProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function DatePicker({ date, onDateChange, className }: DatePickerProps) {
|
export function DatePicker({ date, onDateChange, className }: DatePickerProps) {
|
||||||
|
const [open, setOpen] = React.useState(false)
|
||||||
|
|
||||||
|
const selectDate = (selectedDate: Date | undefined) => {
|
||||||
|
onDateChange(selectedDate)
|
||||||
|
setOpen(false) // Закрываем Popover после выбора даты
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Popover>
|
<Popover open={open} onOpenChange={setOpen}>
|
||||||
<PopoverTrigger asChild>
|
<PopoverTrigger asChild>
|
||||||
<Button
|
<Button
|
||||||
variant={"outline"}
|
variant={"outline"}
|
||||||
@@ -25,7 +32,7 @@ export function DatePicker({ date, onDateChange, className }: DatePickerProps) {
|
|||||||
</Button>
|
</Button>
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent className="w-auto p-0" align="start">
|
<PopoverContent className="w-auto p-0" align="start">
|
||||||
<Calendar mode="single" selected={date} onSelect={onDateChange} initialFocus />
|
<Calendar mode="single" selected={date} onSelect={selectDate} initialFocus />
|
||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</Popover>
|
</Popover>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user