mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-11-22 09:15:33 +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 isString = typeof account === 'string';
|
||||||
const [info, setInfo] = useState(isString ? null : account);
|
const [info, setInfo] = useState(isString ? null : account);
|
||||||
|
|
||||||
const isSelf = useMemo(
|
|
||||||
() => account.id === store.session.get('currentAccount'),
|
|
||||||
[account?.id],
|
|
||||||
);
|
|
||||||
|
|
||||||
const sameCurrentInstance = useMemo(
|
const sameCurrentInstance = useMemo(
|
||||||
() => instance === currentInstance,
|
() => instance === currentInstance,
|
||||||
[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(() => {
|
const accountInstance = useMemo(() => {
|
||||||
if (!url) return null;
|
if (!url) return null;
|
||||||
const domain = new URL(url).hostname;
|
const domain = new URL(url).hostname;
|
||||||
|
|
Loading…
Reference in a new issue