fix: Double document highlight in sidebar (#2551)

* fix: Single highlighted doc when starred
closes #2544

* fix: Collection expand/collapse as navigating starred docs
This commit is contained in:
Tom Moor
2021-09-11 15:54:05 -07:00
committed by GitHub
parent f1c9c6fdf9
commit 2aca760ee0
4 changed files with 19 additions and 4 deletions

View File

@ -3,6 +3,7 @@ import fractionalIndex from "fractional-index";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import * as React from "react"; import * as React from "react";
import { useDrop, useDrag } from "react-dnd"; import { useDrop, useDrag } from "react-dnd";
import { useLocation } from "react-router-dom";
import styled from "styled-components"; import styled from "styled-components";
import Collection from "models/Collection"; import Collection from "models/Collection";
import Document from "models/Document"; import Document from "models/Document";
@ -36,6 +37,7 @@ function CollectionLink({
isDraggingAnyCollection, isDraggingAnyCollection,
onChangeDragging, onChangeDragging,
}: Props) { }: Props) {
const { search } = useLocation();
const [menuOpen, handleMenuOpen, handleMenuClose] = useBoolean(); const [menuOpen, handleMenuOpen, handleMenuClose] = useBoolean();
const handleTitleChange = React.useCallback( const handleTitleChange = React.useCallback(
@ -52,12 +54,17 @@ function CollectionLink({
); );
React.useEffect(() => { 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) { if (isDraggingAnyCollection) {
setExpanded(false); setExpanded(false);
} else { } else {
setExpanded(collection.id === ui.activeCollectionId); setExpanded(collection.id === ui.activeCollectionId);
} }
}, [isDraggingAnyCollection, collection.id, ui.activeCollectionId]); }, [isDraggingAnyCollection, collection.id, ui.activeCollectionId, search]);
const manualSort = collection.sort.field === "index"; const manualSort = collection.sort.field === "index";
const can = policies.abilities(collection.id); const can = policies.abilities(collection.id);

View File

@ -240,6 +240,9 @@ function DocumentLink(
/> />
</> </>
} }
isActive={(match, location) =>
match && location.search !== "?starred"
}
isActiveDrop={isOverReparent && canDropToReparent} isActiveDrop={isOverReparent && canDropToReparent}
depth={depth} depth={depth}
exact={false} exact={false}

View File

@ -8,7 +8,7 @@ import EventBoundary from "components/EventBoundary";
import NavLink from "./NavLink"; import NavLink from "./NavLink";
import { type Theme } from "types"; import { type Theme } from "types";
type Props = { type Props = {|
to?: string | Object, to?: string | Object,
href?: string | Object, href?: string | Object,
innerRef?: (?HTMLElement) => void, innerRef?: (?HTMLElement) => void,
@ -29,7 +29,7 @@ type Props = {
exact?: boolean, exact?: boolean,
depth?: number, depth?: number,
scrollIntoViewIfNeeded?: boolean, scrollIntoViewIfNeeded?: boolean,
}; |};
function SidebarLink( function SidebarLink(
{ {
@ -51,6 +51,7 @@ function SidebarLink(
match, match,
className, className,
scrollIntoViewIfNeeded, scrollIntoViewIfNeeded,
...rest
}: Props, }: Props,
ref ref
) { ) {
@ -86,6 +87,7 @@ function SidebarLink(
href={href} href={href}
className={className} className={className}
ref={ref} ref={ref}
{...rest}
> >
{icon && <IconWrapper>{icon}</IconWrapper>} {icon && <IconWrapper>{icon}</IconWrapper>}
<Label>{label}</Label> <Label>{label}</Label>

View File

@ -69,7 +69,10 @@ function StarredLink({ depth, title, to, documentId, collectionId }: Props) {
<Relative> <Relative>
<SidebarLink <SidebarLink
depth={depth} depth={depth}
to={to} to={`${to}?starred`}
isActive={(match, location) =>
match && location.search === "?starred"
}
label={ label={
<> <>
{hasChildDocuments && ( {hasChildDocuments && (