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

This reverts commit a2aad487abf806a50a7d07550937663b593cb05f.
This commit is contained in:
Ren Amamiya 2023-04-21 11:00:45 +07:00
parent a2aad487ab
commit 1ee77c28fe
11 changed files with 26 additions and 44 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -10,7 +10,7 @@ export const ChannelListItem = ({ data }: { data: any }) => {
return (
<ActiveLink
href={`/nostr/channels?id=${data.event_id}`}
href={`/nostr/channels/${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?pubkey=${activeAccount.pubkey}`);
router.push(`/nostr/chats/${activeAccount.pubkey}`);
};
useEffect(() => {

View File

@ -11,7 +11,7 @@ export const ChatListItem = ({ pubkey }: { pubkey: string }) => {
return (
<ActiveLink
href={`/nostr/chats?pubkey=${pubkey}`}
href={`/nostr/chats/${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"
>