diff --git a/app/javascript/gabsocial/features/ui/ui.js b/app/javascript/gabsocial/features/ui/ui.js index 87de61d2..25e287ca 100644 --- a/app/javascript/gabsocial/features/ui/ui.js +++ b/app/javascript/gabsocial/features/ui/ui.js @@ -245,6 +245,8 @@ class UI extends PureComponent { } state = { + fetchedHome: false, + fetchedNotifications: false, draggingOver: false, } @@ -372,9 +374,13 @@ class UI extends PureComponent { window.setTimeout(() => Notification.requestPermission(), 120 * 1000) } - if (this.context.router.route.location.pathname === '/home') { + const pathname = this.context.router.route.location.pathname + + if (pathname === '/home') { + this.setState({ fetchedHome: true }) this.props.dispatch(expandHomeTimeline()) - } else if (this.context.router.route.location.pathname === '/notifications') { + } else if (pathname.startsWith('/notifications')) { + this.setState({ fetchedNotifications: true }) this.props.dispatch(expandNotifications()) } @@ -396,6 +402,20 @@ class UI extends PureComponent { document.removeEventListener('dragend', this.handleDragEnd) } + componentDidUpdate(prevProps) { + if (this.props.location !== prevProps.location) { + const pathname = this.props.location.pathname + + if (pathname === '/home' && !this.state.fetchedHome) { + this.setState({ fetchedHome: true }) + this.props.dispatch(expandHomeTimeline()) + } else if (pathname.startsWith('/notifications') && !this.state.fetchedNotifications) { + this.setState({ fetchedNotifications: true }) + this.props.dispatch(expandNotifications()) + } + } + } + setRef = (c) => { this.node = c }