feat: group metadata query

This commit is contained in:
reya
2024-10-29 15:05:03 +07:00
parent d87371aec4
commit 11dcef4e87
23 changed files with 323 additions and 169 deletions
+11 -12
View File
@@ -1,10 +1,9 @@
import type { RichEvent } from "@/commands.gen";
import { Spinner } from "@/components";
import type { Metadata, NostrEvent } from "@/types";
import type { QueryClient } from "@tanstack/react-query";
import { Outlet, createRootRouteWithContext } from "@tanstack/react-router";
import { listen } from "@tauri-apps/api/event";
import { getCurrentWindow } from "@tauri-apps/api/window";
import type { OsType } from "@tauri-apps/plugin-os";
import { nip19 } from "nostr-tools";
import { useEffect } from "react";
interface RouterContext {
@@ -22,16 +21,16 @@ function Screen() {
const { queryClient } = Route.useRouteContext();
useEffect(() => {
const unlisten = listen<RichEvent>("event", async (data) => {
const event = JSON.parse(data.payload.raw);
const unlisten = getCurrentWindow().listen<string>(
"metadata",
async (data) => {
const payload = data.payload;
const event: NostrEvent = JSON.parse(payload);
const metadata: Metadata = JSON.parse(event.content);
if (event.kind === 0) {
const npub = nip19.npubEncode(event.pubkey);
await queryClient.invalidateQueries({
queryKey: ["profile", npub, event.pubkey],
});
}
});
queryClient.setQueryData(["profile", event.pubkey], () => metadata);
},
);
return () => {
unlisten.then((f) => f());
+1 -1
View File
@@ -199,7 +199,7 @@ function OpenLaunchpad() {
const list: Promise<MenuItem>[] = [];
for (const account of accounts) {
const res = await commands.getProfile(account, true);
const res = await commands.getProfile(account);
let name = "unknown";
if (res.status === "ok") {
+1 -1
View File
@@ -104,7 +104,7 @@ function Screen() {
const list: Promise<MenuItem>[] = [];
for (const account of accounts) {
const res = await commands.getProfile(account, true);
const res = await commands.getProfile(account);
let name = "unknown";
if (res.status === "ok") {
+1 -1
View File
@@ -3,7 +3,7 @@ import { createFileRoute } from "@tanstack/react-router";
export const Route = createFileRoute("/settings/$id/profile")({
beforeLoad: async ({ params }) => {
const res = await commands.getProfile(params.id, true);
const res = await commands.getProfile(params.id);
if (res.status === "ok") {
const profile: Profile = JSON.parse(res.data);
+1 -1
View File
@@ -31,7 +31,7 @@ function Screen() {
const list: Promise<MenuItem>[] = [];
for (const account of accounts) {
const res = await commands.getProfile(account, true);
const res = await commands.getProfile(account);
let name = "unknown";
if (res.status === "ok") {