|
1 | 1 | import Image from 'next/image'; |
2 | 2 | import { List } from '@zenstackhq/runtime/types'; |
3 | 3 | import { customAlphabet } from 'nanoid'; |
4 | | -import { LockClosedIcon } from '@heroicons/react/24/outline'; |
| 4 | +import { LockClosedIcon, TrashIcon } from '@heroicons/react/24/outline'; |
5 | 5 | import { User } from 'next-auth'; |
6 | 6 | import Avatar from './Avatar'; |
7 | 7 | import Link from 'next/link'; |
8 | 8 | import { useRouter } from 'next/router'; |
| 9 | +import { useList } from '@zenstackhq/runtime/hooks'; |
| 10 | +import TimeInfo from './TimeInfo'; |
9 | 11 |
|
10 | 12 | type Props = { |
11 | 13 | value: List & { owner: User }; |
| 14 | + deleted?: (value: List) => void; |
12 | 15 | }; |
13 | 16 |
|
14 | | -export default function TodoList({ value }: Props) { |
| 17 | +export default function TodoList({ value, deleted }: Props) { |
15 | 18 | const router = useRouter(); |
| 19 | + |
| 20 | + const { del } = useList(); |
| 21 | + |
| 22 | + const deleteList = async () => { |
| 23 | + if (confirm('Are you sure to delete this list?')) { |
| 24 | + await del(value.id); |
| 25 | + if (deleted) { |
| 26 | + deleted(value); |
| 27 | + } |
| 28 | + } |
| 29 | + }; |
| 30 | + |
16 | 31 | return ( |
17 | | - <Link href={`${router.asPath}/${value.id}`}> |
18 | | - <a className="card w-80 bg-base-100 shadow-xl cursor-pointer hover:bg-gray-50"> |
19 | | - <figure> |
20 | | - <Image |
21 | | - src={`https://picsum.photos/300/200?r=${customAlphabet( |
22 | | - '0123456789' |
23 | | - )(4)}`} |
24 | | - width={320} |
25 | | - height={200} |
26 | | - alt="Cover" |
27 | | - /> |
28 | | - </figure> |
29 | | - <div className="card-body"> |
30 | | - <h2 className="card-title line-clamp-1"> |
31 | | - {value.title || 'Missing Title'} |
32 | | - </h2> |
33 | | - <div className="card-actions justify-end"> |
| 32 | + <div className="card w-80 bg-base-100 shadow-xl cursor-pointer hover:bg-gray-50"> |
| 33 | + <Link href={`${router.asPath}/${value.id}`}> |
| 34 | + <a> |
| 35 | + <figure> |
| 36 | + <Image |
| 37 | + src={`https://picsum.photos/300/200?r=${customAlphabet( |
| 38 | + '0123456789' |
| 39 | + )(4)}`} |
| 40 | + width={320} |
| 41 | + height={200} |
| 42 | + alt="Cover" |
| 43 | + /> |
| 44 | + </figure> |
| 45 | + </a> |
| 46 | + </Link> |
| 47 | + <div className="card-body"> |
| 48 | + <Link href={`${router.asPath}/${value.id}`}> |
| 49 | + <a> |
| 50 | + <h2 className="card-title line-clamp-1"> |
| 51 | + {value.title || 'Missing Title'} |
| 52 | + </h2> |
| 53 | + </a> |
| 54 | + </Link> |
| 55 | + <div className="card-actions flex w-full justify-between"> |
| 56 | + <div> |
| 57 | + <TimeInfo value={value} /> |
| 58 | + </div> |
| 59 | + <div className="flex space-x-2"> |
34 | 60 | <Avatar user={value.owner} size={18} /> |
35 | 61 | {value.private && ( |
36 | 62 | <div className="tooltip" data-tip="Private"> |
37 | 63 | <LockClosedIcon className="w-4 h-4 text-gray-500" /> |
38 | 64 | </div> |
39 | 65 | )} |
| 66 | + <TrashIcon |
| 67 | + className="w-4 h-4 text-gray-500 cursor-pointer" |
| 68 | + onClick={() => { |
| 69 | + deleteList(); |
| 70 | + }} |
| 71 | + /> |
40 | 72 | </div> |
41 | 73 | </div> |
42 | | - </a> |
43 | | - </Link> |
| 74 | + </div> |
| 75 | + </div> |
44 | 76 | ); |
45 | 77 | } |
0 commit comments