-
-
+
+
+
+
+
+
);
diff --git a/src/app/space/components/blocks/thread.tsx b/src/app/space/components/blocks/thread.tsx
index 56bfeec6..e0420425 100644
--- a/src/app/space/components/blocks/thread.tsx
+++ b/src/app/space/components/blocks/thread.tsx
@@ -21,7 +21,9 @@ export function ThreadBlock({ params }: { params: any }) {
);
const block = useMutation({
- mutationFn: (id: string) => removeBlock(id),
+ mutationFn: (id: string) => {
+ return removeBlock(id);
+ },
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["blocks"] });
},
diff --git a/src/libs/openGraph.tsx b/src/libs/openGraph.tsx
index 15174b58..83c9b3f4 100644
--- a/src/libs/openGraph.tsx
+++ b/src/libs/openGraph.tsx
@@ -345,7 +345,7 @@ export async function getLinkPreview(text: string) {
const fetchUrl = text;
const options: FetchOptions = {
method: "GET",
- timeout: 30,
+ timeout: 5,
responseType: ResponseType.Text,
};
diff --git a/src/libs/storage.tsx b/src/libs/storage.tsx
index 90563eb7..2019283b 100644
--- a/src/libs/storage.tsx
+++ b/src/libs/storage.tsx
@@ -45,10 +45,19 @@ export async function createAccount(
is_active?: number,
) {
const db = await connect();
- return await db.execute(
+ const res = await db.execute(
"INSERT OR IGNORE INTO accounts (npub, pubkey, privkey, follows, is_active) VALUES (?, ?, ?, ?, ?);",
[npub, pubkey, privkey, follows || "", is_active || 0],
);
+ if (res) {
+ await createBlock(
+ 0,
+ "Preserve your freedom",
+ "https://void.cat/d/949GNg7ZjSLHm2eTR3jZqv",
+ );
+ }
+ const getAccount = await getActiveAccount();
+ return getAccount;
}
// update account
@@ -408,7 +417,7 @@ export async function getBlocks() {
const db = await connect();
const activeAccount = await getActiveAccount();
const result: any = await db.select(
- `SELECT * FROM blocks WHERE account_id <= "${activeAccount.id}";`,
+ `SELECT * FROM blocks WHERE account_id = "${activeAccount.id}" ORDER BY created_at DESC;`,
);
return result;
}
diff --git a/src/main.tsx b/src/main.tsx
index 30478b93..1ec94619 100644
--- a/src/main.tsx
+++ b/src/main.tsx
@@ -1,6 +1,23 @@
import App from "./app";
+import { RelayProvider } from "@shared/relayProvider";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { createRoot } from "react-dom/client";
+const queryClient = new QueryClient({
+ defaultOptions: {
+ queries: {
+ cacheTime: 1000 * 60 * 60 * 24,
+ },
+ },
+});
+
const container = document.getElementById("root");
const root = createRoot(container);
-root.render(
);
+
+root.render(
+
+
+
+
+ ,
+);
diff --git a/src/shared/notes/mentions/note.tsx b/src/shared/notes/mentions/note.tsx
index c6cdb8d6..2b12ad61 100644
--- a/src/shared/notes/mentions/note.tsx
+++ b/src/shared/notes/mentions/note.tsx
@@ -16,7 +16,9 @@ export const MentionNote = memo(function MentionNote({ id }: { id: string }) {
const queryClient = useQueryClient();
const block = useMutation({
- mutationFn: (data: any) => createBlock(data.kind, data.title, data.content),
+ mutationFn: (data: any) => {
+ return createBlock(data.kind, data.title, data.content);
+ },
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["blocks"] });
},
diff --git a/src/shared/notes/metadata/reply.tsx b/src/shared/notes/metadata/reply.tsx
index 2587ff61..3df2437d 100644
--- a/src/shared/notes/metadata/reply.tsx
+++ b/src/shared/notes/metadata/reply.tsx
@@ -10,7 +10,9 @@ export function NoteReply({
const queryClient = useQueryClient();
const block = useMutation({
- mutationFn: (data: any) => createBlock(data.kind, data.title, data.content),
+ mutationFn: (data: any) => {
+ return createBlock(data.kind, data.title, data.content);
+ },
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["blocks"] });
},
diff --git a/src/shared/notes/note.tsx b/src/shared/notes/note.tsx
index 50fc244b..c656d857 100644
--- a/src/shared/notes/note.tsx
+++ b/src/shared/notes/note.tsx
@@ -71,7 +71,7 @@ export function Note({ event, block }: Note) {
time={event.created_at}
repost={isRepost}
/>
-
+
{renderContent}
{!isRepost && (
@@ -22,10 +19,10 @@ export function NoteParent({
) : (
<>
-
- {kind1 &&
}
- {kind1063 &&
}
- {!kind1 && !kind1063 && (
+
+ {data.kind === 1 &&
}
+ {data.kind === 1063 &&
}
+ {data.kind !== 1 && data.kind !== 1063 && (
diff --git a/src/shared/notes/preview/link.tsx b/src/shared/notes/preview/link.tsx
index 3c4658a3..7efaa38e 100644
--- a/src/shared/notes/preview/link.tsx
+++ b/src/shared/notes/preview/link.tsx
@@ -3,11 +3,11 @@ import { useOpenGraph } from "@utils/hooks/useOpenGraph";
export function LinkPreview({ urls }: { urls: string[] }) {
const domain = new URL(urls[0]);
- const { status, data, isFetching } = useOpenGraph(urls[0]);
+ const { status, data, error } = useOpenGraph(urls[0]);
return (
- {isFetching || status === "loading" ? (
+ {status === "loading" ? (
@@ -25,25 +25,35 @@ export function LinkPreview({ urls }: { urls: string[] }) {
target="_blank"
rel="noreferrer"
>
-
-
-
- {data.title}
-
- {data.description && (
+ {error ? (
+
- {data.description}
+ Can't fetch open graph, click to open webpage
- )}
-
- {domain.hostname}
-
-
+
+ ) : (
+ <>
+
+
+
+ {data.title}
+
+ {data.description && (
+
+ {data.description}
+
+ )}
+
+ {domain.hostname}
+
+
+ >
+ )}
)}
diff --git a/src/shared/notes/repost.tsx b/src/shared/notes/repost.tsx
index e60b7981..ce9bab90 100644
--- a/src/shared/notes/repost.tsx
+++ b/src/shared/notes/repost.tsx
@@ -14,9 +14,6 @@ export function Repost({
const repostID = getRepostID(event.tags);
const { status, data, isFetching } = useEvent(repostID);
- const kind1 = data?.kind === 1 ? data.content : null;
- const kind1063 = data?.kind === 1063 ? data.tags : null;
-
return (
{isFetching || status === "loading" ? (
@@ -24,10 +21,10 @@ export function Repost({
) : (
<>
-
- {kind1 &&
}
- {kind1063 &&
}
- {!kind1 && !kind1063 && (
+
+ {data.kind === 1 &&
}
+ {data.kind === 1063 &&
}
+ {data.kind !== 1 && data.kind !== 1063 && (
diff --git a/src/shared/relayProvider.tsx b/src/shared/relayProvider.tsx
index 7b635eb1..b137fa64 100644
--- a/src/shared/relayProvider.tsx
+++ b/src/shared/relayProvider.tsx
@@ -5,8 +5,7 @@ import { createContext } from "react";
export const RelayContext = createContext(null);
-const ndk = new NDK({ explicitRelayUrls: FULL_RELAYS });
-await ndk.connect();
+const ndk = await initNDK(FULL_RELAYS);
export function RelayProvider({ children }: { children: React.ReactNode }) {
return {children};
diff --git a/src/utils/hooks/useAccount.tsx b/src/utils/hooks/useAccount.tsx
index 00dda840..06027f6a 100644
--- a/src/utils/hooks/useAccount.tsx
+++ b/src/utils/hooks/useAccount.tsx
@@ -2,10 +2,16 @@ import { getActiveAccount } from "@libs/storage";
import { useQuery } from "@tanstack/react-query";
export function useAccount() {
- const { status, data: account } = useQuery(["currentAccount"], async () => {
- const res = await getActiveAccount();
- return res;
- });
+ const { status, data: account } = useQuery(
+ ["currentAccount"],
+ async () => await getActiveAccount(),
+ {
+ staleTime: Infinity,
+ refetchOnMount: true,
+ refetchOnWindowFocus: false,
+ refetchOnReconnect: true,
+ },
+ );
return { status, account };
}
diff --git a/src/utils/hooks/useOpenGraph.tsx b/src/utils/hooks/useOpenGraph.tsx
index 0663e718..aa493397 100644
--- a/src/utils/hooks/useOpenGraph.tsx
+++ b/src/utils/hooks/useOpenGraph.tsx
@@ -5,7 +5,11 @@ export function useOpenGraph(url: string) {
const { status, data, error, isFetching } = useQuery(
["preview", url],
async () => {
- return await getLinkPreview(url);
+ const res = await getLinkPreview(url);
+ if (!res) {
+ throw new Error("Can' fetch");
+ }
+ return res;
},
{
refetchOnWindowFocus: false,