This commit is contained in:
Ren Amamiya
2023-08-06 15:11:58 +07:00
parent 71338b3b07
commit 02ff9e3b68
34 changed files with 321 additions and 320 deletions

View File

@@ -20,7 +20,7 @@ export function useAccount() {
staleTime: Infinity,
refetchOnMount: false,
refetchOnWindowFocus: false,
refetchOnReconnect: true,
refetchOnReconnect: false,
}
);

View File

@@ -1,33 +0,0 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { createBlock, removeBlock } from '@libs/storage';
interface BlockData {
kind: number;
title: string;
content: string;
}
export function useBlock() {
const queryClient = useQueryClient();
const add = useMutation({
mutationFn: (data: BlockData) => {
return createBlock(data.kind, data.title, data.content);
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['blocks'] });
},
});
const remove = useMutation({
mutationFn: (id: string) => {
return removeBlock(id);
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['blocks'] });
},
});
return { add, remove };
}

View File

@@ -17,6 +17,7 @@ export function useEvent(id: string, fallback?: string) {
} else {
if (fallback) {
const embed: LumeEvent = JSON.parse(fallback);
if (embed.kind === 1) embed['content'] = parser(embed);
embed['event_id'] = embed.id;
await createNote(
embed.id,
@@ -28,22 +29,18 @@ export function useEvent(id: string, fallback?: string) {
);
return embed;
} else {
const event = await ndk.fetchEvent(id);
const event = (await ndk.fetchEvent(id)) as unknown as LumeEvent;
if (event) {
await createNote(
event.id,
event.pubkey,
event.kind,
event.tags,
event.content,
event.content as unknown as string,
event.created_at
);
event['event_id'] = event.id;
if (event.kind === 1) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
event['content'] = parser(event);
}
if (event.kind === 1) event['content'] = parser(event);
return event as unknown as LumeEvent;
} else {
throw new Error('Event not found');

View File

@@ -47,7 +47,7 @@ export function useNostr() {
});
});
network = [...network.values()] as string[];
network = [...lruNetwork.values()] as string[];
} else {
network = account.network;
}
@@ -69,7 +69,7 @@ export function useNostr() {
if (network.length > 0) {
let since: number;
if (totalNotes === 0 || lastLogin === 0) {
since = nHoursAgo(6);
since = nHoursAgo(24);
} else {
since = lastLogin;
}

View File

@@ -32,8 +32,8 @@ export interface Profile extends NDKUserProfile {
}
export interface Block {
id: string;
account_id: number;
id?: string;
account_id?: number;
kind: number;
title: string;
content: string;