fixed nextjs build with super cringe solution (will be revert in next commit)

This commit is contained in:
Ren Amamiya
2023-04-21 10:45:29 +07:00
parent 5a7389b7e8
commit a2aad487ab
11 changed files with 44 additions and 26 deletions

View File

@@ -12,9 +12,13 @@ import { dateToUnix, hoursAgo } from '@utils/getDate';
import useLocalStorage from '@rehooks/local-storage'; import useLocalStorage from '@rehooks/local-storage';
import { useSetAtom } from 'jotai'; import { useSetAtom } from 'jotai';
import { useResetAtom } from 'jotai/utils'; import { useResetAtom } from 'jotai/utils';
import { useSearchParams } from 'next/navigation';
import { useContext, useEffect, useRef } from 'react'; import { useContext, useEffect, useRef } from 'react';
export default function Page({ params }: { params: { id: string } }) { export default function Page() {
const searchParams = useSearchParams();
const channelID = searchParams.get('id');
const [pool]: any = useContext(RelayContext); const [pool]: any = useContext(RelayContext);
const [activeAccount]: any = useLocalStorage('account', {}); const [activeAccount]: any = useLocalStorage('account', {});
@@ -40,7 +44,7 @@ export default function Page({ params }: { params: { id: string } }) {
since: dateToUnix(hoursAgo(24, now.current)), since: dateToUnix(hoursAgo(24, now.current)),
}, },
{ {
'#e': [params.id], '#e': [channelID],
kinds: [42], kinds: [42],
since: dateToUnix(hoursAgo(24, now.current)), since: dateToUnix(hoursAgo(24, now.current)),
}, },
@@ -66,13 +70,13 @@ export default function Page({ params }: { params: { id: string } }) {
return () => { return () => {
unsubscribe(); unsubscribe();
}; };
}, [pool, activeAccount.pubkey, params.id, setChannelMessages, resetChannelReply, resetChannelMessages]); }, [pool, activeAccount.pubkey, channelID, setChannelMessages, resetChannelReply, resetChannelMessages]);
return ( return (
<div className="flex h-full w-full flex-col justify-between"> <div className="flex h-full w-full flex-col justify-between">
<ChannelMessages /> <ChannelMessages />
<div className="shrink-0 p-3"> <div className="shrink-0 p-3">
<FormChannel eventId={params.id} /> <FormChannel eventId={channelID} />
</div> </div>
</div> </div>
); );

View File

