mirror of
https://github.com/outline/outline.git
synced 2026-11-29 00:29:36 +03:00
* Allow dragging documents from list views into the sidebar Previously the react-dnd provider was scoped to the sidebar, so only sidebar rows could be dragged. This lifts the DndProvider up to the authenticated layout so both the main content and the sidebar share a single drag-and-drop context, and makes DocumentListItem a drag source. Now any document in search results or paginated lists (Home, Drafts, Collections, etc.) can be dragged into the sidebar to move it between collections, reparent it under another document, star it, or archive it — reusing the existing sidebar drop targets. * Make the whole Starred section a drop target to star documents Previously the only "create star" drop targets in the Starred section were the thin cursors between items, so dragging a document onto the section header or a starred row showed the drop cursor but did nothing. Wrap the section in a catch-all drop target (mirroring the Archive section) so dropping anywhere in Starred stars the document, while the precise inter-item cursors still control ordering. A didDrop guard on useDropToCreateStar prevents the catch-all from double-starring when a nested cursor already handled the drop, and the hover highlight uses a shallow isOver check so it only lights up when not over a nested target. * Let document list drag ghost follow the cursor The sidebar drag placeholder tethers the ghost near its starting x so it stays aligned with the sidebar during reordering. When a drag starts out in the main content (a document list item), that clamp pinned the ghost to a narrow band, making it look stuck in a small area. Thread a constrainToSidebar flag through the drag item (true for sidebar drags, false for document list drags) and let the placeholder follow the cursor freely when the drag originated outside the sidebar. * Clarify constrainToSidebar JSDoc to match placeholder behavior The placeholder treats an unset flag as tethered (constrainToSidebar !== false), so external drags must set it explicitly to false rather than leaving it unset. Update the comment to reflect that. * css
158 lines
5.2 KiB
TypeScript
158 lines
5.2 KiB
TypeScript
import { observer } from "mobx-react";
|
|
import { SearchIcon, HomeIcon, SidebarIcon } from "outline-icons";
|
|
import { useEffect, useState, useCallback, useRef } from "react";
|
|
import {
|
|
DragActiveProvider,
|
|
SidebarScrollProvider,
|
|
} from "./components/DragActiveContext";
|
|
import { useTranslation } from "react-i18next";
|
|
import { useHistory } from "react-router-dom";
|
|
import styled from "styled-components";
|
|
import { metaDisplay } from "@shared/utils/keyboard";
|
|
import Scrollable from "~/components/Scrollable";
|
|
import { inviteUser } from "~/actions/definitions/users";
|
|
import useCurrentTeam from "~/hooks/useCurrentTeam";
|
|
import useCurrentUser from "~/hooks/useCurrentUser";
|
|
import usePolicy from "~/hooks/usePolicy";
|
|
import useStores from "~/hooks/useStores";
|
|
import TeamMenu from "~/menus/TeamMenu";
|
|
import { homePath, searchPath } from "~/utils/routeHelpers";
|
|
import TeamLogo from "../TeamLogo";
|
|
import Tooltip from "../Tooltip";
|
|
import Sidebar from "./Sidebar";
|
|
import ArchiveLink from "./components/ArchiveLink";
|
|
import Collections from "./components/Collections";
|
|
import { DraftsLink } from "./components/DraftsLink";
|
|
import DragPlaceholder from "./components/DragPlaceholder";
|
|
import HistoryNavigation from "./components/HistoryNavigation";
|
|
import Section from "./components/Section";
|
|
import SharedWithMe from "./components/SharedWithMe";
|
|
import SidebarAction from "./components/SidebarAction";
|
|
import SidebarButton from "./components/SidebarButton";
|
|
import SidebarLink from "./components/SidebarLink";
|
|
import Starred from "./components/Starred";
|
|
import ToggleButton from "./components/ToggleButton";
|
|
import TrashLink from "./components/TrashLink";
|
|
import useMobile from "~/hooks/useMobile";
|
|
|
|
function AppSidebar() {
|
|
const { t } = useTranslation();
|
|
const { documents, ui, collections } = useStores();
|
|
const team = useCurrentTeam();
|
|
const user = useCurrentUser();
|
|
const can = usePolicy(team);
|
|
const history = useHistory();
|
|
const isMobile = useMobile();
|
|
|
|
const handleSearchClick = useCallback(() => {
|
|
const basePath = searchPath();
|
|
const { pathname, search } = history.location;
|
|
if (pathname.startsWith(basePath) && (search || pathname !== basePath)) {
|
|
history.push(basePath);
|
|
}
|
|
}, [history]);
|
|
|
|
useEffect(() => {
|
|
void collections.fetchAll();
|
|
|
|
if (!user.isViewer) {
|
|
void documents.fetchDrafts();
|
|
}
|
|
}, [documents, collections, user.isViewer]);
|
|
|
|
// Scrollable reads ref.current internally for its shadow/ResizeObserver
|
|
// logic, so we must pass an object ref — a callback ref would leave those
|
|
// reads undefined. We mirror the attached node into state so the
|
|
// SidebarScrollProvider can re-render descendants with the scroll element.
|
|
const scrollRef = useRef<HTMLDivElement>(null);
|
|
const [scrollArea, setScrollArea] = useState<HTMLElement | null>(null);
|
|
useEffect(() => {
|
|
setScrollArea(scrollRef.current);
|
|
}, []);
|
|
|
|
return (
|
|
<Sidebar hidden={!ui.readyToShow}>
|
|
<DragActiveProvider>
|
|
<DragPlaceholder />
|
|
|
|
<TeamMenu>
|
|
<SidebarButton
|
|
title={team.name}
|
|
image={<TeamLogo model={team} size={24} alt={t("Logo")} />}
|
|
>
|
|
{isMobile ? null : (
|
|
<Tooltip
|
|
content={t("Toggle sidebar")}
|
|
shortcut={`${metaDisplay}+.`}
|
|
>
|
|
<ToggleButton
|
|
position="bottom"
|
|
image={<SidebarIcon />}
|
|
aria-label={
|
|
ui.sidebarCollapsed
|
|
? t("Expand sidebar")
|
|
: t("Collapse sidebar")
|
|
}
|
|
style={{ paddingInline: 4 }}
|
|
onClick={() => {
|
|
ui.toggleCollapsedSidebar();
|
|
(document.activeElement as HTMLElement)?.blur();
|
|
}}
|
|
/>
|
|
</Tooltip>
|
|
)}
|
|
</SidebarButton>
|
|
</TeamMenu>
|
|
<Overflow>
|
|
<Section>
|
|
<SidebarLink
|
|
to={homePath()}
|
|
icon={<HomeIcon />}
|
|
exact={false}
|
|
label={t("Home")}
|
|
/>
|
|
<SidebarLink
|
|
to={searchPath()}
|
|
icon={<SearchIcon />}
|
|
label={t("Search")}
|
|
exact={false}
|
|
onClick={handleSearchClick}
|
|
/>
|
|
{can.createDocument && <DraftsLink />}
|
|
</Section>
|
|
</Overflow>
|
|
<Scrollable flex shadow ref={scrollRef}>
|
|
<SidebarScrollProvider value={scrollArea}>
|
|
<Section>
|
|
<Starred />
|
|
</Section>
|
|
<Section>
|
|
<SharedWithMe />
|
|
</Section>
|
|
<Section>
|
|
<Collections />
|
|
</Section>
|
|
{can.createDocument && (
|
|
<Section auto>
|
|
<ArchiveLink />
|
|
</Section>
|
|
)}
|
|
<Section>
|
|
{can.createDocument && <TrashLink />}
|
|
<SidebarAction action={inviteUser} />
|
|
</Section>
|
|
</SidebarScrollProvider>
|
|
</Scrollable>
|
|
</DragActiveProvider>
|
|
<HistoryNavigation />
|
|
</Sidebar>
|
|
);
|
|
}
|
|
|
|
const Overflow = styled.div`
|
|
overflow: hidden;
|
|
flex-shrink: 0;
|
|
`;
|
|
|
|
export default observer(AppSidebar);
|