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
+1 -1
View File
@@ -45,7 +45,7 @@ export function NoteRepost({
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") {
+3 -5
View File
@@ -5,7 +5,7 @@ import { memo } from "react";
export const MentionUser = memo(function MentionUser({
pubkey,
}: { pubkey: string }) {
const { isLoading, isError, profile } = useProfile(pubkey);
const { isLoading, profile } = useProfile(pubkey);
return (
<button
@@ -14,10 +14,8 @@ export const MentionUser = memo(function MentionUser({
className="break-words text-start text-blue-500 hover:text-blue-600"
>
{isLoading
? "@anon"
: isError
? displayNpub(pubkey, 16)
: `@${profile?.name || profile?.display_name || displayNpub(pubkey, 16)}`}
? displayNpub(pubkey, 16)
: `@${profile?.name || profile?.display_name || displayNpub(pubkey, 16)}`}
</button>
);
});
+9 -8
View File
@@ -2,26 +2,27 @@ import { useProfile } from "@/system";
import type { Metadata } from "@/types";
import { type ReactNode, createContext, useContext } from "react";
const UserContext = createContext<{
interface UserContext {
pubkey: string;
profile: Metadata;
isError: boolean;
profile: Metadata | undefined;
isLoading: boolean;
}>(null);
}
const UserContext = createContext<UserContext | null>(null);
export function UserProvider({
pubkey,
children,
embedProfile,
data,
}: {
pubkey: string;
children: ReactNode;
embedProfile?: string;
data?: string;
}) {
const { isLoading, isError, profile } = useProfile(pubkey, embedProfile);
const { isLoading, profile } = useProfile(pubkey, data);
return (
<UserContext.Provider value={{ pubkey, profile, isError, isLoading }}>
<UserContext.Provider value={{ pubkey, isLoading, profile }}>
{children}
</UserContext.Provider>
);