Auto-update self account info

And fix isSelf not working in some cases
This commit is contained in:
Lim Chee Aun 2023-11-06 00:49:45 +08:00
parent 8d41ff6884
commit f73a942b61

View file

@ -131,11 +131,6 @@ function AccountInfo({
const isString = typeof account === 'string';
const [info, setInfo] = useState(isString ? null : account);
const isSelf = useMemo(
() => account.id === store.session.get('currentAccount'),
[account?.id],
);
const sameCurrentInstance = useMemo(
() => instance === currentInstance,
[instance, currentInstance],
@ -198,6 +193,37 @@ function AccountInfo({
}
}
const isSelf = useMemo(
() => id === store.session.get('currentAccount'),
[id],
);
useEffect(() => {
const infoHasEssentials = !!(
info?.id &&
info?.username &&
info?.acct &&
info?.avatar &&
info?.avatarStatic &&
info?.displayName &&
info?.url
);
if (isSelf && instance && infoHasEssentials) {
const accounts = store.local.getJSON('accounts');
let updated = false;
accounts.forEach((account) => {
if (account.info.id === info.id && account.instanceURL === instance) {
account.info = info;
updated = true;
}
});
if (updated) {
console.log('Updated account info', info);
store.local.setJSON('accounts', accounts);
}
}
}, [isSelf, info, instance]);
const accountInstance = useMemo(() => {
if (!url) return null;
const domain = new URL(url).hostname;