From 0f20a17cb4c4d18551d63337ff3deed23defc952 Mon Sep 17 00:00:00 2001 From: Trang Doan Date: Tue, 20 May 2025 11:36:57 -0400 Subject: [PATCH 1/5] test hiding fm setting --- .../src/components/FrontmatterSettings.tsx | 107 ++++++++++++++++++ apps/obsidian/src/components/Settings.tsx | 11 ++ 2 files changed, 118 insertions(+) create mode 100644 apps/obsidian/src/components/FrontmatterSettings.tsx diff --git a/apps/obsidian/src/components/FrontmatterSettings.tsx b/apps/obsidian/src/components/FrontmatterSettings.tsx new file mode 100644 index 000000000..507dc7428 --- /dev/null +++ b/apps/obsidian/src/components/FrontmatterSettings.tsx @@ -0,0 +1,107 @@ +import React, { useState } from "react"; +import { usePlugin } from "./PluginContext"; +import { Notice } from "obsidian"; + +const FrontmatterSettings = () => { + const plugin = usePlugin(); + const [hiddenKeys, setHiddenKeys] = useState( + () => plugin.settings.hiddenFrontmatterKeys || [], + ); + const [newKey, setNewKey] = useState(""); + const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false); + + const handleAddKey = () => { + if (!newKey.trim()) return; + + if (hiddenKeys.includes(newKey.trim())) { + new Notice(`Key "${newKey}" is already in the list`); + return; + } + + const updatedKeys = [...hiddenKeys, newKey.trim()]; + setHiddenKeys(updatedKeys); + setNewKey(""); + setHasUnsavedChanges(true); + }; + + const handleRemoveKey = (keyToRemove: string) => { + const updatedKeys = hiddenKeys.filter((key) => key !== keyToRemove); + setHiddenKeys(updatedKeys); + setHasUnsavedChanges(true); + }; + + const handleSave = async () => { + plugin.settings.hiddenFrontmatterKeys = hiddenKeys; + await plugin.saveSettings(); + new Notice("Frontmatter settings saved"); + setHasUnsavedChanges(false); + }; + + return ( +
+

Hidden Frontmatter Keys

+

+ Frontmatter keys in this list will be hidden from view +

+ +
+
+ setNewKey(e.target.value)} + className="flex-1" + /> + +
+
+ + {hiddenKeys.length > 0 ? ( +
+ {hiddenKeys.map((key) => ( +
+
+ {key} + +
+
+ ))} +
+ ) : ( +
+
+ No hidden keys. All frontmatter will be visible. +
+
+ )} + +
+ +
+ + {hasUnsavedChanges && ( +
You have unsaved changes
+ )} +
+ ); +}; + +export default FrontmatterSettings; diff --git a/apps/obsidian/src/components/Settings.tsx b/apps/obsidian/src/components/Settings.tsx index 437f7f2cd..35f683442 100644 --- a/apps/obsidian/src/components/Settings.tsx +++ b/apps/obsidian/src/components/Settings.tsx @@ -57,12 +57,23 @@ const Settings = () => { > Discourse Relations + {activeTab === "general" && } {activeTab === "nodeTypes" && } {activeTab === "relationTypes" && } {activeTab === "relations" && } + {activeTab === "frontmatter" && } ); }; From f150260b8c84a7ac30621f7f758af5233197bf5a Mon Sep 17 00:00:00 2001 From: Trang Doan Date: Thu, 5 Jun 2025 14:45:58 -0400 Subject: [PATCH 2/5] cur progress --- .../src/components/FrontmatterSettings.tsx | 107 ------------------ apps/obsidian/src/components/Settings.tsx | 10 -- 2 files changed, 117 deletions(-) delete mode 100644 apps/obsidian/src/components/FrontmatterSettings.tsx diff --git a/apps/obsidian/src/components/FrontmatterSettings.tsx b/apps/obsidian/src/components/FrontmatterSettings.tsx deleted file mode 100644 index 507dc7428..000000000 --- a/apps/obsidian/src/components/FrontmatterSettings.tsx +++ /dev/null @@ -1,107 +0,0 @@ -import React, { useState } from "react"; -import { usePlugin } from "./PluginContext"; -import { Notice } from "obsidian"; - -const FrontmatterSettings = () => { - const plugin = usePlugin(); - const [hiddenKeys, setHiddenKeys] = useState( - () => plugin.settings.hiddenFrontmatterKeys || [], - ); - const [newKey, setNewKey] = useState(""); - const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false); - - const handleAddKey = () => { - if (!newKey.trim()) return; - - if (hiddenKeys.includes(newKey.trim())) { - new Notice(`Key "${newKey}" is already in the list`); - return; - } - - const updatedKeys = [...hiddenKeys, newKey.trim()]; - setHiddenKeys(updatedKeys); - setNewKey(""); - setHasUnsavedChanges(true); - }; - - const handleRemoveKey = (keyToRemove: string) => { - const updatedKeys = hiddenKeys.filter((key) => key !== keyToRemove); - setHiddenKeys(updatedKeys); - setHasUnsavedChanges(true); - }; - - const handleSave = async () => { - plugin.settings.hiddenFrontmatterKeys = hiddenKeys; - await plugin.saveSettings(); - new Notice("Frontmatter settings saved"); - setHasUnsavedChanges(false); - }; - - return ( -
-

Hidden Frontmatter Keys

-

- Frontmatter keys in this list will be hidden from view -

- -
-
- setNewKey(e.target.value)} - className="flex-1" - /> - -
-
- - {hiddenKeys.length > 0 ? ( -
- {hiddenKeys.map((key) => ( -
-
- {key} - -
-
- ))} -
- ) : ( -
-
- No hidden keys. All frontmatter will be visible. -
-
- )} - -
- -
- - {hasUnsavedChanges && ( -
You have unsaved changes
- )} -
- ); -}; - -export default FrontmatterSettings; diff --git a/apps/obsidian/src/components/Settings.tsx b/apps/obsidian/src/components/Settings.tsx index 35f683442..e87d527b9 100644 --- a/apps/obsidian/src/components/Settings.tsx +++ b/apps/obsidian/src/components/Settings.tsx @@ -57,16 +57,6 @@ const Settings = () => { > Discourse Relations - {activeTab === "general" && } From 23d1865425c7be1e72c238c73fd8d372a6119811 Mon Sep 17 00:00:00 2001 From: Trang Doan Date: Thu, 5 Jun 2025 17:47:44 -0400 Subject: [PATCH 3/5] feature finished --- .../src/components/GeneralSettings.tsx | 27 ++++++++++++ .../obsidian/src/components/NodeTypeModal.tsx | 7 ++-- apps/obsidian/src/constants.ts | 1 + apps/obsidian/src/index.ts | 2 +- apps/obsidian/src/types.ts | 1 + .../src/utils/createNodeFromSelectedText.ts | 42 ++++++++++++++----- apps/obsidian/src/utils/registerCommands.ts | 2 +- 7 files changed, 66 insertions(+), 16 deletions(-) diff --git a/apps/obsidian/src/components/GeneralSettings.tsx b/apps/obsidian/src/components/GeneralSettings.tsx index 632c6ca21..26871e6b4 100644 --- a/apps/obsidian/src/components/GeneralSettings.tsx +++ b/apps/obsidian/src/components/GeneralSettings.tsx @@ -7,6 +7,9 @@ const GeneralSettings = () => { const [showIdsInFrontmatter, setShowIdsInFrontmatter] = useState( plugin.settings.showIdsInFrontmatter, ); + const [nodesFolderPath, setNodesFolderPath] = useState( + plugin.settings.nodesFolderPath, + ); const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false); const handleToggleChange = (newValue: boolean) => { @@ -14,8 +17,14 @@ const GeneralSettings = () => { setHasUnsavedChanges(true); }; + const handleFolderPathChange = (newValue: string) => { + setNodesFolderPath(newValue); + setHasUnsavedChanges(true); + }; + const handleSave = async () => { plugin.settings.showIdsInFrontmatter = showIdsInFrontmatter; + plugin.settings.nodesFolderPath = nodesFolderPath; await plugin.saveSettings(); new Notice("General settings saved"); setHasUnsavedChanges(false); @@ -43,6 +52,24 @@ const GeneralSettings = () => { +
+
+
Discourse nodes folder path
+
+ Specify the folder where new Discourse nodes should be created. + Leave empty to create nodes in the root folder. +
+
+
+ handleFolderPathChange(e.target.value)} + placeholder="Discourse Nodes" + /> +
+
+