mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-11-25 10:45:41 +03:00
Auto-update self account info
And fix isSelf not working in some cases
This commit is contained in:
parent
8d41ff6884
commit
f73a942b61
1 changed files with 31 additions and 5 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue