feat: rework multi account

This commit is contained in:
reya
2024-10-24 15:50:45 +07:00
parent 469296790e
commit 055d73c829
31 changed files with 979 additions and 1207 deletions
+11 -26
View File
@@ -1,14 +1,13 @@
import { commands } from "@/commands.gen";
import { appSettings, cn, displayNpub } from "@/commons";
import { RepostIcon, Spinner } from "@/components";
import { LumeWindow } from "@/system";
import type { Metadata } from "@/types";
import * as Tooltip from "@radix-ui/react-tooltip";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { useStore } from "@tanstack/react-store";
import { Menu, MenuItem } from "@tauri-apps/api/menu";
import type { Window } from "@tauri-apps/api/window";
import { useCallback, useEffect, useState, useTransition } from "react";
import { message } from "@tauri-apps/plugin-dialog";
import { useCallback, useTransition } from "react";
import { useNoteContext } from "../provider";
export function NoteRepost({
@@ -38,13 +37,12 @@ export function NoteRepost({
});
const [isPending, startTransition] = useTransition();
const [popup, setPopup] = useState<Window>(null);
const showContextMenu = useCallback(async (e: React.MouseEvent) => {
e.preventDefault();
const accounts = await commands.getAccounts();
const list = [];
const list: Promise<MenuItem>[] = [];
for (const account of accounts) {
const res = await commands.getProfile(account);
@@ -52,7 +50,7 @@ export function NoteRepost({
if (res.status === "ok") {
const profile: Metadata = JSON.parse(res.data);
name = profile.display_name ?? profile.name;
name = profile.display_name ?? profile.name ?? "unknown";
}
list.push(
@@ -102,14 +100,14 @@ export function NoteRepost({
if (signer.status === "ok") {
if (!signer.data) {
const newPopup = await LumeWindow.openPopup(
`/set-signer/${account}`,
undefined,
false,
);
if (!signer.data) {
const res = await commands.setSigner(account);
setPopup(newPopup);
return;
if (res.status === "error") {
await message(res.error, { kind: "error" });
return;
}
}
}
repost.mutate();
@@ -122,19 +120,6 @@ export function NoteRepost({
});
};
useEffect(() => {
if (!visible) return;
if (!popup) return;
const unlisten = popup.listen("signer-updated", async () => {
repost.mutate();
});
return () => {
unlisten.then((f) => f());
};
}, [popup]);
if (!visible) return null;
return (