From ec88110e2d8b4a738be88cf47817075f05fe4479 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Wed, 7 Jun 2023 19:37:47 +0800 Subject: [PATCH] Possibly fix sometimes the Profile menu becomes missing --- src/components/nav-menu.jsx | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/components/nav-menu.jsx b/src/components/nav-menu.jsx index 45793528..7ac55fb8 100644 --- a/src/components/nav-menu.jsx +++ b/src/components/nav-menu.jsx @@ -1,7 +1,7 @@ import './nav-menu.css'; import { ControlledMenu, MenuDivider, MenuItem } from '@szhsin/react-menu'; -import { useRef, useState } from 'preact/hooks'; +import { useEffect, useRef, useState } from 'preact/hooks'; import { useLongPress } from 'use-long-press'; import { useSnapshot } from 'valtio'; @@ -16,11 +16,18 @@ import MenuLink from './menu-link'; function NavMenu(props) { const snapStates = useSnapshot(states); const { instance, authenticated } = api(); - const accounts = store.local.getJSON('accounts') || []; - const currentAccount = accounts.find( - (account) => account.info.id === store.session.get('currentAccount'), - ); - const moreThanOneAccount = accounts.length > 1; + + const [currentAccount, setCurrentAccount] = useState(); + const [moreThanOneAccount, setMoreThanOneAccount] = useState(false); + + useEffect(() => { + const accounts = store.local.getJSON('accounts') || []; + const acc = accounts.find( + (account) => account.info.id === store.session.get('currentAccount'), + ); + if (acc) setCurrentAccount(acc); + setMoreThanOneAccount(accounts.length > 1); + }, []); // Home = Following // But when in multi-column mode, Home becomes columns of anything