@@ -10,9 +10,13 @@ import { FULL_RELAYS } from '@stores/constants';
import useLocalStorage from '@rehooks/local-storage'; import useLocalStorage from '@rehooks/local-storage';
import { useSetAtom } from 'jotai'; import { useSetAtom } from 'jotai';
import { useResetAtom } from 'jotai/utils'; import { useResetAtom } from 'jotai/utils';
import { useSearchParams } from 'next/navigation';
import { Suspense, useCallback, useContext, useEffect, useRef } from 'react'; import { Suspense, useCallback, useContext, useEffect, useRef } from 'react';
export default function Page({ params }: { params: { pubkey: string } }) { export default function Page() {
const searchParams = useSearchParams();
const pubkey = searchParams.get('pubkey');
const [pool]: any = useContext(RelayContext); const [pool]: any = useContext(RelayContext);
const [activeAccount]: any = useLocalStorage('account', {}); const [activeAccount]: any = useLocalStorage('account', {});
@@ -26,13 +30,13 @@ export default function Page({ params }: { params: { pubkey: string } }) {
[ [
{ {
kinds: [4], kinds: [4],
authors: [params.pubkey], authors: [pubkey],
'#p': [activeAccount.pubkey], '#p': [activeAccount.pubkey],
}, },
{ {
kinds: [4], kinds: [4],
authors: [activeAccount.pubkey], authors: [activeAccount.pubkey],
'#p': [params.pubkey], '#p': [pubkey],
}, },
], ],
FULL_RELAYS, FULL_RELAYS,
@@ -40,7 +44,7 @@ export default function Page({ params }: { params: { pubkey: string } }) {
setChatMessages((data) => [...data, event]); setChatMessages((data) => [...data, event]);
} }
); );
}, [activeAccount.pubkey, params.pubkey, pool, setChatMessages]); }, [activeAccount.pubkey, pubkey, pool, setChatMessages]);
useEffect(() => { useEffect(() => {
// reset stored messages // reset stored messages
@@ -61,7 +65,7 @@ export default function Page({ params }: { params: { pubkey: string } }) {
<MessageList /> <MessageList />
</Suspense> </Suspense>
<div className="shrink-0 p-3"> <div className="shrink-0 p-3">
<FormChat receiverPubkey={params.pubkey} /> <FormChat receiverPubkey={pubkey} />
</div> </div>
</div> </div>
); );

View File

@@ -68,7 +68,9 @@ export default function Page() {
// broadcast // broadcast
pool.publish(event, relays); pool.publish(event, relays);
// redirect to next step // redirect to next step
router.push(`/onboarding/create/${pubkey}/${privkey}`); router.replace(`/onboarding/create/step-2?pubkey=${pubkey}&privkey=${privkey}`, {
forceOptimisticNavigation: true,
});
}, [pool, pubkey, privkey, metadata, relays, router]); }, [pool, pubkey, privkey, metadata, relays, router]);
return ( return (

View File

@@ -9,7 +9,7 @@ import { arrayToNIP02 } from '@utils/transform';
import { createClient } from '@supabase/supabase-js'; import { createClient } from '@supabase/supabase-js';
import { CheckCircle } from 'iconoir-react'; import { CheckCircle } from 'iconoir-react';
import { useRouter } from 'next/navigation'; import { useRouter, useSearchParams } from 'next/navigation';
import { getEventHash, signEvent } from 'nostr-tools'; import { getEventHash, signEvent } from 'nostr-tools';
import { Key, useCallback, useContext, useEffect, useState } from 'react'; import { Key, useCallback, useContext, useEffect, useState } from 'react';
@@ -53,11 +53,12 @@ const initialList = [
{ pubkey: 'ff04a0e6cd80c141b0b55825fed127d4532a6eecdb7e743a38a3c28bf9f44609' }, { pubkey: 'ff04a0e6cd80c141b0b55825fed127d4532a6eecdb7e743a38a3c28bf9f44609' },
]; ];
export default function Page({ params }: { params: { slug: string } }) { export default function Page() {
const router = useRouter(); const router = useRouter();
const searchParams = useSearchParams();
const pubkey = params.slug[0]; const pubkey = searchParams.get('pubkey');
const privkey = params.slug[1]; const privkey = searchParams.get('privkey');
const [pool, relays]: any = useContext(RelayContext); const [pool, relays]: any = useContext(RelayContext);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
@@ -99,7 +100,7 @@ export default function Page({ params }: { params: { slug: string } }) {
// broadcast // broadcast
pool.publish(event, relays); pool.publish(event, relays);
// redirect to splashscreen // redirect to splashscreen
router.replace('/'); router.replace('/', { forceOptimisticNavigation: true });
}, [pubkey, privkey, follows, pool, relays, router]); }, [pubkey, privkey, follows, pool, relays, router]);
useEffect(() => { useEffect(() => {

View File

@@ -40,7 +40,7 @@ export default function Page() {
privkey = nip19.decode(privkey).data; privkey = nip19.decode(privkey).data;
} }
if (typeof getPublicKey(privkey) === 'string') { if (typeof getPublicKey(privkey) === 'string') {
router.push(`/onboarding/login/${privkey}`); router.push(`/onboarding/login/step-2?privkey=${privkey}`, { forceOptimisticNavigation: true });
} }
} catch (error) { } catch (error) {
setError('key', { setError('key', {

View File

@@ -11,12 +11,16 @@ import { nip02ToArray } from '@utils/transform';
import Image from 'next/image'; import Image from 'next/image';
import Link from 'next/link'; import Link from 'next/link';
import { useSearchParams } from 'next/navigation';
import { getPublicKey } from 'nostr-tools'; import { getPublicKey } from 'nostr-tools';
import { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react'; import { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
export default function Page({ params }: { params: { privkey: string } }) { export default function Page() {
const searchParams = useSearchParams();
const privkey = searchParams.get('privkey');
const [pool, relays]: any = useContext(RelayContext); const [pool, relays]: any = useContext(RelayContext);
const pubkey = useMemo(() => (params.privkey ? getPublicKey(params.privkey) : null), [params.privkey]); const pubkey = useMemo(() => (privkey ? getPublicKey(privkey) : null), [privkey]);
const timeout = useRef(null); const timeout = useRef(null);
const [profile, setProfile] = useState({ metadata: null }); const [profile, setProfile] = useState({ metadata: null });
@@ -42,7 +46,7 @@ export default function Page({ params }: { params: { privkey: string } }) {
(event: any) => { (event: any) => {
if (event.kind === 0) { if (event.kind === 0) {
// create account // create account
createAccount(pubkey, params.privkey, event.content); createAccount(pubkey, privkey, event.content);
// update state // update state
setProfile({ setProfile({
metadata: JSON.parse(event.content), metadata: JSON.parse(event.content),
@@ -70,7 +74,7 @@ export default function Page({ params }: { params: { privkey: string } }) {
unsubscribe; unsubscribe;
clearTimeout(timeout.current); clearTimeout(timeout.current);
}; };
}, [pool, relays, pubkey, params.privkey, createPlebs]); }, [pool, relays, pubkey, privkey, createPlebs]);
return ( return (
<div className="grid h-full w-full grid-rows-5"> <div className="grid h-full w-full grid-rows-5">

View File

@@ -125,7 +125,10 @@ export default function Page() {
undefined, undefined,
() => { () => {
updateLastLogin(dateToUnix(now.current)); updateLastLogin(dateToUnix(now.current));
timeout.current = setTimeout(() => router.replace('/nostr/newsfeed/following'), 5000); timeout.current = setTimeout(
() => router.replace('/nostr/newsfeed/following', { forceOptimisticNavigation: true }),
5000
);
}, },
{ {
unsubscribeOnEose: true, unsubscribeOnEose: true,
@@ -154,7 +157,7 @@ export default function Page() {
// fetch data // fetch data
fetchData(account, account.follows); fetchData(account, account.follows);
} else { } else {
router.replace('/onboarding'); router.replace('/onboarding', { forceOptimisticNavigation: true });
} }
}) })
.catch(console.error); .catch(console.error);

View File

@@ -18,7 +18,7 @@ export default function AppActions() {
}; };
const reload = () => { const reload = () => {
router.refresh(); window.location.reload();
}; };
useLayoutEffect(() => { useLayoutEffect(() => {

View File

@@ -10,7 +10,7 @@ export const ChannelListItem = ({ data }: { data: any }) => {
return ( return (
<ActiveLink <ActiveLink
href={`/nostr/channels/${data.event_id}`} href={`/nostr/channels?id=${data.event_id}`}
activeClassName="dark:bg-zinc-900 dark:text-zinc-100 hover:dark:bg-zinc-800" 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" 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 profile = JSON.parse(activeAccount.metadata);
const openSelfChat = () => { const openSelfChat = () => {
router.push(`/nostr/chats/${activeAccount.pubkey}`); router.push(`/nostr/chats?pubkey=${activeAccount.pubkey}`);
}; };
useEffect(() => { useEffect(() => {

View File

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