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

View file

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

View file

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