|
1 | | -import { Either } from "effect"; |
2 | 1 | import { XIcon } from "lucide-react"; |
3 | 2 | import { Button } from "react-aria-components"; |
4 | 3 | import { useDeleteLog } from "../lib/hooks/use-delete-log"; |
5 | 4 | import { useGetLogByDate } from "../lib/hooks/use-get-log-by-date"; |
6 | 5 | import { textColor } from "../styles"; |
| 6 | +import Spinner from "./Spinner"; |
7 | 7 |
|
8 | 8 | export default function DateLogs({ date }: { date: string }) { |
9 | 9 | const [_, action, pending] = useDeleteLog(); |
10 | | - const logByDate = useGetLogByDate(date); |
11 | | - return Either.isRight(logByDate) ? ( |
| 10 | + const { error, data, loading } = useGetLogByDate(date); |
| 11 | + |
| 12 | + if (loading) { |
| 13 | + return <Spinner />; |
| 14 | + } else if (error) { |
| 15 | + return <div>{error.message}</div>; |
| 16 | + } |
| 17 | + |
| 18 | + return ( |
12 | 19 | <div className="flex flex-wrap items-center justify-center gap-2"> |
13 | | - {logByDate.right.map((log) => ( |
14 | | - <div |
15 | | - key={log.logId} |
16 | | - className={textColor({ |
17 | | - theme: log.color, |
18 | | - className: |
19 | | - "border rounded-md inline-flex items-center gap-x-2 px-2 py-1", |
20 | | - })} |
21 | | - > |
22 | | - <form |
23 | | - action={action} |
24 | | - className="inline-flex items-center justify-center" |
| 20 | + {data.length === 0 ? ( |
| 21 | + <span className="text-sm text-fuchsia/50">No activity</span> |
| 22 | + ) : ( |
| 23 | + data.map((log) => ( |
| 24 | + <div |
| 25 | + key={log.logId} |
| 26 | + className={textColor({ |
| 27 | + theme: log.color, |
| 28 | + className: |
| 29 | + "border rounded-md inline-flex items-center gap-x-2 px-2 py-1", |
| 30 | + })} |
25 | 31 | > |
26 | | - <input type="hidden" value={log.logId} name="log-id" /> |
27 | | - <Button |
28 | | - type="submit" |
29 | | - isDisabled={pending} |
30 | | - className="text-sm hover:cursor-pointer" |
| 32 | + <form |
| 33 | + action={action} |
| 34 | + className="inline-flex items-center justify-center" |
31 | 35 | > |
32 | | - <XIcon |
33 | | - size={16} |
34 | | - className="hover:scale-125 transition-transform duration-150" |
35 | | - /> |
36 | | - </Button> |
37 | | - </form> |
38 | | - <span>{log.name}</span> |
39 | | - </div> |
40 | | - ))} |
| 36 | + <input type="hidden" value={log.logId} name="log-id" /> |
| 37 | + <Button |
| 38 | + type="submit" |
| 39 | + isDisabled={pending} |
| 40 | + className="text-sm hover:cursor-pointer" |
| 41 | + > |
| 42 | + <XIcon |
| 43 | + size={16} |
| 44 | + className="hover:scale-125 transition-transform duration-150" |
| 45 | + /> |
| 46 | + </Button> |
| 47 | + </form> |
| 48 | + <span>{log.name}</span> |
| 49 | + </div> |
| 50 | + )) |
| 51 | + )} |
41 | 52 | </div> |
42 | | - ) : ( |
43 | | - <div>{logByDate.left._tag}</div> |
44 | 53 | ); |
45 | 54 | } |
0 commit comments