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: improve move note to notebook dialog ux
thecodrr5093e7fa0248
diff --git a/apps/web/src/components/dialogs/move-note-dialog.js b/apps/web/src/components/dialogs/move-note-dialog.jsindex bb892bd93..4297a12cd 100644--- a/apps/web/src/components/dialogs/move-note-dialog.js+++ b/apps/web/src/components/dialogs/move-note-dialog.js@@ -8,7 +8,6 @@ import { showToast } from "../../utils/toast";import Field from "../field";class MoveDialog extends React.Component {- history = [];_inputRef;selectedNotebook;selectedTopic;@@ -27,6 +26,45 @@ class MoveDialog extends React.Component {}}+ async addTopic(notebook, input) {+ if (input.value.length > 0) {+ await db.notebooks.notebook(notebook).topics.add(input.value);+ this.setState({ notebooks: db.notebooks.all });+ input.value = "";+ }+ }++ _topicHasNotes(topic, noteIds) {+ return noteIds.some((id) => topic.notes.indexOf(id) > -1);+ }++ async _addNoteToTopic(notebook, topic) {+ const { noteIds, onMove, onClose } = this.props;+ if (this._topicHasNotes(topic, noteIds)) {+ await db.notebooks+ .notebook(topic.notebookId)+ .topics.topic(topic.id)+ .delete(...noteIds);+ this.setState({ notebooks: db.notebooks.all });+ return;+ }+ try {+ const nb = {+ id: notebook.id,+ topic: topic.id,+ };+ const note = db.notes.note(noteIds[0]).data;+ await db.notes.move(nb, ...noteIds);+ showNotesMovedToast(note, noteIds, nb);+ onMove();+ } catch (e) {+ showToast("error", e.message);+ console.error(e);+ } finally {+ onClose();+ }+ }+render() {const { notebooks, currentOpenedIndex } = this.state;const props = this.props;@@ -49,7 +87,8 @@ class MoveDialog extends React.Component {label="Notebooks"id="notebook-title"name="notebook-title"- helpText="Press enter to add a new notebook"+ helpText="Add a new notebook"+ placeholder="Press enter to add a new notebook"action={{onClick: async () => {await this.addNotebook(this.inputRef);@@ -77,11 +116,24 @@ class MoveDialog extends React.Component {icon={Icon.Notebook}title={notebook.title}totalNotes={notebook.totalNotes}- onClick={() =>+ onClick={(e) => {this.setState({currentOpenedIndex:this.state.currentOpenedIndex === index ? -1 : index,- })+ });+ }}+ action={+ currentOpenedIndex === index && (+ <Icon.Plus+ size={20}+ onClick={(e) => {+ e.stopPropagation();+ this.setState({+ isAddingTopic: true,+ });+ }}+ />+ )}/><Flex@@ -90,35 +142,47 @@ class MoveDialog extends React.Component {display: currentOpenedIndex === index ? "flex" : "none",}}>+ {this.state.isAddingTopic && (+ <Field+ autoFocus+ inputRef={(ref) => (this.inputRef = ref)}+ data-test-id="mnd-new-topic-title"+ id="topic-title"+ name="topic-title"+ placeholder="Press enter to add a topic"+ action={{+ onClick: () => {+ this.setState({+ isAddingTopic: false,+ });+ },+ icon: Icon.Close,+ }}+ onKeyUp={async (e) => {+ if (e.key === "Enter")+ await this.addTopic(notebook, e.target);+ }}+ />+ )}{notebook.topics.map((topic, topicIndex) => (<Itemdata-test-id={`notebook-${index}-topic-${topicIndex}`}key={topic.id}- onClick={async () => {- try {- const nb = {- id: notebook.id,- topic: topic.id,- };- const note = db.notes.note(props.noteIds[0]).data;- await db.notes.move(nb, ...props.noteIds);- showNotesMovedToast(note, props.noteIds, nb);- props.onMove();- } catch (e) {- showToast("error", e.message);- console.error(e);- } finally {- props.onClose();- }- }}+ onClick={() => this._addNoteToTopic(notebook, topic)}indent={1}icon={Icon.Topic}title={topic.title}totalNotes={topic.totalNotes}action={- <Text color="primary" fontSize="body">- Move here- </Text>+ this._topicHasNotes(topic, props.noteIds) ? (+ <Text color="error" fontSize="body">+ Remove from+ </Text>+ ) : (+ <Text color="primary" fontSize="body">+ Add to+ </Text>+ )}/>))}@@ -147,9 +211,10 @@ function Item(props) {return (<Flexdata-test-id={props["data-test-id"]}- p={2}+ p={1}justifyContent="space-between"alignItems="center"+ pr={2}pl={!indent ? 2 : indent * 30}sx={{borderWidth: 1,@@ -162,15 +227,14 @@ function Item(props) {><Flex alignItems="center" justifyContent="center"><Icon />- <Text as="span" ml={1} fontSize="body">- {title}- </Text>+ <Flex ml={1} flexDirection="column">+ <Text as="span" fontSize="body">+ {title}+ </Text>+ <Text variant="subBody">{totalNotes + " Notes"}</Text>+ </Flex></Flex>- {action || (- <Text sx={{ textAlign: "right" }} fontSize="body">- {totalNotes + " Notes"}- </Text>- )}+ {action}</Flex>);}diff --git a/apps/web/src/components/field/index.js b/apps/web/src/components/field/index.jsindex e48e3c419..3f2e68d8d 100644--- a/apps/web/src/components/field/index.js+++ b/apps/web/src/components/field/index.js@@ -19,6 +19,7 @@ function Field(props) {onChange,inputRef,defaultValue,+ placeholder,} = props;const [isPasswordVisible, setIsPasswordVisible] = useState(false);@@ -48,6 +49,7 @@ function Field(props) {required={required}name={name}id={id}+ placeholder={placeholder}autoComplete={autoComplete}type={type || "text"}onChange={onChange}@@ -85,15 +87,15 @@ function Field(props) {variant="rowCenter"sx={{position: "absolute",- right: 0,- top: 0,- bottom: 0,+ right: "2px",+ top: "2px",+ bottom: "2px",px: 1,borderRadius: "default",":hover": { bg: "border" },}}>- <action.icon />+ <action.icon size={20} /></Flex>)}</Flex>diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.jsindex a613812a8..f49265f89 100644--- a/apps/web/src/components/note/index.js+++ b/apps/web/src/components/note/index.js@@ -128,7 +128,9 @@ function Note(props) {const theme = useTheme();const color = useMemo(() => COLORS[note.color], [note.color]);const notebook = useMemo(- () => note.notebooks && db.notebooks.notebook(note.notebooks[0].id)?.data,+ () =>+ !!note.notebooks?.length &&+ db.notebooks.notebook(note.notebooks[0].id)?.data,[note.notebooks]);@@ -228,6 +230,7 @@ export default React.memo(Note, function (prevProps, nextProps) {prevItem.title === nextItem.title &&prevItem.locked === nextItem.locked &&prevItem.conflicted === nextItem.conflicted &&- prevItem.color === nextItem.color+ prevItem.color === nextItem.color &&+ prevItem.notebooks?.length === nextItem.notebooks?.length);});diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.jsindex 9b04f9512..aabda31ff 100644--- a/apps/web/src/stores/editor-store.js+++ b/apps/web/src/stores/editor-store.js@@ -6,10 +6,11 @@ import { db } from "../common";import BaseStore from ".";import { isMobile, isTablet } from "../utils/dimensions";import { getHashParam, setHashParam } from "../utils/useHashParam";+import { qclone } from "qclone";const SESSION_STATES = { stale: "stale", new: "new", locked: "locked" };const DEFAULT_SESSION = {- notebook: undefined,+ notebooks: undefined,state: undefined,isSaving: false,title: "",@@ -35,6 +36,8 @@ class EditorStore extends BaseStore {window.addEventListener("hashchange", async () => {const note = getHashParam("note");+ if (this.get().session.id === note) return;+if (isMobile() && !note && appStore.get().isEditorOpen) {return this.clearSession();}@@ -73,7 +76,7 @@ class EditorStore extends BaseStore {openSession = async (noteId) => {let note = db.notes.note(noteId);if (!note) return;- note = note.data;+ note = qclone(note.data);noteStore.setSelectedNote(note.id);diff --git a/apps/web/yarn.lock b/apps/web/yarn.lockindex 9e107ef12..3348a6274 100644--- a/apps/web/yarn.lock+++ b/apps/web/yarn.lock@@ -8964,7 +8964,7 @@ normalize-url@^3.0.0, normalize-url@^3.0.1:"notes-core@git+ssh://[email protected]:streetwriters/notesnook-core.git":version "4.3.0"- resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#70fa2cbebb0d3f445699ae8b1d6c6f371d16310e"+ resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#5399fc915ef2b8660c947c618b741d0ec1e5f54a"dependencies:fast-sort "^2.0.1"fuzzysearch "^1.0.3"