diff --git a/web/src/feature/AccountList/index.tsx b/web/src/feature/AccountList/index.tsx new file mode 100644 index 0000000..b4fe9db --- /dev/null +++ b/web/src/feature/AccountList/index.tsx @@ -0,0 +1,61 @@ +import { useDbContext } from "@/context/db/db"; +import { type LocalAccount, useAccountRepo } from "@/repository/account"; +import { User } from "lucide-react"; +import { useEffect, useState, type FC } from "react"; + +const AccountList: FC = () => { + const [accounts, setAccounts] = useState([]); + + const repo = useAccountRepo(); + const { connected } = useDbContext(); + + useEffect(() => { + if (connected) repo.loadAll().then(setAccounts); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [connected]); + + if (!connected) { + return ( +
+
+ + Loading... +
+
+ ); + } + + return accounts.map((account) => ( +
+
+
+ +
+
+
+

{account.label}

+

{account.email}

+
+
+ )); +}; + +export default AccountList; diff --git a/web/src/pages/Index/index.tsx b/web/src/pages/Index/index.tsx index 93e53e1..5c00ee8 100644 --- a/web/src/pages/Index/index.tsx +++ b/web/src/pages/Index/index.tsx @@ -1,22 +1,10 @@ -import { useDbContext } from "@/context/db/db"; -import { useAccountRepo, type LocalAccount } from "@/repository/account"; -import { useEffect, useState, type FC } from "react"; +import { type FC } from "react"; import overlay from "@/assets/overlay.jpg"; import { Card, CardContent } from "@/components/ui/card"; -import { User } from "lucide-react"; +import AccountList from "@/feature/AccountList"; const IndexPage: FC = () => { - const [accounts, setAccounts] = useState([]); - - const repo = useAccountRepo(); - const { connected } = useDbContext(); - - useEffect(() => { - if (connected) repo.loadAll().then(setAccounts); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [connected]); - return (
{ >
-
+
{ {/* */} - {accounts.map((account) => ( -
-
-
- -
-
-
-

{account.label}

-

{account.email}

-
-
- ))} +