From 4b6b10794cf73af1fcac9864444bedd13df9fb5a Mon Sep 17 00:00:00 2001 From: thecodrr Date: Thu, 2 Dec 2021 12:12:42 +0500 Subject: [PATCH] feat: add header in notebook view --- apps/web/src/components/icons/index.js | 5 + .../src/components/list-container/index.js | 15 ++- .../src/components/route-container/index.js | 104 +++++++++--------- apps/web/src/navigation/routes.js | 6 - apps/web/src/views/topics.js | 70 +++++++++++- 5 files changed, 133 insertions(+), 67 deletions(-) diff --git a/apps/web/src/components/icons/index.js b/apps/web/src/components/icons/index.js index 84f57c8fb..cb7f24fa9 100644 --- a/apps/web/src/components/icons/index.js +++ b/apps/web/src/components/icons/index.js @@ -123,6 +123,8 @@ import { mdiFirefox, mdiAppleSafari, mdiBugOutline, + mdiLinkVariant, + mdiLinkVariantOff, } from "@mdi/js"; import { useTheme } from "emotion-theming"; import { AnimatedFlex } from "../animated"; @@ -149,6 +151,7 @@ function createIcon(name, rotate = false) { const [isHovering, setIsHovering] = useState(); return ( ListProfiles[type], [type]); const shouldSelectAll = useSelectionStore((store) => store.shouldSelectAll); @@ -27,9 +27,12 @@ function ListContainer(props) { return ( {!props.items.length && props.placeholder ? ( - - {props.isLoading ? : } - + <> + {header} + + {props.isLoading ? : } + + ) : ( <> @@ -43,7 +46,9 @@ function ListContainer(props) { components={{ Scroller: CustomScrollbarsVirtualList, Header: () => - announcements.length ? ( + header ? ( + header + ) : announcements.length ? ( store.toggleSelectionMode ); - if (!title && !subtitle) return null; + // if (!subtitle) return null; return ( @@ -75,11 +75,14 @@ function Header(props) { size={30} /> )} - + {title && ( + + )} {!isSelectionMode && ( @@ -111,18 +114,6 @@ function Header(props) { )} - {subtitle && ( - - {subtitle} - - )} {isSelectionMode && ( { @@ -173,45 +164,48 @@ function RouteTitle({ title, isEditable, onChange }) { }, [title]); return ( - + {subtitle && {subtitle}} + { - setIsEditing(isEditable && true); - e.target.focus(); - }} - onKeyUp={(e) => { - if (e.key === "Escape") { - e.target.value = title; - setIsEditing(false); - } else if (e.key === "Enter") { + ":focus-visible": { outline: "none" }, + }} + onDoubleClick={(e) => { + setIsEditing(isEditable && true); + e.target.focus(); + }} + onKeyUp={(e) => { + if (e.key === "Escape") { + e.target.value = title; + setIsEditing(false); + } else if (e.key === "Enter") { + if (onChange) onChange(e.target.value); + setIsEditing(false); + } + }} + onBlur={(e) => { if (onChange) onChange(e.target.value); setIsEditing(false); - } - }} - onBlur={(e) => { - if (onChange) onChange(e.target.value); - setIsEditing(false); - }} - readOnly={!isEditing} - /> + }} + readOnly={!isEditing} + /> + ); } diff --git a/apps/web/src/navigation/routes.js b/apps/web/src/navigation/routes.js index aade74832..ea2e41d47 100644 --- a/apps/web/src/navigation/routes.js +++ b/apps/web/src/navigation/routes.js @@ -44,12 +44,6 @@ const routes = { return { key: "topics", type: "topics", - title: notebook.title, - isEditable: true, - onChange: (title) => { - db.notebooks.add({ id: notebookId, title }); - showToast("success", "Notebook title updated!"); - }, component: , buttons: { back: { diff --git a/apps/web/src/views/topics.js b/apps/web/src/views/topics.js index b0ddf78bd..e1ba9e03b 100644 --- a/apps/web/src/views/topics.js +++ b/apps/web/src/views/topics.js @@ -1,8 +1,14 @@ -import React from "react"; +import React, { useEffect, useState } from "react"; import ListContainer from "../components/list-container"; import { useStore as useNbStore } from "../stores/notebook-store"; +import { useStore as useAppStore } from "../stores/app-store"; import { hashNavigate } from "../navigation"; import TopicsPlaceholder from "../components/placeholders/topics-placeholder"; +import { Button, Flex, Text } from "rebass"; +import { Edit, RemoveShortcutLink, ShortcutLink } from "../components/icons"; +import { getTotalNotes } from "../common"; +import { formatDate } from "notes-core/utils/date"; +import { db } from "../common/db"; function Topics() { const selectedNotebookTopics = useNbStore( @@ -20,6 +26,11 @@ function Topics() { items={selectedNotebookTopics} context={{ notebookId: selectedNotebookId }} placeholder={TopicsPlaceholder} + header={ + + } button={{ content: "Add a new topic", onClick: () => hashNavigate(`/topics/create`), @@ -29,3 +40,60 @@ function Topics() { ); } export default Topics; + +function NotebookHeader({ notebook }) { + const { title, description, topics, dateEdited } = notebook; + const [isShortcut, setIsShortcut] = useState(false); + const menuPins = useAppStore((store) => store.menuPins); + const pinItemToMenu = useAppStore((store) => store.pinItemToMenu); + useEffect(() => { + setIsShortcut(menuPins.findIndex((p) => p.id === notebook.id) > -1); + }, [menuPins, notebook]); + + return ( + + {formatDate(dateEdited)} + + {title} + + + + + + + {description && ( + + {description} + + )} + + {topics.length} topic, {getTotalNotes(notebook)} notes + + + ); +}