page.jsx 1.24 KB
Newer Older
wyuer's avatar
wyuer committed
1
"use client";
wuhao's avatar
wuhao committed
2 3

import React from "react";
wuhao's avatar
wuhao committed
4
import AddFolder from "@/components/AddFolder";
wyuer's avatar
wyuer committed
5
import AddCollection from "@/components/AddCollection";
wuhao's avatar
wuhao committed
6
import Cards from "@/components/Cards";
wyuer's avatar
wyuer committed
7
import Collections from "@/components/Collections";
wuhao's avatar
wuhao committed
8 9
import { useRequest } from "ahooks";
import { getFetch } from "@/lib/doFetch";
wuhao's avatar
wuhao committed
10
import { Image } from "@nextui-org/react";
wuhao's avatar
wuhao committed
11 12

export default function Home(props) {
wuhao's avatar
wuhao committed
13 14 15 16 17
  const { data, refreshAsync, refresh } = useRequest(async () => {
    const res = await getFetch({ url: "/api/folder", params: {} });
    return res?.data ?? [];
  });

wyuer's avatar
wyuer committed
18 19 20 21
  const collection = useRequest(async () => {
    const res = await getFetch({ url: "/api/collection", params: {} });
    return res?.data ?? [];
  });
wuhao's avatar
wuhao committed
22 23
  return (
    <div>
wuhao's avatar
wuhao committed
24 25
      <div className="flex gap-4">
        <AddFolder refresh={refreshAsync} />
wyuer's avatar
wyuer committed
26
        <AddCollection refresh={collection?.refreshAsync} />
wuhao's avatar
wuhao committed
27
      </div>
wyuer's avatar
wyuer committed
28
      <div className="flex gap-4">
wuhao's avatar
wuhao committed
29
      <Cards list={data ?? []} />
wyuer's avatar
wyuer committed
30
      <Collections list={collection?.data ?? []} />
wuhao's avatar
wuhao committed
31 32 33 34 35 36 37 38 39
      {data?.length === 0 &&collection?.data?.length ===0 &&  (
        <Image
          alt="empty"
          isZoomed
          className="object-cover"
          src="/empty.png"
          width={240}
        />
      )}
wyuer's avatar
wyuer committed
40
      </div>
wuhao's avatar
wuhao committed
41 42 43
    </div>
  );
}