From a2aad487abf806a50a7d07550937663b593cb05f Mon Sep 17 00:00:00 2001
From: Ren Amamiya <123083837+reyamir@users.noreply.github.com>
Date: Fri, 21 Apr 2023 10:45:29 +0700
Subject: [PATCH] fixed nextjs build with super cringe solution (will be revert
in next commit)
---
src/app/nostr/channels/{[id] => }/page.tsx | 12 ++++++++----
src/app/nostr/chats/{[pubkey] => }/page.tsx | 14 +++++++++-----
src/app/onboarding/create/page.tsx | 4 +++-
.../create/{[...slug] => step-2}/page.tsx | 11 ++++++-----
src/app/onboarding/login/page.tsx | 2 +-
.../login/{[privkey] => step-2}/page.tsx | 12 ++++++++----
src/app/page.tsx | 7 +++++--
src/components/appHeader/actions.tsx | 2 +-
src/components/channels/channelListItem.tsx | 2 +-
src/components/chats/chatList.tsx | 2 +-
src/components/chats/chatListItem.tsx | 2 +-
11 files changed, 44 insertions(+), 26 deletions(-)
rename src/app/nostr/channels/{[id] => }/page.tsx (87%)
rename src/app/nostr/chats/{[pubkey] => }/page.tsx (83%)
rename src/app/onboarding/create/{[...slug] => step-2}/page.tsx (96%)
rename src/app/onboarding/login/{[privkey] => step-2}/page.tsx (93%)
diff --git a/src/app/nostr/channels/[id]/page.tsx b/src/app/nostr/channels/page.tsx
similarity index 87%
rename from src/app/nostr/channels/[id]/page.tsx
rename to src/app/nostr/channels/page.tsx
index a25aec1e..9517bcf1 100644
--- a/src/app/nostr/channels/[id]/page.tsx
+++ b/src/app/nostr/channels/page.tsx
@@ -12,9 +12,13 @@ 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({ params }: { params: { id: string } }) {
+export default function Page() {
+ const searchParams = useSearchParams();
+ const channelID = searchParams.get('id');
+
const [pool]: any = useContext(RelayContext);
const [activeAccount]: any = useLocalStorage('account', {});
@@ -40,7 +44,7 @@ export default function Page({ params }: { params: { id: string } }) {
since: dateToUnix(hoursAgo(24, now.current)),
},
{
- '#e': [params.id],
+ '#e': [channelID],
kinds: [42],
since: dateToUnix(hoursAgo(24, now.current)),
},
@@ -66,13 +70,13 @@ export default function Page({ params }: { params: { id: string } }) {
return () => {
unsubscribe();
};
- }, [pool, activeAccount.pubkey, params.id, setChannelMessages, resetChannelReply, resetChannelMessages]);
+ }, [pool, activeAccount.pubkey, channelID, setChannelMessages, resetChannelReply, resetChannelMessages]);
return (
);
diff --git a/src/app/nostr/chats/[pubkey]/page.tsx b/src/app/nostr/chats/page.tsx
similarity index 83%
rename from src/app/nostr/chats/[pubkey]/page.tsx
rename to src/app/nostr/chats/page.tsx
index aba3eaa8..bfcf8619 100644
--- a/src/app/nostr/chats/[pubkey]/page.tsx
+++ b/src/app/nostr/chats/page.tsx
@@ -10,9 +10,13 @@ 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({ params }: { params: { pubkey: string } }) {
+export default function Page() {
+ const searchParams = useSearchParams();
+ const pubkey = searchParams.get('pubkey');
+
const [pool]: any = useContext(RelayContext);
const [activeAccount]: any = useLocalStorage('account', {});
@@ -26,13 +30,13 @@ export default function Page({ params }: { params: { pubkey: string } }) {
[
{
kinds: [4],
- authors: [params.pubkey],
+ authors: [pubkey],
'#p': [activeAccount.pubkey],
},
{
kinds: [4],
authors: [activeAccount.pubkey],
- '#p': [params.pubkey],
+ '#p': [pubkey],
},
],
FULL_RELAYS,
@@ -40,7 +44,7 @@ export default function Page({ params }: { params: { pubkey: string } }) {
setChatMessages((data) => [...data, event]);
}
);
- }, [activeAccount.pubkey, params.pubkey, pool, setChatMessages]);
+ }, [activeAccount.pubkey, pubkey, pool, setChatMessages]);
useEffect(() => {
// reset stored messages
@@ -61,7 +65,7 @@ export default function Page({ params }: { params: { pubkey: string } }) {
-
+
);
diff --git a/src/app/onboarding/create/page.tsx b/src/app/onboarding/create/page.tsx
index d38e5882..efce96fa 100644
--- a/src/app/onboarding/create/page.tsx
+++ b/src/app/onboarding/create/page.tsx
@@ -68,7 +68,9 @@ export default function Page() {
// broadcast
pool.publish(event, relays);
// 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]);
return (
diff --git a/src/app/onboarding/create/[...slug]/page.tsx b/src/app/onboarding/create/step-2/page.tsx
similarity index 96%
rename from src/app/onboarding/create/[...slug]/page.tsx
rename to src/app/onboarding/create/step-2/page.tsx
index 60f84f2a..af97bc31 100644
--- a/src/app/onboarding/create/[...slug]/page.tsx
+++ b/src/app/onboarding/create/step-2/page.tsx
@@ -9,7 +9,7 @@ import { arrayToNIP02 } from '@utils/transform';
import { createClient } from '@supabase/supabase-js';
import { CheckCircle } from 'iconoir-react';
-import { useRouter } from 'next/navigation';
+import { useRouter, useSearchParams } from 'next/navigation';
import { getEventHash, signEvent } from 'nostr-tools';
import { Key, useCallback, useContext, useEffect, useState } from 'react';
@@ -53,11 +53,12 @@ const initialList = [
{ pubkey: 'ff04a0e6cd80c141b0b55825fed127d4532a6eecdb7e743a38a3c28bf9f44609' },
];
-export default function Page({ params }: { params: { slug: string } }) {
+export default function Page() {
const router = useRouter();
+ const searchParams = useSearchParams();
- const pubkey = params.slug[0];
- const privkey = params.slug[1];
+ const pubkey = searchParams.get('pubkey');
+ const privkey = searchParams.get('privkey');
const [pool, relays]: any = useContext(RelayContext);
const [loading, setLoading] = useState(false);
@@ -99,7 +100,7 @@ export default function Page({ params }: { params: { slug: string } }) {
// broadcast
pool.publish(event, relays);
// redirect to splashscreen
- router.replace('/');
+ router.replace('/', { forceOptimisticNavigation: true });
}, [pubkey, privkey, follows, pool, relays, router]);
useEffect(() => {
diff --git a/src/app/onboarding/login/page.tsx b/src/app/onboarding/login/page.tsx
index dc2adca1..a0eeccfa 100644
--- a/src/app/onboarding/login/page.tsx
+++ b/src/app/onboarding/login/page.tsx
@@ -40,7 +40,7 @@ export default function Page() {
privkey = nip19.decode(privkey).data;
}
if (typeof getPublicKey(privkey) === 'string') {
- router.push(`/onboarding/login/${privkey}`);
+ router.push(`/onboarding/login/step-2?privkey=${privkey}`, { forceOptimisticNavigation: true });
}
} catch (error) {
setError('key', {
diff --git a/src/app/onboarding/login/[privkey]/page.tsx b/src/app/onboarding/login/step-2/page.tsx
similarity index 93%
rename from src/app/onboarding/login/[privkey]/page.tsx
rename to src/app/onboarding/login/step-2/page.tsx
index 430bfd13..1a178d17 100644
--- a/src/app/onboarding/login/[privkey]/page.tsx
+++ b/src/app/onboarding/login/step-2/page.tsx
@@ -11,12 +11,16 @@ 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({ params }: { params: { privkey: string } }) {
+export default function Page() {
+ const searchParams = useSearchParams();
+ const privkey = searchParams.get('privkey');
+
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 [profile, setProfile] = useState({ metadata: null });
@@ -42,7 +46,7 @@ export default function Page({ params }: { params: { privkey: string } }) {
(event: any) => {
if (event.kind === 0) {
// create account
- createAccount(pubkey, params.privkey, event.content);
+ createAccount(pubkey, privkey, event.content);
// update state
setProfile({
metadata: JSON.parse(event.content),
@@ -70,7 +74,7 @@ export default function Page({ params }: { params: { privkey: string } }) {
unsubscribe;
clearTimeout(timeout.current);
};
- }, [pool, relays, pubkey, params.privkey, createPlebs]);
+ }, [pool, relays, pubkey, privkey, createPlebs]);
return (
diff --git a/src/app/page.tsx b/src/app/page.tsx
index 52aa4101..5d365624 100644
--- a/src/app/page.tsx
+++ b/src/app/page.tsx
@@ -125,7 +125,10 @@ export default function Page() {
undefined,
() => {
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,
@@ -154,7 +157,7 @@ export default function Page() {
// fetch data
fetchData(account, account.follows);
} else {
- router.replace('/onboarding');
+ router.replace('/onboarding', { forceOptimisticNavigation: true });
}
})
.catch(console.error);
diff --git a/src/components/appHeader/actions.tsx b/src/components/appHeader/actions.tsx
index b8c13ada..2a9c5007 100644
--- a/src/components/appHeader/actions.tsx
+++ b/src/components/appHeader/actions.tsx
@@ -18,7 +18,7 @@ export default function AppActions() {
};
const reload = () => {
- router.refresh();
+ window.location.reload();
};
useLayoutEffect(() => {
diff --git a/src/components/channels/channelListItem.tsx b/src/components/channels/channelListItem.tsx
index c687c811..28be73e6 100644
--- a/src/components/channels/channelListItem.tsx
+++ b/src/components/channels/channelListItem.tsx
@@ -10,7 +10,7 @@ export const ChannelListItem = ({ data }: { data: any }) => {
return (
diff --git a/src/components/chats/chatList.tsx b/src/components/chats/chatList.tsx
index 5fc443f7..ddd4573e 100644
--- a/src/components/chats/chatList.tsx
+++ b/src/components/chats/chatList.tsx
@@ -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/chats?pubkey=${activeAccount.pubkey}`);
};
useEffect(() => {
diff --git a/src/components/chats/chatListItem.tsx b/src/components/chats/chatListItem.tsx
index c5f29ad7..d9da48ec 100644
--- a/src/components/chats/chatListItem.tsx
+++ b/src/components/chats/chatListItem.tsx
@@ -11,7 +11,7 @@ export const ChatListItem = ({ pubkey }: { pubkey: string }) => {
return (