use top level await for some functions

This commit is contained in:
Ren Amamiya
2023-04-23 12:15:04 +07:00
parent ac6fb3cb55
commit 97c45a8c8f
11 changed files with 270 additions and 271 deletions

View File

@@ -3,32 +3,22 @@ import { ChatModal } from '@components/chats/chatModal';
import { DEFAULT_AVATAR } from '@stores/constants';
import { getChats } from '@utils/storage';
import useLocalStorage from '@rehooks/local-storage';
import { useEffect, useState } from 'react';
let list: any = [];
if (typeof window !== 'undefined') {
const { getChats } = await import('@utils/storage');
const getAccount = window.localStorage.getItem('account');
const account = getAccount ? JSON.parse(getAccount) : null;
list = await getChats(account.id);
}
export default function ChatList() {
const [list, setList] = useState([]);
const [activeAccount]: any = useLocalStorage('account', {});
const profile = activeAccount.metadata ? JSON.parse(activeAccount.metadata) : null;
useEffect(() => {
let ignore = false;
getChats(activeAccount.id)
.then((res: any) => {
if (!ignore) {
setList(res);
}
})
.catch(console.error);
return () => {
ignore = true;
};
}, [activeAccount.id]);
return (
<div className="flex flex-col gap-px">
<a