Make account info load wayyyy faster on Profile page

This commit is contained in:
Lim Chee Aun 2023-03-11 21:33:55 +08:00
parent 4ddd1d3219
commit e0e1196c9e
3 changed files with 15 additions and 6 deletions

View file

@ -1,6 +1,8 @@
import { useEffect } from 'preact/hooks';
import { useHotkeys } from 'react-hotkeys-hook'; import { useHotkeys } from 'react-hotkeys-hook';
import { api } from '../utils/api'; import { api } from '../utils/api';
import states from '../utils/states';
import AccountInfo from './account-info'; import AccountInfo from './account-info';
@ -10,6 +12,12 @@ function AccountSheet({ account, instance: propInstance, onClose }) {
const escRef = useHotkeys('esc', onClose, [onClose]); const escRef = useHotkeys('esc', onClose, [onClose]);
useEffect(() => {
if (!isString) {
states.accounts[`${account.id}@${instance}`] = account;
}
}, [account]);
return ( return (
<div <div
ref={escRef} ref={escRef}

View file

@ -74,18 +74,18 @@ function AccountStatuses() {
const { displayName, acct, emojis } = account || {}; const { displayName, acct, emojis } = account || {};
const TimelineStart = useMemo( const TimelineStart = useMemo(() => {
() => ( const cachedAccount = snapStates.accounts[`${id}@${instance}`];
return (
<AccountInfo <AccountInfo
instance={instance} instance={instance}
account={id} account={cachedAccount || id}
fetchAccount={() => masto.v1.accounts.fetch(id)} fetchAccount={() => masto.v1.accounts.fetch(id)}
authenticated={authenticated} authenticated={authenticated}
standalone standalone
/> />
),
[id, instance, authenticated],
); );
}, [id, instance, authenticated]);
return ( return (
<Timeline <Timeline

View file

@ -27,6 +27,7 @@ const states = proxy({
spoilers: {}, spoilers: {},
scrollPositions: {}, scrollPositions: {},
unfurledLinks: {}, unfurledLinks: {},
accounts: {},
// Modals // Modals
showCompose: false, showCompose: false,
showSettings: false, showSettings: false,