Skip to content

Commit d9a3326

Browse files
authored
Merge pull request #4369 from joaquimrocha/minimize-blocking-activities-on-page-change
frontend: Minimize activities blocking the main content when needed
2 parents 84af694 + c81859a commit d9a3326

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

frontend/src/components/activity/Activity.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import React, {
4747
import { createPortal } from 'react-dom';
4848
import { useHotkeys } from 'react-hotkeys-hook';
4949
import { Trans, useTranslation } from 'react-i18next';
50+
import { useLocation } from 'react-router-dom';
5051
import { useTypedSelector } from '../../redux/hooks';
5152
import store from '../../redux/stores/store';
5253
import { activitySlice } from './activitySlice';
@@ -946,6 +947,28 @@ export const ActivitiesRenderer = React.memo(function ActivitiesRenderer() {
946947
const history = useTypedSelector(state => state.activity.history) as string[];
947948
const lastElement = history.at(-1);
948949
const [isOverview, setIsOverview] = useState(false);
950+
const location = useLocation();
951+
const locationRef = useRef(location.pathname);
952+
953+
// Minimize activities that block the main content on route change.
954+
// Activities in 'split-right' location are kept visible since they
955+
// allow the user to see most of the main content.
956+
useEffect(() => {
957+
activities.forEach(activity => {
958+
// If we were triggered just because of the activities changing but the
959+
// location hasn't changed, we have nothing to do.
960+
if (locationRef.current === location.pathname) {
961+
return;
962+
}
963+
964+
if (activity.location !== 'split-right' && !activity.minimized) {
965+
Activity.update(activity.id, { minimized: true });
966+
}
967+
});
968+
969+
locationRef.current = location.pathname;
970+
}, [location.pathname, activities]);
971+
949972
useEffect(() => {
950973
if (activities.length === 0 && isOverview) {
951974
setIsOverview(false);

0 commit comments

Comments
 (0)