Fix load wrong account's stuff when adding new account

Some account-based calls were called before states are initialized
This commit is contained in:
Lim Chee Aun 2023-10-11 19:07:36 +08:00
parent 68759e64d1
commit b8767f3618
3 changed files with 18 additions and 16 deletions

View file

@ -126,11 +126,13 @@ function App() {
setUIState('default'); setUIState('default');
})(); })();
} else { } else {
window.__IGNORE_GET_ACCOUNT_ERROR__ = true;
const account = getCurrentAccount(); const account = getCurrentAccount();
if (account) { if (account) {
store.session.set('currentAccount', account.info.id); store.session.set('currentAccount', account.info.id);
const { masto, instance } = api({ account }); const { masto, instance } = api({ account });
console.log('masto', masto); console.log('masto', masto);
initStates();
initPreferences(masto); initPreferences(masto);
setUIState('loading'); setUIState('loading');
(async () => { (async () => {

View file

@ -18,7 +18,7 @@ const states = proxy({
homeLast: null, // Last item in 'home' list homeLast: null, // Last item in 'home' list
homeLastFetchTime: null, homeLastFetchTime: null,
notifications: [], notifications: [],
notificationsLast: store.account.get('notificationsLast') || null, // Last read notification notificationsLast: null, // Last read notification
notificationsNew: [], notificationsNew: [],
notificationsShowNew: false, notificationsShowNew: false,
notificationsLastFetchTime: null, notificationsLastFetchTime: null,
@ -46,23 +46,18 @@ const states = proxy({
showGenericAccounts: false, showGenericAccounts: false,
showMediaAlt: false, showMediaAlt: false,
// Shortcuts // Shortcuts
shortcuts: store.account.get('shortcuts') ?? [], shortcuts: [],
// Settings // Settings
settings: { settings: {
autoRefresh: store.account.get('settings-autoRefresh') ?? false, autoRefresh: false,
shortcutsViewMode: store.account.get('settings-shortcutsViewMode') ?? null, shortcutsViewMode: null,
shortcutsColumnsMode: shortcutsColumnsMode: false,
store.account.get('settings-shortcutsColumnsMode') ?? false, boostsCarousel: true,
boostsCarousel: store.account.get('settings-boostsCarousel') ?? true, contentTranslation: true,
contentTranslation: contentTranslationTargetLanguage: null,
store.account.get('settings-contentTranslation') ?? true, contentTranslationHideLanguages: [],
contentTranslationTargetLanguage: contentTranslationAutoInline: false,
store.account.get('settings-contentTranslationTargetLanguage') || null, cloakMode: false,
contentTranslationHideLanguages:
store.account.get('settings-contentTranslationHideLanguages') || [],
contentTranslationAutoInline:
store.account.get('settings-contentTranslationAutoInline') ?? false,
cloakMode: store.account.get('settings-cloakMode') ?? false,
}, },
}); });

View file

@ -11,6 +11,11 @@ export function getAccountByAccessToken(accessToken) {
} }
export function getCurrentAccount() { export function getCurrentAccount() {
if (!window.__IGNORE_GET_ACCOUNT_ERROR__) {
// Track down getCurrentAccount() calls before account-based states are initialized
console.error('getCurrentAccount() called before states are initialized');
if (import.meta.env.DEV) console.trace();
}
const currentAccount = store.session.get('currentAccount'); const currentAccount = store.session.get('currentAccount');
const account = getAccount(currentAccount); const account = getAccount(currentAccount);
return account; return account;