temporary fix redirect issue in nextjs export

This commit is contained in:
Ren Amamiya
2023-04-21 17:37:47 +07:00
parent b64ed8b587
commit 8bf386ca9b
12 changed files with 41 additions and 32 deletions

View File

@@ -7,30 +7,35 @@ import { DEFAULT_AVATAR } from '@stores/constants';
import { getChats } from '@utils/storage';
import useLocalStorage from '@rehooks/local-storage';
import { useRouter } from 'next/navigation';
import Link from 'next/link';
import { useEffect, useState } from 'react';
export default function ChatList() {
const router = useRouter();
const [list, setList] = useState([]);
const [activeAccount]: any = useLocalStorage('account', {});
const profile = JSON.parse(activeAccount.metadata);
const openSelfChat = () => {
router.push(`/nostr/chat?pubkey=${activeAccount.pubkey}`);
};
useEffect(() => {
let ignore = false;
getChats(activeAccount.id)
.then((res: any) => setList(res))
.then((res: any) => {
if (!ignore) {
setList(res);
}
})
.catch(console.error);
return () => {
ignore = true;
};
}, [activeAccount.id]);
return (
<div className="flex flex-col gap-px">
<div
onClick={() => openSelfChat()}
<Link
prefetch={false}
href={`/nostr/chat?pubkey=${activeAccount.pubkey}`}
className="inline-flex items-center gap-2 rounded-md px-2.5 py-1.5 hover:bg-zinc-900"
>
<div className="relative h-5 w-5 shrink overflow-hidden rounded bg-white">
@@ -46,7 +51,7 @@ export default function ChatList() {
{profile?.display_name || profile?.name} <span className="text-zinc-500">(you)</span>
</h5>
</div>
</div>
</Link>
{list.map((item) => (
<ChatListItem key={item.id} pubkey={item.pubkey} />
))}