-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTodoList.tsx
65 lines (59 loc) · 2.43 KB
/
TodoList.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use client';
import { LockClosedIcon, TrashIcon } from '@heroicons/react/24/outline';
import { List } from '@prisma/client';
import { useCheckList, useDeleteList } from 'lib/hooks';
import { customAlphabet } from 'nanoid';
import { User } from 'next-auth';
import Image from 'next/image';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import Avatar from './Avatar';
import TimeInfo from './TimeInfo';
type Props = {
value: List & { owner: User };
};
export default function TodoList({ value }: Props) {
const path = usePathname();
// check if the current user can delete the list (based on its owner)
const { data: canDelete } = useCheckList({ operation: 'delete', where: { ownerId: value.ownerId } });
const { mutate: deleteList } = useDeleteList();
const onDelete = () => {
if (confirm('Are you sure to delete this list?')) {
deleteList({ where: { id: value.id } });
}
};
return (
<div className="card w-80 bg-base-100 shadow-xl cursor-pointer hover:bg-gray-50">
<Link href={`${path}/${value.id}`}>
<figure>
<Image
src={`https://picsum.photos/300/200?r=${customAlphabet('0123456789')(4)}`}
className="rounded-t-2xl"
width={320}
height={200}
alt="Cover"
/>
</figure>
</Link>
<div className="card-body">
<Link href={`${path}/${value.id}`}>
<h2 className="card-title line-clamp-1">{value.title || 'Missing Title'}</h2>
</Link>
<div className="card-actions flex w-full justify-between">
<div>
<TimeInfo value={value} />
</div>
<div className="flex space-x-2">
<Avatar user={value.owner} size={18} />
{value.private && (
<div className="tooltip" data-tip="Private">
<LockClosedIcon className="w-4 h-4 text-gray-500" />
</div>
)}
{canDelete && <TrashIcon className="w-4 h-4 text-gray-500 cursor-pointer" onClick={onDelete} />}
</div>
</div>
</div>
</div>
);
}