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

View File

@@ -1,40 +0,0 @@
import { ImageWithFallback } from '@components/imageWithFallback';
import { DEFAULT_AVATAR, DEFAULT_CHANNEL_BANNER } from '@stores/constants';
import { useChannelMetadata } from '@utils/hooks/useChannelMetadata';
export const BrowseChannelItem = ({ data }: { data: any }) => {
const channel = useChannelMetadata(data.event_id, data.metadata);
return (
<div className="h-64 w-full rounded-md bg-zinc-900">
<div className="relative h-24">
<div className="h-24 w-full rounded-t-md bg-zinc-800">
<ImageWithFallback
src={channel?.banner || DEFAULT_CHANNEL_BANNER}
alt={data.id}
fill={true}
className="h-full w-full rounded-t-md object-cover"
/>
</div>
<div className="relative -top-6 z-10 px-4">
<div className="relative h-11 w-11 rounded-md bg-white">
<ImageWithFallback
src={channel?.picture || DEFAULT_AVATAR}
alt={data.id}
fill={true}
className="rounded-md object-cover ring-1 ring-black/50"
/>
</div>
</div>
</div>
<div className="mt-7 px-4">
<div className="flex flex-col">
<h3 className="w-full truncate font-semibold leading-tight text-zinc-100">{channel?.name}</h3>
</div>
<div className="line-clamp-3 text-sm text-zinc-400">{channel?.about}</div>
</div>
</div>
);
};

View File

@@ -10,7 +10,7 @@ export const ChannelListItem = ({ data }: { data: any }) => {
return (
<ActiveLink
href={`/nostr/channels/${data.event_id}`}
href={`/nostr/channel?channel-id=${data.event_id}`}
activeClassName="dark:bg-zinc-900 dark:text-zinc-100 hover:dark:bg-zinc-800"
className="inline-flex items-center gap-2 rounded-md px-2.5 py-1.5 hover:bg-zinc-900"
>

View File

@@ -18,7 +18,7 @@ export default function ChatList() {
const profile = JSON.parse(activeAccount.metadata);
const openSelfChat = () => {
router.push(`/nostr/chats/${activeAccount.pubkey}`);
router.push(`/nostr/chat?pubkey=${activeAccount.pubkey}`);
};
useEffect(() => {

View File

@@ -11,7 +11,7 @@ export const ChatListItem = ({ pubkey }: { pubkey: string }) => {
return (
<ActiveLink
href={`/nostr/chats/${pubkey}`}
href={`/nostr/chat?pubkey=${pubkey}`}
activeClassName="dark:bg-zinc-900 dark:text-zinc-100 hover:dark:bg-zinc-800"
className="inline-flex items-center gap-2 rounded-md px-2.5 py-1.5 hover:bg-zinc-900"
>

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">

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 (

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 (

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} />

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) {