Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: add support for item drag/droping (#3230)

Muhammad Ali9798ada3356b
diff --git a/apps/web/src/common/drop-handler.ts b/apps/web/src/common/drop-handler.ts
new file mode 100644
index 000000000..89048061f
--- /dev/null
+++ b/apps/web/src/common/drop-handler.ts
@@ -0,0 +1,87 @@
+/*
+This file is part of the Notesnook project (https://notesnook.com/)
+
+Copyright (C) 2023 Streetwriters (Private) Limited
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+import { ItemReference } from "@notesnook/core";
+import { Context } from "../components/list-container/types";
+import { getDragData } from "../utils/data-transfer";
+import { db } from "./db";
+import { useStore as useNoteStore } from "../stores/note-store";
+import { useStore as useNotebookStore } from "../stores/notebook-store";
+import { useStore as useTagStore } from "../stores/tag-store";
+
+export async function handleDrop(
+ dataTransfer: DataTransfer,
+ item:
+ | ItemReference
+ | Context
+ | { type: "trash" | "notebooks" | "favorites" | undefined }
+) {
+ if (!item.type) return;
+
+ const noteIds = getDragData(dataTransfer, "note");
+ const notebookIds = getDragData(dataTransfer, "notebook");
+ const { setColor, favorite, delete: trashNotes } = useNoteStore.getState();
+ switch (item.type) {
+ case "notebook":
+ if (noteIds.length > 0) {
+ await db.notes?.addToNotebook(item.id, ...noteIds);
+ await useNoteStore.getState().refresh();
+ await useNotebookStore.getState().refresh();
+ } else if (notebookIds.length > 0) {
+ const breadcrumbs = await db.notebooks.breadcrumbs(item.id);
+ for (const notebookId of notebookIds) {
+ if (breadcrumbs.findIndex((b) => b.id === notebookId) > -1) continue;
+
+ await db.relations
+ .to({ type: "notebook", id: notebookId }, "notebook")
+ .unlink();
+ await db.relations.add(item, {
+ type: "notebook",
+ id: notebookId
+ });
+ }
+ await useNotebookStore.getState().refresh();
+ }
+ break;
+ case "color":
+ return setColor(item.id, false, ...noteIds);
+ case "favorites":
+ case "favorite":
+ return favorite(true, ...noteIds);
+ case "tag":
+ for (const noteId of noteIds) {
+ await db.relations.add(item, { type: "note", id: noteId });
+ }
+ await useNoteStore.getState().refresh();
+ await useTagStore.getState().refresh();
+ break;
+ case "trash":
+ trashNotes(...noteIds);
+ break;
+ case "notebooks":
+ if (notebookIds.length > 0) {
+ await db.relations
+ .to({ type: "notebook", ids: notebookIds }, "notebook")
+ .unlink();
+ await useNotebookStore.getState().refresh();
+ await useNoteStore.getState().refresh();
+ }
+ break;
+ }
+}
diff --git a/apps/web/src/components/field/index.tsx b/apps/web/src/components/field/index.tsx
index fffd41f40..21f1c0398 100644
--- a/apps/web/src/components/field/index.tsx
+++ b/apps/web/src/components/field/index.tsx
@@ -145,8 +145,10 @@ function Field(props: FieldProps) {
sx={{
bg: "transparent",
position: "absolute",
- right: "4px",
- top: "2px",
+ margin: 0,
+ top: 0,
+ right: "2px",
+ height: "100%",
px: 1,
borderRadius: "default",
":hover": { bg: "border" }
diff --git a/apps/web/src/components/list-container/index.tsx b/apps/web/src/components/list-container/index.tsx
index 83599fde4..c00b858e8 100644
--- a/apps/web/src/components/list-container/index.tsx
+++ b/apps/web/src/components/list-container/index.tsx
@@ -30,7 +30,6 @@ import Announcements from "../announcements";
import { ListLoader } from "../loaders/list-loader";
import ScrollContainer from "../scroll-container";
import { useKeyboardListNavigation } from "../../hooks/use-keyboard-list-navigation";
-import { Context } from "./types";
import { VirtualizedGrouping, GroupingKey, Item } from "@notesnook/core";
import {
ItemProps,
@@ -40,6 +39,7 @@ import {
} from "react-virtuoso";
import Skeleton from "react-loading-skeleton";
import { useResolvedItem } from "@notesnook/common";
+import { Context } from "./types";
export const CustomScrollbarsVirtualList = forwardRef<
HTMLDivElement,
@@ -65,6 +65,7 @@ type ListContainerProps = {
header?: JSX.Element;
placeholder: JSX.Element;
isLoading?: boolean;
+ onDrop?: (e: React.DragEvent<HTMLDivElement>) => void;
button?: {
onClick: () => void;
};
@@ -135,7 +136,12 @@ function ListContainer(props: ListContainerProps) {
});
return (
- <Flex variant="columnFill" sx={{ overflow: "hidden" }}>
+ <Flex
+ variant="columnFill"
+ sx={{ overflow: "hidden" }}
+ onDragOver={(e) => e.preventDefault()}
+ onDrop={props.onDrop}
+ >
{!props.items.length && props.placeholder ? (
<>
{header}
diff --git a/apps/web/src/components/list-item/index.tsx b/apps/web/src/components/list-item/index.tsx
index 6b8401a35..1f725d628 100644
--- a/apps/web/src/components/list-item/index.tsx
+++ b/apps/web/src/components/list-item/index.tsx
@@ -29,6 +29,7 @@ import { SchemeColors } from "@notesnook/theme";
import { MenuItem } from "@notesnook/ui";
import { alpha } from "@theme-ui/color";
import { Item } from "@notesnook/core/dist/types";
+import { setDragData } from "../../utils/data-transfer";
type ListItemProps<TItem extends Item, TContext> = {
colors?: {
@@ -41,10 +42,16 @@ type ListItemProps<TItem extends Item, TContext> = {
isDisabled?: boolean;
isSimple?: boolean;
item: TItem;
+ draggable?: boolean;
onKeyPress?: (e: React.KeyboardEvent<HTMLDivElement>) => void;
onClick?: () => void;
onSelect?: () => void;
+
+ onDragEnter?: (e: React.DragEvent<HTMLDivElement>) => void;
+ onDragLeave?: (e: React.DragEvent<HTMLDivElement>) => void;
+ onDrop?: (e: React.DragEvent<HTMLDivElement>) => void;
+
title: string | JSX.Element;
header?: JSX.Element;
body?: JSX.Element | string;
@@ -71,7 +78,11 @@ function ListItem<TItem extends Item, TContext>(
isSimple,
item,
sx,
- context
+ context,
+ onDragEnter,
+ onDragLeave,
+ onDrop,
+ draggable
} = props;
const listItemRef = useRef<HTMLDivElement>(null);
@@ -91,6 +102,21 @@ function ListItem<TItem extends Item, TContext>(
id={`id_${item.id}`}
className={isSelected ? "selected" : ""}
ref={listItemRef}
+ draggable={draggable}
+ onDragEnter={onDragEnter}
+ onDrop={onDrop}
+ onDragOver={(e) => e.preventDefault()}
+ onDragLeave={onDragLeave}
+ onDragEnd={onDragLeave}
+ onDragStart={(e) => {
+ if (!draggable) return;
+ let selectedItems = selectionStore.get().selectedItems;
+ if (selectedItems.findIndex((i) => i === item.id) === -1) {
+ selectedItems = [];
+ selectedItems.push(item.id);
+ }
+ setDragData(e.dataTransfer, item.type, selectedItems);
+ }}
onContextMenu={(e) => {
e.preventDefault();
e.stopPropagation();
diff --git a/apps/web/src/components/navigation-menu/index.tsx b/apps/web/src/components/navigation-menu/index.tsx
index 302eb7fa3..db867a68f 100644
--- a/apps/web/src/components/navigation-menu/index.tsx
+++ b/apps/web/src/components/navigation-menu/index.tsx
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import { useCallback, useEffect, useState } from "react";
+import { useCallback, useEffect, useRef, useState } from "react";
import { Box, Button, Flex } from "@theme-ui/components";
import {
Note,
@@ -65,11 +65,10 @@ import {
sortableKeyboardCoordinates,
verticalListSortingStrategy
} from "@dnd-kit/sortable";
-import { isUserPremium } from "../../hooks/use-is-user-premium";
-import { showToast } from "../../utils/toast";
import { usePersistentState } from "../../hooks/use-persistent-state";
import { MenuItem } from "@notesnook/ui";
import { Notebook, Tag } from "@notesnook/core";
+import { handleDrop } from "../../common/drop-handler";
type Route = {
id: string;
@@ -149,6 +148,7 @@ function NavigationMenu(props: NavigationMenuProps) {
"sidebarHiddenItems:colors",
db.settings.getSideBarHiddenItems("colors")
);
+ const dragTimeout = useRef(0);
const _navigate = useCallback(
(path: string) => {
@@ -261,6 +261,28 @@ function NavigationMenu(props: NavigationMenuProps) {
title={item.title}
icon={item.icon}
tag={item.tag}
+ onDragEnter={() => {
+ if (["/notebooks", "/tags"].includes(item.path))
+ dragTimeout.current = setTimeout(
+ () => _navigate(item.path),
+ 1000
+ ) as unknown as number;
+ }}
+ onDragLeave={() => clearTimeout(dragTimeout.current)}
+ onDrop={async (e) => {
+ clearTimeout(dragTimeout.current);
+
+ await handleDrop(e.dataTransfer, {
+ type:
+ item.path === "/trash"
+ ? "trash"
+ : item.path === "/favorites"
+ ? "favorites"
+ : item.path === "/notebooks"
+ ? "notebooks"
+ : undefined
+ });
+ }}
selected={
item.path === "/"
? location === item.path
@@ -311,6 +333,7 @@ function NavigationMenu(props: NavigationMenuProps) {
onClick={() => {
_navigate(`/colors/${color.id}`);
}}
+ onDrop={(e) => handleDrop(e.dataTransfer, color)}
menuItems={[
{
type: "button",
@@ -395,6 +418,7 @@ function NavigationMenu(props: NavigationMenuProps) {
}
isShortcut
selected={shouldSelectNavItem(location, item)}
+ onDrop={(e) => handleDrop(e.dataTransfer, item)}
onClick={async () => {
if (item.type === "notebook") {
const root = (await db.notebooks.breadcrumbs(item.id)).at(
diff --git a/apps/web/src/components/navigation-menu/navigation-item.tsx b/apps/web/src/components/navigation-menu/navigation-item.tsx
index 22022c9b7..326078a56 100644
--- a/apps/web/src/components/navigation-menu/navigation-item.tsx
+++ b/apps/web/src/components/navigation-menu/navigation-item.tsx
@@ -39,8 +39,6 @@ type NavigationItemProps = {
selected?: boolean;
onClick?: () => void;
count?: number;
- animate?: boolean;
- index?: number;
menuItems?: MenuItem[];
};
@@ -73,6 +71,10 @@ function NavigationItem(
<Flex
{...restProps}
ref={containerRef}
+ onDragOver={(e) => {
+ e.preventDefault();
+ e.currentTarget.focus();
+ }}
sx={{
...createButtonVariant(
selected ? "background-selected" : "transparent",
@@ -91,6 +93,7 @@ function NavigationItem(
position: "relative",
":first-of-type": { mt: 1 },
":last-of-type": { mb: 1 },
+ ":focus": { bg: selected ? "hover-selected" : "hover" },
...sx
// ":hover:not(:disabled)": {
// bg: "hover",
@@ -190,7 +193,14 @@ function NavigationItem(
export default NavigationItem;
export function SortableNavigationItem(
- props: PropsWithChildren<{ id: string } & NavigationItemProps>
+ props: PropsWithChildren<
+ {
+ id: string;
+ onDragEnter?: React.DragEventHandler<HTMLElement>;
+ onDragLeave?: React.DragEventHandler<HTMLElement>;
+ onDrop?: React.DragEventHandler<HTMLElement>;
+ } & NavigationItemProps
+ >
) {
const { id, ...restProps } = props;
const { attributes, listeners, setNodeRef, transform, transition, active } =
diff --git a/apps/web/src/components/note/index.tsx b/apps/web/src/components/note/index.tsx
index 4e494fca2..113edb0e1 100644
--- a/apps/web/src/components/note/index.tsx
+++ b/apps/web/src/components/note/index.tsx
@@ -117,6 +117,7 @@ function Note(props: NoteProps) {
return (
<ListItem
+ draggable={true}
isFocused={isOpened}
isCompact={compact}
isSimple={simplified}
diff --git a/apps/web/src/components/notebook/index.tsx b/apps/web/src/components/notebook/index.tsx
index dd218d05c..8dc482f6e 100644
--- a/apps/web/src/components/notebook/index.tsx
+++ b/apps/web/src/components/notebook/index.tsx
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import React from "react";
+import React, { useCallback, useRef } from "react";
import { Flex, Text } from "@theme-ui/components";
import ListItem from "../list-item";
import { useStore, store } from "../../stores/notebook-store";
@@ -42,6 +42,45 @@ import { confirm } from "../../common/dialog-controller";
import { getFormattedDate } from "@notesnook/common";
import { MenuItem } from "@notesnook/ui";
import { Notebook } from "@notesnook/core";
+import { handleDrop } from "../../common/drop-handler";
+
+function useDragHandler(id: string) {
+ const isDraggingOver = useRef(false);
+ const bounds = useRef<DOMRect>();
+
+ const isDragLeaving = useCallback((e: React.DragEvent) => {
+ if (
+ !isDraggingOver.current ||
+ !bounds.current ||
+ (e.clientX >= bounds.current.x &&
+ e.clientX <= bounds.current.right &&
+ e.clientY >= bounds.current.y &&
+ e.clientY <= bounds.current.bottom)
+ )
+ return false;
+
+ isDraggingOver.current = false;
+ bounds.current = undefined;
+ return true;
+ }, []);
+
+ const isDragEntering = useCallback(
+ (e: React.DragEvent) => {
+ if (
+ isDraggingOver.current ||
+ !(e.target instanceof HTMLElement) ||
+ (e.target.id !== id && !e.target.closest(`#${id}`))
+ )
+ return false;
+ isDraggingOver.current = true;
+ bounds.current = e.target.closest(`#${id}`)!.getBoundingClientRect();
+ return true;
+ },
+ [id]
+ );
+
+ return { isDragEntering, isDragLeaving };
+}
type NotebookProps = {
item: Notebook;
@@ -53,17 +92,32 @@ function Notebook(props: NotebookProps) {
const { item, totalNotes, date, simplified } = props;
const notebook = item;
const isCompact = useStore((store) => store.viewMode === "compact");
+ const dragTimeout = useRef(0);
+ const { isDragEntering, isDragLeaving } = useDragHandler(`id_${notebook.id}`);
return (
<ListItem
+ draggable
isCompact={isCompact}
isSimple={simplified}
item={notebook}
- onClick={async () => {
- await useNotesStore
- .getState()
- .setContext({ type: "notebook", id: notebook.id, item, totalNotes });
- navigate(`/notebooks/${notebook.id}`);
+ onClick={() => openNotebook(notebook, totalNotes)}
+ onDragEnter={(e) => {
+ if (!isDragEntering(e)) return;
+ e.currentTarget.focus();
+ dragTimeout.current = setTimeout(
+ () => openNotebook(notebook, totalNotes),
+ 1000
+ ) as unknown as number;
+ }}
+ onDragLeave={(e) => {
+ if (!isDragLeaving(e)) return;
+ clearTimeout(dragTimeout.current);
+ }}
+ onDrop={async (e) => {
+ clearTimeout(dragTimeout.current);
+
+ handleDrop(e.dataTransfer, notebook);
}}
title={notebook.title}
body={notebook.description as string}
@@ -213,3 +267,13 @@ export const notebookMenuItems: (
}
];
};
+
+async function openNotebook(notebook: Notebook, totalNotes?: number) {
+ await useNotesStore.getState().setContext({
+ type: "notebook",
+ id: notebook.id,
+ item: notebook,
+ totalNotes: totalNotes
+ });
+ navigate(`/notebooks/${notebook.id}`);
+}
diff --git a/apps/web/src/components/sub-notebook/index.tsx b/apps/web/src/components/sub-notebook/index.tsx
index af4517275..14d7c87ae 100644
--- a/apps/web/src/components/sub-notebook/index.tsx
+++ b/apps/web/src/components/sub-notebook/index.tsx
@@ -26,6 +26,9 @@ import { ChevronDown, ChevronRight, Plus } from "../icons";
import { MenuItem } from "@notesnook/ui";
import { showAddNotebookDialog } from "../../common/dialog-controller";
import { navigate } from "../../navigation";
+import { useCallback, useRef } from "react";
+import { getDragData } from "../../utils/data-transfer";
+import { handleDrop } from "../../common/drop-handler";
type SubNotebookProps = {
item: Notebook;
@@ -56,23 +59,43 @@ function SubNotebook(props: SubNotebookProps) {
(store) =>
store.context?.type === "notebook" && store.context.id === item.id
);
+ const dragTimeout = useRef(0);
+
+ const openNotebook = useCallback(async () => {
+ if (isOpened) return;
+ focus();
+ expand();
+ await useNotesStore.getState().setContext({
+ type: "notebook",
+ id: item.id,
+ item,
+ totalNotes
+ });
+ navigate(`/notebooks/${rootId}/${item.id}`);
+ }, [expand, focus, isOpened, item, rootId, totalNotes]);
return (
<ListItem
+ draggable
isFocused={isOpened}
isCompact
item={item}
- onClick={async () => {
- if (isOpened) return;
+ onClick={() => openNotebook()}
+ onDragEnter={(e) => {
+ e.currentTarget.focus();
focus();
- expand();
- await useNotesStore.getState().setContext({
- type: "notebook",
- id: item.id,
- item,
- totalNotes
- });
- navigate(`/notebooks/${rootId}/${item.id}`);
+
+ const noteIds = getDragData(e.dataTransfer, "note");
+ const notebookIds = getDragData(e.dataTransfer, "notebook");
+ dragTimeout.current = setTimeout(() => {
+ if (notebookIds.length > 0) expand();
+ else if (noteIds.length > 0) openNotebook();
+ }, 1000) as unknown as number;
+ }}
+ onDragLeave={() => clearTimeout(dragTimeout.current)}
+ onDrop={async (e) => {
+ clearTimeout(dragTimeout.current);
+ handleDrop(e.dataTransfer, item);
}}
onKeyPress={async (e) => {
if (e.code === "Space") {
diff --git a/apps/web/src/components/tag/index.tsx b/apps/web/src/components/tag/index.tsx
index b9179e17b..e4b961f24 100644
--- a/apps/web/src/components/tag/index.tsx
+++ b/apps/web/src/components/tag/index.tsx
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import ListItem from "../list-item";
-import { hashNavigate, navigate } from "../../navigation";
+import { navigate } from "../../navigation";
import { Text } from "@theme-ui/components";
import { store as appStore } from "../../stores/app-store";
import { store as tagStore } from "../../stores/tag-store";
@@ -31,6 +31,7 @@ import { pluralize } from "@notesnook/common";
import { MenuItem } from "@notesnook/ui";
import { Tag } from "@notesnook/core/dist/types";
import { showEditTagDialog } from "../../common/dialog-controller";
+import { handleDrop } from "../../common/drop-handler";
type TagProps = { item: Tag; totalNotes: number };
function Tag(props: TagProps) {
@@ -58,6 +59,10 @@ function Tag(props: TagProps) {
onClick={() => {
navigate(`/tags/${id}`);
}}
+ onDragEnter={(e) => {
+ e?.currentTarget.focus();
+ }}
+ onDrop={(e) => handleDrop(e.dataTransfer, item)}
/>
);
}
diff --git a/apps/web/src/utils/data-transfer.ts b/apps/web/src/utils/data-transfer.ts
new file mode 100644
index 000000000..271b23c85
--- /dev/null
+++ b/apps/web/src/utils/data-transfer.ts
@@ -0,0 +1,65 @@
+/*
+This file is part of the Notesnook project (https://notesnook.com/)
+
+Copyright (C) 2023 Streetwriters (Private) Limited
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+import { pluralize } from "@notesnook/common";
+import { tryParse } from "./parse";
+
+const DRAG_MIME_TYPE = "application/vnd.notesnook.items";
+export function setDragData(
+ dataTransfer: DataTransfer,
+ type: string,
+ ids: string[]
+) {
+ const dragImage = document.createElement("div");
+ dragImage.classList.add("theme-scope-base");
+ dragImage.style.position = "absolute";
+ dragImage.style.top = "-1000px";
+ dragImage.style.backgroundColor = "var(--background)";
+ dragImage.style.color = "var(--paragraph)";
+ dragImage.style.fontSize = "16px";
+ dragImage.style.border = "1px solid var(--border)";
+ dragImage.style.borderRadius = "5px";
+ dragImage.style.paddingLeft = "5px";
+ dragImage.style.paddingRight = "5px";
+
+ dragImage.textContent = pluralize(ids.length, "item");
+
+ document.body.appendChild(dragImage);
+ dataTransfer.setDragImage(dragImage, -10, 0);
+
+ dataTransfer.setData(DRAG_MIME_TYPE, JSON.stringify({ type: type, ids }));
+
+ setTimeout(() => {
+ dragImage.remove();
+ });
+}
+
+export function getDragData(
+ dataTransfer: DataTransfer,
+ type: string
+): string[] {
+ try {
+ const data = tryParse(dataTransfer.getData(DRAG_MIME_TYPE));
+ if (!data || data.type !== type || !data.ids) return [];
+ return data.ids;
+ } catch (e) {
+ console.error(e);
+ return [];
+ }
+}
diff --git a/apps/web/src/views/notebook.tsx b/apps/web/src/views/notebook.tsx
index 351b4c78b..c40500471 100644
--- a/apps/web/src/views/notebook.tsx
+++ b/apps/web/src/views/notebook.tsx
@@ -18,7 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { useCallback, useEffect, useRef, useState } from "react";
-import ListContainer from "../components/list-container";
import { useStore as useAppStore } from "../stores/app-store";
import { hashNavigate, navigate } from "../navigation";
import { Button, Flex, Text } from "@theme-ui/components";
@@ -29,18 +28,13 @@ import {
MoreHorizontal,
Notebook2,
RemoveShortcutLink,
- ShortcutLink,
- SortAsc
+ ShortcutLink
} from "../components/icons";
import { pluralize } from "@notesnook/common";
import { Allotment, AllotmentHandle } from "allotment";
import { Plus } from "../components/icons";
-import {
- notesFromContext,
- useStore as useNotesStore
-} from "../stores/note-store";
+import { useStore as useNotesStore } from "../stores/note-store";
import { useStore as useNotebookStore } from "../stores/notebook-store";
-import Placeholder from "../components/placeholders";
import { db } from "../common/db";
import { getFormattedDate } from "@notesnook/common";
import { showAddNotebookDialog } from "../common/dialog-controller";
@@ -56,7 +50,7 @@ import { NotebookContext } from "../components/list-container/types";
import { FlexScrollContainer } from "../components/scroll-container";
import { Menu } from "../hooks/use-menu";
import Config from "../utils/config";
-import { useSearch } from "../hooks/use-search";
+import Notes from "./notes";
// import { showSortMenu } from "../components/group-header";
type NotebookProps = {
@@ -72,17 +66,6 @@ function Notebook(props: NotebookProps) {
const context = useNotesStore((store) => store.context);
const notes = useNotesStore((store) => store.contextNotes);
- const refreshContext = useNotesStore((store) => store.refreshContext);
- const isCompact = useNotesStore((store) => store.viewMode === "compact");
- const filteredItems = useSearch(
- "notes",
- (query) => {
- if (!context || context.type !== "notebook") return;
- const notes = notesFromContext(context);
- return db.lookup.notes(query, notes).sorted();
- },
- [context, notes]
- );
useEffect(() => {
const { context, setContext } = useNotesStore.getState();
@@ -134,13 +117,7 @@ function Notebook(props: NotebookProps) {
>
<Allotment.Pane>
<Flex variant="columnFill" sx={{ height: "100%" }}>
- <ListContainer
- group="notes"
- refresh={refreshContext}
- compact={isCompact}
- context={context}
- items={filteredItems || notes}
- placeholder={<Placeholder context="notes" />}
+ <Notes
header={
<NotebookHeader
key={context.id}
@@ -148,13 +125,6 @@ function Notebook(props: NotebookProps) {
context={context}
/>
}
- button={{
- onClick: () =>
- hashNavigate("/notes/create", {
- addNonce: true,
- replace: true
- })
- }}
/>
</Flex>
</Allotment.Pane>
diff --git a/apps/web/src/views/notes.tsx b/apps/web/src/views/notes.tsx
index 6b8d3b5e9..680ef90eb 100644
--- a/apps/web/src/views/notes.tsx
+++ b/apps/web/src/views/notes.tsx
@@ -27,8 +27,11 @@ import { hashNavigate, navigate } from "../navigation";
import Placeholder from "../components/placeholders";
import { useSearch } from "../hooks/use-search";
import { db } from "../common/db";
+import { handleDrop } from "../common/drop-handler";
-function Notes() {
+type NotesProps = { header?: JSX.Element };
+function Notes(props: NotesProps) {
+ const { header } = props;
const context = useNotesStore((store) => store.context);
const contextNotes = useNotesStore((store) => store.contextNotes);
const refreshContext = useNotesStore((store) => store.refreshContext);
@@ -58,6 +61,7 @@ function Notes() {
compact={isCompact}
context={context}
items={filteredItems || contextNotes}
+ onDrop={(e) => handleDrop(e.dataTransfer, context)}
placeholder={
<Placeholder
context={
@@ -73,6 +77,7 @@ function Notes() {
onClick: () =>
hashNavigate("/notes/create", { addNonce: true, replace: true })
}}
+ header={header}
/>
);
}