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: add topic editing
thecodrrdc8a986e6bc9
diff --git a/apps/web/src/components/dialogs/topicdialog.js b/apps/web/src/components/dialogs/topicdialog.jsindex f7d106341..b19150245 100644--- a/apps/web/src/components/dialogs/topicdialog.js+++ b/apps/web/src/components/dialogs/topicdialog.js@@ -1,4 +1,4 @@-import React, { useState } from "react";+import React, { useRef } from "react";import { Box } from "rebass";import { Input } from "@rebass/forms";import * as Icon from "../icons";@@ -7,7 +7,7 @@ import Dialog, { showDialog } from "./dialog";import { store } from "../../stores/notebook-store";function TopicDialog(props) {- const [topic, setTopic] = useState();+ const ref = useRef();return (<DialogisOpen={true}@@ -15,16 +15,18 @@ function TopicDialog(props) {icon={props.icon}positiveButton={{text: "Add",- onClick: props.onYes.bind(this, topic),+ onClick: () => {+ props.onYes(ref.current.value);+ },}}negativeButton={{ text: "Cancel", onClick: props.onNo }}><Box my={1}><Input+ autoFocus+ ref={ref}placeholder="Topic title"- onChange={(e) => {- setTopic(e.target.value);- }}+ defaultValue={props.topic && props.topic.title}></Input></Box></Dialog>@@ -48,3 +50,23 @@ export function showTopicDialog(notebook) {/>));}++export function showEditTopicDialog(topic) {+ return showDialog((perform) => (+ <TopicDialog+ title={"Topic"}+ icon={Icon.Topic}+ topic={topic}+ onNo={() => {+ perform(false);+ }}+ onYes={async (t) => {+ await db.notebooks+ .notebook(topic.notebookId)+ .topics.add({ ...topic, title: t });+ store.setSelectedNotebookTopics(topic.notebookId);+ perform(true);+ }}+ />+ ));+}diff --git a/apps/web/src/components/topic/index.js b/apps/web/src/components/topic/index.jsindex 9ff7a8fd9..dfbeadba5 100644--- a/apps/web/src/components/topic/index.js+++ b/apps/web/src/components/topic/index.js@@ -1,7 +1,15 @@import React from "react";import ListItem from "../list-item";+import { showEditTopicDialog } from "../dialogs/topicdialog";-const menuItems = [+const menuItems = (item) => [+ {+ title: "Edit",+ onClick: () => {+ showEditTopicDialog(item);+ },+ visible: item.title === "General",+ },{title: "Delete",color: "red",@@ -19,7 +27,7 @@ function Topic({ item, index, onClick }) {info={`${topic.totalNotes} Notes`}index={index}menuData={topic}- menuItems={menuItems}+ menuItems={menuItems(topic)}/>);}