feat: handle account selection
This commit is contained in:
@ -1,7 +1,8 @@
|
|||||||
import { useDbContext } from "@/context/db";
|
import { useDbContext } from "@/context/db";
|
||||||
|
import { useOAuthContext } from "@/context/oauth";
|
||||||
import { type LocalAccount, useAccountRepo } from "@/repository/account";
|
import { type LocalAccount, useAccountRepo } from "@/repository/account";
|
||||||
import { CirclePlus, User } from "lucide-react";
|
import { CirclePlus, User } from "lucide-react";
|
||||||
import { useEffect, useState, type FC } from "react";
|
import { useCallback, useEffect, useState, type FC } from "react";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
|
|
||||||
const AccountList: FC = () => {
|
const AccountList: FC = () => {
|
||||||
@ -10,6 +11,15 @@ const AccountList: FC = () => {
|
|||||||
const repo = useAccountRepo();
|
const repo = useAccountRepo();
|
||||||
const { connected } = useDbContext();
|
const { connected } = useDbContext();
|
||||||
|
|
||||||
|
const oauth = useOAuthContext();
|
||||||
|
|
||||||
|
const handleAccountSelect = useCallback(
|
||||||
|
(account: LocalAccount) => {
|
||||||
|
oauth.selectSession(account.access);
|
||||||
|
},
|
||||||
|
[oauth]
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (connected) repo.loadAll().then(setAccounts);
|
if (connected) repo.loadAll().then(setAccounts);
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
@ -46,6 +56,7 @@ const AccountList: FC = () => {
|
|||||||
{accounts.map((account) => (
|
{accounts.map((account) => (
|
||||||
<div
|
<div
|
||||||
key={account.accountId}
|
key={account.accountId}
|
||||||
|
onClick={() => handleAccountSelect(account)}
|
||||||
className="flex flex-row items-center p-4 border-gray-200 dark:border-gray-700/65 border-b border-r-0 border-l-0 select-none cursor-pointer hover:bg-gray-50/50 dark:hover:bg-gray-800/10 transition-colors mb-0"
|
className="flex flex-row items-center p-4 border-gray-200 dark:border-gray-700/65 border-b border-r-0 border-l-0 select-none cursor-pointer hover:bg-gray-50/50 dark:hover:bg-gray-800/10 transition-colors mb-0"
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
|
Reference in New Issue
Block a user