fixed nextjs ssg build issue

This commit is contained in:
Ren Amamiya
2023-04-21 16:41:04 +07:00
parent 9fdf2eb81c
commit b64ed8b587
18 changed files with 107 additions and 106 deletions
+3 -3
View File
@@ -22,13 +22,13 @@ export const NoteBase = memo(function NoteBase({ event }: { event: any }) {
const openUserPage = (e) => {
e.stopPropagation();
router.push(`/nostr/users/${event.pubkey}`);
router.push(`/nostr/user?pubkey=${event.pubkey}`);
};
const openThread = (e) => {
const selection = window.getSelection();
if (selection.toString().length === 0) {
router.push(`/newsfeed/${event.parent_id}`);
router.push(`/nostr/newsfeed/note?id=${event.parent_id}`);
} else {
e.stopPropagation();
}
@@ -37,7 +37,7 @@ export const NoteBase = memo(function NoteBase({ event }: { event: any }) {
return (
<div
onClick={(e) => openThread(e)}
className="relative z-10 m-0 flex h-min min-h-min w-full select-text flex-col border-b border-zinc-800 px-3 py-5 hover:bg-black/20"
className="relative z-10 flex h-min min-h-min w-full select-text flex-col border-b border-zinc-800 px-3 py-5 hover:bg-black/20"
>
{parentNote()}
<div className="relative z-10 flex flex-col">
+14 -9
View File
@@ -7,19 +7,18 @@ import { createNote, getNoteByID } from '@utils/storage';
import { getParentID } from '@utils/transform';
import useLocalStorage from '@rehooks/local-storage';
import { memo, useCallback, useContext, useEffect, useRef, useState } from 'react';
import { memo, useCallback, useContext, useEffect, useState } from 'react';
export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
const [pool, relays]: any = useContext(RelayContext);
const [activeAccount]: any = useLocalStorage('account', {});
const [event, setEvent] = useState(null);
const unsubscribe = useRef(null);
const content = event ? contentParser(event.content, event.tags) : '';
const fetchEvent = useCallback(async () => {
unsubscribe.current = pool.subscribe(
const unsubscribe = pool.subscribe(
[
{
ids: [id],
@@ -50,9 +49,13 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
unsubscribeOnEose: true,
}
);
return () => {
unsubscribe();
};
}, [activeAccount.id, id, pool, relays]);
const checkNoteExist = useCallback(async () => {
const checkNoteIsSaved = useCallback(async () => {
getNoteByID(id)
.then((res) => {
if (res) {
@@ -65,14 +68,16 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
}, [fetchEvent, id]);
useEffect(() => {
checkNoteExist();
let ignore = false;
if (!ignore) {
checkNoteIsSaved();
}
return () => {
if (unsubscribe.current) {
unsubscribe.current();
}
ignore = true;
};
}, [checkNoteExist]);
}, [checkNoteIsSaved]);
if (event) {
return (
+14 -9
View File
@@ -6,19 +6,18 @@ import { createNote, getNoteByID } from '@utils/storage';
import { getParentID } from '@utils/transform';
import useLocalStorage from '@rehooks/local-storage';
import { memo, useCallback, useContext, useEffect, useRef, useState } from 'react';
import { memo, useCallback, useContext, useEffect, useState } from 'react';
export const NoteQuote = memo(function NoteQuote({ id }: { id: string }) {
const [pool, relays]: any = useContext(RelayContext);
const [activeAccount]: any = useLocalStorage('account', {});
const [event, setEvent] = useState(null);
const unsubscribe = useRef(null);
const content = event ? contentParser(event.content, event.tags) : '';
const fetchEvent = useCallback(async () => {
unsubscribe.current = pool.subscribe(
const unsubscribe = pool.subscribe(
[
{
ids: [id],
@@ -48,9 +47,13 @@ export const NoteQuote = memo(function NoteQuote({ id }: { id: string }) {
unsubscribeOnEose: true,
}
);
return () => {
unsubscribe();
};
}, [activeAccount.id, id, pool, relays]);
const checkNoteExist = useCallback(async () => {
const checkNoteIsSaved = useCallback(async () => {
getNoteByID(id)
.then((res) => {
if (res) {
@@ -63,14 +66,16 @@ export const NoteQuote = memo(function NoteQuote({ id }: { id: string }) {
}, [fetchEvent, id]);
useEffect(() => {
checkNoteExist();
let ignore = false;
if (!ignore) {
checkNoteIsSaved();
}
return () => {
if (unsubscribe.current) {
unsubscribe.current();
}
ignore = true;
};
}, [checkNoteExist]);
}, [checkNoteIsSaved]);
if (event) {
return (
+1 -1
View File
@@ -21,7 +21,7 @@ export const NoteQuoteRepost = memo(function NoteQuoteRepost({ event }: { event:
};
return (
<div className="relative z-10 m-0 flex h-min min-h-min w-full select-text flex-col border-b border-zinc-800 px-3 py-5 hover:bg-black/20">
<div className="relative z-10 flex h-min min-h-min w-full select-text flex-col border-b border-zinc-800 px-3 py-5 hover:bg-black/20">
<div className="relative z-10 flex flex-col pb-5">
<div className="absolute left-[21px] top-0 h-full w-0.5 bg-gradient-to-t from-zinc-800 to-zinc-600"></div>
<UserQuoteRepost pubkey={event.pubkey} time={event.created_at} />
+21 -11
View File
@@ -5,7 +5,7 @@ import { UserExtend } from '@components/user/extend';
import { contentParser } from '@utils/parser';
import { useRouter } from 'next/navigation';
import { memo, useCallback, useContext, useEffect, useRef, useState } from 'react';
import { memo, useCallback, useContext, useEffect, useState } from 'react';
export const RootNote = memo(function RootNote({ event }: { event: any }) {
const router = useRouter();
@@ -14,17 +14,15 @@ export const RootNote = memo(function RootNote({ event }: { event: any }) {
const [data, setData] = useState(null);
const [content, setContent] = useState('');
const unsubscribe = useRef(null);
const openUserPage = (e) => {
e.stopPropagation();
router.push(`/nostr/users/${event.pubkey}`);
router.push(`/nostr/user?pubkey=${event.pubkey}`);
};
const openThread = (e) => {
const selection = window.getSelection();
if (selection.toString().length === 0) {
router.push(`/nostr/newsfeed/${event.id}`);
router.push(`/nostr/newsfeed/note?id=${event.parent_id}`);
} else {
e.stopPropagation();
}
@@ -32,7 +30,7 @@ export const RootNote = memo(function RootNote({ event }: { event: any }) {
const fetchEvent = useCallback(
async (id: string) => {
unsubscribe.current = pool.subscribe(
const unsubscribe = pool.subscribe(
[
{
ids: [id],
@@ -50,17 +48,29 @@ export const RootNote = memo(function RootNote({ event }: { event: any }) {
unsubscribeOnEose: true,
}
);
return () => {
unsubscribe();
};
},
[pool, relays]
);
useEffect(() => {
if (typeof event === 'object') {
setData(event);
setContent(contentParser(event.content, event.tags));
} else {
fetchEvent(event);
let ignore = false;
if (!ignore) {
if (typeof event === 'object') {
setData(event);
setContent(contentParser(event.content, event.tags));
} else {
fetchEvent(event);
}
}
return () => {
ignore = true;
};
}, [event, fetchEvent]);
if (data) {