|
| 1 | +import { createFileRoute } from "@tanstack/react-router" |
| 2 | +import { motion } from "framer-motion" |
| 3 | +import { Check, Circle } from "lucide-react" |
| 4 | +import { useState } from "react" |
| 5 | + |
| 6 | +export const Route = createFileRoute("/_layout/tasks")({ |
| 7 | + component: Tasks, |
| 8 | +}) |
| 9 | + |
| 10 | +const tasks = [ |
| 11 | + { id: 1, title: "Study for 3 hours", completed: true }, |
| 12 | + { id: 2, title: "Create task list", completed: false }, |
| 13 | + { id: 3, title: "Clean bedroom", completed: false }, |
| 14 | + { |
| 15 | + id: 4, |
| 16 | + title: |
| 17 | + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", |
| 18 | + completed: false, |
| 19 | + }, |
| 20 | +] |
| 21 | + |
| 22 | +function Tasks() { |
| 23 | + return ( |
| 24 | + <div className="mx-20 my-10"> |
| 25 | + <div className="flex justify-center"> |
| 26 | + <div className="flex-col shrink w-[800px] min-w-56"> |
| 27 | + <header className="mb-4"> |
| 28 | + <h1 className="text-3xl font-bold">Inbox</h1> |
| 29 | + </header> |
| 30 | + <main className="flex flex-col"> |
| 31 | + {tasks.map((task) => ( |
| 32 | + <Task key={task.id} task={task} /> |
| 33 | + ))} |
| 34 | + </main> |
| 35 | + </div> |
| 36 | + </div> |
| 37 | + </div> |
| 38 | + ) |
| 39 | +} |
| 40 | + |
| 41 | +function Task({ |
| 42 | + task, |
| 43 | +}: { task: { id: number; title: string; completed: boolean } }) { |
| 44 | + const [isCompleted, setIsCompleted] = useState(task.completed) |
| 45 | + return ( |
| 46 | + <div className="flex gap-2 shrink-1 border-b py-3"> |
| 47 | + <motion.button |
| 48 | + whileTap={{ scale: 1.2 }} |
| 49 | + onTap={() => setIsCompleted(!isCompleted)} |
| 50 | + className="flex-none self-start" |
| 51 | + > |
| 52 | + <div className="grid grid-cols-1 grid-rows-1"> |
| 53 | + <Circle className="h-5 w-5 row-start-1 row-end-1 col-start-1 col-end-1" /> |
| 54 | + <div className="flex justify-center items-center row-start-1 row-end-1 col-start-1 col-end-1"> |
| 55 | + {isCompleted && <Check strokeWidth={4.5} className="h-3 w-3" />} |
| 56 | + </div> |
| 57 | + </div> |
| 58 | + </motion.button> |
| 59 | + <p className="text-sm line-clamp-4 text-ellipsis">{task.title}</p> |
| 60 | + </div> |
| 61 | + ) |
| 62 | +} |
0 commit comments