From 96ddab27c417d8bbd69b3b07b3294a5c691ca48e Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 11 Sep 2021 14:47:26 -0700 Subject: [PATCH] fix: Collection expand/collapse as navigating starred docs --- app/components/Sidebar/components/CollectionLink.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/components/Sidebar/components/CollectionLink.js b/app/components/Sidebar/components/CollectionLink.js index 74513c7848..74e564d59a 100644 --- a/app/components/Sidebar/components/CollectionLink.js +++ b/app/components/Sidebar/components/CollectionLink.js @@ -3,6 +3,7 @@ import fractionalIndex from "fractional-index"; import { observer } from "mobx-react"; import * as React from "react"; import { useDrop, useDrag } from "react-dnd"; +import { useLocation } from "react-router-dom"; import styled from "styled-components"; import Collection from "models/Collection"; import Document from "models/Document"; @@ -36,6 +37,7 @@ function CollectionLink({ isDraggingAnyCollection, onChangeDragging, }: Props) { + const { search } = useLocation(); const [menuOpen, handleMenuOpen, handleMenuClose] = useBoolean(); const handleTitleChange = React.useCallback( @@ -52,12 +54,17 @@ function CollectionLink({ ); React.useEffect(() => { + // If we're viewing a starred document through the starred menu then don't + // touch the expanded / collapsed state of the collections + if (search === "?starred") { + return; + } if (isDraggingAnyCollection) { setExpanded(false); } else { setExpanded(collection.id === ui.activeCollectionId); } - }, [isDraggingAnyCollection, collection.id, ui.activeCollectionId]); + }, [isDraggingAnyCollection, collection.id, ui.activeCollectionId, search]); const manualSort = collection.sort.field === "index"; const can = policies.abilities(collection.id);