UI: fix the way initial data is loaded

This commit is contained in:
Alex Gleason 2021-12-15 10:29:07 -05:00
parent e2df6eff8b
commit e283afe191
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 39 additions and 29 deletions

View File

@ -470,26 +470,10 @@ class UI extends React.PureComponent {
trailing: true, trailing: true,
}); });
componentDidMount() { // Load initial data when a user is logged in
const { account, features, vapidKey, dispatch } = this.props; loadAccountData = () => {
if (!account) return; const { account, features, dispatch } = this.props;
window.addEventListener('resize', this.handleResize, { passive: true });
document.addEventListener('dragenter', this.handleDragEnter, false);
document.addEventListener('dragover', this.handleDragOver, false);
document.addEventListener('drop', this.handleDrop, false);
document.addEventListener('dragleave', this.handleDragLeave, false);
document.addEventListener('dragend', this.handleDragEnd, false);
if ('serviceWorker' in navigator) {
navigator.serviceWorker.addEventListener('message', this.handleServiceWorkerPostMessage);
}
if (typeof window.Notification !== 'undefined' && Notification.permission === 'default') {
window.setTimeout(() => Notification.requestPermission(), 120 * 1000);
}
if (account) {
dispatch(expandHomeTimeline()); dispatch(expandHomeTimeline());
dispatch(expandNotifications()) dispatch(expandNotifications())
@ -518,6 +502,28 @@ class UI extends React.PureComponent {
setTimeout(() => dispatch(fetchScheduledStatuses()), 900); setTimeout(() => dispatch(fetchScheduledStatuses()), 900);
} }
componentDidMount() {
const { account, vapidKey, dispatch } = this.props;
window.addEventListener('resize', this.handleResize, { passive: true });
document.addEventListener('dragenter', this.handleDragEnter, false);
document.addEventListener('dragover', this.handleDragOver, false);
document.addEventListener('drop', this.handleDrop, false);
document.addEventListener('dragleave', this.handleDragLeave, false);
document.addEventListener('dragend', this.handleDragEnd, false);
if ('serviceWorker' in navigator) {
navigator.serviceWorker.addEventListener('message', this.handleServiceWorkerPostMessage);
}
if (typeof window.Notification !== 'undefined' && Notification.permission === 'default') {
window.setTimeout(() => Notification.requestPermission(), 120 * 1000);
}
if (account) {
this.loadAccountData();
}
dispatch(fetchCustomEmojis()); dispatch(fetchCustomEmojis());
this.connectStreaming(); this.connectStreaming();
@ -531,7 +537,11 @@ class UI extends React.PureComponent {
const { dispatch, account, features, vapidKey } = this.props; const { dispatch, account, features, vapidKey } = this.props;
if (features.chats && account && !prevProps.features.chats) { // The user has logged in
if (account && !prevProps.account) {
this.loadAccountData();
// The instance has loaded
} else if (account && features.chats && !prevProps.features.chats) {
dispatch(fetchChats()); dispatch(fetchChats());
} }