A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
feat: allow editing topics & notebooks from inside
thecodrr6df7caa0e413
diff --git a/apps/web/src/components/cached-router/index.js b/apps/web/src/components/cached-router/index.jsindex 175b0a339..7f628757a 100644--- a/apps/web/src/components/cached-router/index.js+++ b/apps/web/src/components/cached-router/index.js@@ -54,6 +54,8 @@ function CachedRouter() {title={RouteResult?.title}subtitle={RouteResult?.subtitle}buttons={RouteResult?.buttons}+ isEditable={RouteResult?.isEditable}+ onChange={RouteResult?.onChange}/>);}diff --git a/apps/web/src/components/route-container/index.js b/apps/web/src/components/route-container/index.jsindex 5082d5fa4..031e56f56 100644--- a/apps/web/src/components/route-container/index.js+++ b/apps/web/src/components/route-container/index.js@@ -1,4 +1,4 @@-import React from "react";+import React, { useEffect, useRef, useState } from "react";import { Flex, Text } from "rebass";import * as Icon from "../icons";import { useStore } from "../../stores/app-store";@@ -6,12 +6,29 @@ import { useStore as useSelectionStore } from "../../stores/selection-store";import { CREATE_BUTTON_MAP, SELECTION_OPTIONS_MAP } from "../../common";import useMobile from "../../utils/use-mobile";import { navigate } from "../../navigation";+import { Input } from "@rebass/forms";function RouteContainer(props) {- const { id, type, title, subtitle, buttons, component } = props;+ const {+ id,+ type,+ title,+ isEditable,+ onChange,+ subtitle,+ buttons,+ component,+ } = props;return (<>- <Header type={type} title={title} subtitle={subtitle} buttons={buttons} />+ <Header+ type={type}+ title={title}+ subtitle={subtitle}+ buttons={buttons}+ isEditable={isEditable}+ onChange={onChange}+ />{component || <Flex id={id} flexDirection="column" flex={1} />}</>);@@ -20,7 +37,7 @@ function RouteContainer(props) {export default RouteContainer;function Header(props) {- const { title, subtitle, buttons, type } = props;+ const { title, subtitle, onChange, buttons, type, isEditable } = props;const createButtonData = CREATE_BUTTON_MAP[type];const toggleSideMenu = useStore((store) => store.toggleSideMenu);const isMobile = useMobile();@@ -58,13 +75,15 @@ function Header(props) {size={30}/>)}- <Text variant="heading" data-test-id="routeHeader" color={"text"}>- {title}- </Text>+ <RouteTitle+ title={title}+ isEditable={isEditable}+ onChange={onChange}+ /></Flex><SelectionOptions options={SELECTION_OPTIONS_MAP[type]} />{!isSelectionMode && (- <Flex>+ <Flex flexShrink={0}>{buttons?.search && (<Icon.Searchsize={24}@@ -107,9 +126,7 @@ function Header(props) {{isSelectionMode && (<Flexmb={2}- sx={{- cursor: "pointer",- }}+ notebookalignItems="center"onClick={() => {if (shouldSelectAll) toggleSelectionMode(false);@@ -146,3 +163,54 @@ function SelectionOptions(props) {</Flex>);}++function RouteTitle({ title, isEditable, onChange }) {+ const [isEditing, setIsEditing] = useState(false);+ const ref = useRef();+ useEffect(() => {+ ref.current.value = title;+ }, [title]);++ return (+ <Input+ ref={ref}+ variant="heading"+ data-test-id="routeHeader"+ color={"text"}+ title={title}+ sx={{+ overflow: "hidden",+ textOverflow: isEditing ? "initial" : "ellipsis",+ whiteSpace: "nowrap",++ p: 0,+ m: 0,+ fontWeight: "bold",+ fontFamily: "heading",+ fontSize: "heading",+ border: "none",+ bg: isEditing ? "bgSecondary" : "transparent",++ ":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);+ }}+ readOnly={!isEditing}+ />+ );+}diff --git a/apps/web/src/navigation/routes.js b/apps/web/src/navigation/routes.jsindex 253c85619..d69a9ba40 100644--- a/apps/web/src/navigation/routes.js+++ b/apps/web/src/navigation/routes.js@@ -12,6 +12,7 @@ import Trash from "../views/trash";import { store as notestore } from "../stores/note-store";import { store as nbstore } from "../stores/notebook-store";import Monographs from "../views/monographs";+import { showToast } from "../utils/toast";const routes = {"/": () => ({@@ -44,6 +45,11 @@ const routes = {key: "topics",type: "topics",title: notebook.title,+ isEditable: true,+ onChange: (title) => {+ db.notebooks.add({ id: notebookId, title });+ showToast("success", "Notebook title updated!");+ },component: <Topics />,buttons: {back: {@@ -67,8 +73,13 @@ const routes = {return {key: "notes",type: "notes",- title: notebook.title,- subtitle: topic.title,+ title: topic.title,+ subtitle: notebook.title,+ isEditable: true,+ onChange: (title) => {+ db.notebooks.notebook(notebookId).topics.add({ ...topic, title });+ showToast("success", "Topic title updated!");+ },component: <Notes />,buttons: {back: {