fix: overload

This commit is contained in:
2024-10-31 10:25:00 +07:00
parent 9b02ab5842
commit 043cabfd4e
4 changed files with 105 additions and 39 deletions

View File

@@ -32,10 +32,15 @@ export function Images({ urls }: { urls: string[] }) {
return `https://wsrv.nl?url=${url}&ll&af&default=1&n=-1`;
});
} else {
newUrls = urls.map(
(url) =>
`https://wsrv.nl?url=${url}&w=480&h=640&ll&af&default=1&n=-1`,
);
newUrls = urls.map((url) => {
if (url.includes("_next/")) {
return url;
}
if (url.includes("bsky.network")) {
return url;
}
return `https://wsrv.nl?url=${url}&ll&af&default=1&n=-1`;
});
}
return newUrls;

View File

@@ -42,11 +42,16 @@ function Screen() {
const unlisten = getCurrentWindow().listen<string>(
"metadata",
async (data) => {
const payload = data.payload;
const event: NostrEvent = JSON.parse(payload);
const event: NostrEvent = JSON.parse(data.payload);
const metadata: Metadata = JSON.parse(event.content);
// Update query cache
queryClient.setQueryData(["profile", event.pubkey], () => metadata);
// Reset query cache
await queryClient.invalidateQueries({
queryKey: ["profile", event.pubkey],
});
},
);

View File

@@ -29,25 +29,26 @@ export function useProfile(pubkey: string, data?: string) {
const { isLoading, data: profile } = useQuery({
queryKey: ["profile", hex],
queryFn: async () => {
if (data) {
if (data?.length) {
const metadata: Metadata = JSON.parse(data);
return metadata;
}
const query = await commands.getProfile(hex);
const res = await commands.getProfile(hex);
if (query.status === "ok") {
const metadata: Metadata = JSON.parse(query.data);
if (res.status === "ok") {
const metadata: Metadata = JSON.parse(res.data);
return metadata;
} else {
await getCurrentWindow().emit("request_metadata", { id: hex });
return {};
throw new Error(res.error);
}
},
refetchOnMount: false,
refetchOnWindowFocus: false,
refetchOnReconnect: false,
enabled: !!hex,
retry: false,
});
return { isLoading, profile };