mirror of
https://github.com/linsa-io/linsa.git
synced 2026-01-12 12:20:23 +01:00
fixed jazz things
This commit is contained in:
@@ -1,25 +1,30 @@
|
|||||||
"use client"
|
"use client"
|
||||||
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 { Task } from "@/lib/schema/tasks"
|
import { ListOfTasks, Task } from "@/lib/schema/tasks"
|
||||||
import { Input } from "@/components/ui/input"
|
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"
|
||||||
|
|
||||||
interface TaskFormProps {
|
interface TaskFormProps {}
|
||||||
onAddTask: (task: Task) => void
|
|
||||||
}
|
|
||||||
|
|
||||||
export const TaskForm: React.FC<TaskFormProps> = ({ onAddTask }) => {
|
export const TaskForm: React.FC<TaskFormProps> = ({}) => {
|
||||||
const [title, setTitle] = useState("")
|
const [title, setTitle] = useState("")
|
||||||
const [inputVisible, setInputVisible] = useState(false)
|
const [inputVisible, setInputVisible] = useState(false)
|
||||||
const { me } = useAccount()
|
const { me } = useAccount({ root: {} })
|
||||||
const inputRef = useRef<HTMLInputElement>(null)
|
const inputRef = useRef<HTMLInputElement>(null)
|
||||||
|
|
||||||
const handleSubmit = (e: React.FormEvent) => {
|
const handleSubmit = (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
if (title.trim() && me) {
|
console.log(title.trim())
|
||||||
|
console.log(me, "me")
|
||||||
|
if (title.trim()) {
|
||||||
|
if (me?.root?.tasks === undefined) {
|
||||||
|
if (!me) return
|
||||||
|
me.root.tasks = ListOfTasks.create([], { owner: me })
|
||||||
|
}
|
||||||
|
|
||||||
const newTask = Task.create(
|
const newTask = Task.create(
|
||||||
{
|
{
|
||||||
title,
|
title,
|
||||||
@@ -30,7 +35,7 @@ export const TaskForm: React.FC<TaskFormProps> = ({ onAddTask }) => {
|
|||||||
},
|
},
|
||||||
{ owner: me._owner }
|
{ owner: me._owner }
|
||||||
)
|
)
|
||||||
onAddTask(newTask)
|
me.root.tasks?.push(newTask)
|
||||||
resetForm()
|
resetForm()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,16 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import { Task } from "@/lib/schema/tasks"
|
import { ListOfTasks, Task } from "@/lib/schema/tasks"
|
||||||
import { TaskItem } from "./TaskItem"
|
import { TaskItem } from "./TaskItem"
|
||||||
|
|
||||||
interface TaskListProps {
|
interface TaskListProps {
|
||||||
tasks: Task[]
|
tasks?: ListOfTasks
|
||||||
onUpdateTask: (taskId: string, updates: Partial<Task>) => void
|
onUpdateTask: (taskId: string, updates: Partial<Task>) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
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="space-y-2">
|
||||||
{tasks.map(task => (
|
{tasks?.map(task => task?.id && <TaskItem key={task.id} task={task} onUpdateTask={onUpdateTask} />)}
|
||||||
<TaskItem key={task.id} task={task} onUpdateTask={onUpdateTask} />
|
|
||||||
))}
|
|
||||||
</ul>
|
</ul>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,8 @@ import { TaskForm } from "./TaskForm"
|
|||||||
|
|
||||||
export const TaskRoute: React.FC = () => {
|
export const TaskRoute: React.FC = () => {
|
||||||
const { me } = useAccount({ root: { tasks: [] } })
|
const { me } = useAccount({ root: { tasks: [] } })
|
||||||
const tasks = me?.root?.tasks || []
|
const tasks = me?.root.tasks
|
||||||
|
console.log(tasks, "tasks here")
|
||||||
const addTask = (newTask: Task) => {
|
|
||||||
if (me?.root?.tasks) {
|
|
||||||
me.root.tasks.push(newTask)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const updateTask = (taskId: string, updates: Partial<Task>) => {
|
const updateTask = (taskId: string, updates: Partial<Task>) => {
|
||||||
if (me?.root?.tasks) {
|
if (me?.root?.tasks) {
|
||||||
@@ -27,8 +22,8 @@ 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>
|
<h1 className="text-2xl font-bold">Tasks</h1>
|
||||||
<TaskForm onAddTask={addTask} />
|
<TaskForm />
|
||||||
<TaskList tasks={tasks as Task[]} updateTask={updateTask} />
|
<TaskList tasks={tasks} onUpdateTask={updateTask} />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ export class Task extends CoMap {
|
|||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ListOfTasks extends CoList.Of(co.ref(Task)) {}
|
export class ListOfTasks extends CoList.Of(co.ref(Task)) {}
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ const ROUTE_PATTERNS = {
|
|||||||
"/search(.*)",
|
"/search(.*)",
|
||||||
"/settings(.*)",
|
"/settings(.*)",
|
||||||
"/tauri(.*)",
|
"/tauri(.*)",
|
||||||
"/onboarding(.*)"
|
"/onboarding(.*)",
|
||||||
|
"/tasks(.*)"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user