diff --git a/docs/docs/changelog.md b/docs/docs/changelog.md index 6e0c699..c4b4521 100644 --- a/docs/docs/changelog.md +++ b/docs/docs/changelog.md @@ -35,6 +35,8 @@ default Obsidian theme. - Rebuilt the task renderer from the ground up. This now resembles Todoist more closely and has improved the default styling. - Added support for translations in the plugin +- Added a setting to control whether the embedded "Add task" button in a query should automatically add a link to the current page. + - This behaviour can now be turned off or configured to append to the task name or description. ### 🔁 Changes diff --git a/docs/docs/configuration.md b/docs/docs/configuration.md index 4668d05..f0e689c 100644 --- a/docs/docs/configuration.md +++ b/docs/docs/configuration.md @@ -49,6 +49,10 @@ When enabled, queries will render an icon accompanying the labels. When enabled, page links added to tasks created via the [command](./commands/add-task) will be wrapped in parenthesis. This may help identifying links if you primarily use Todoist on mobile platforms. +### Add task button adds page link + +When enabled, the embedded add task button in queries will add a link to the page to the task in the specified place. This behaviour can also be disabled completely. + ## Advanced ### Debug logging diff --git a/plugin/src/commands/index.ts b/plugin/src/commands/index.ts index 579cf2c..fa96f99 100644 --- a/plugin/src/commands/index.ts +++ b/plugin/src/commands/index.ts @@ -31,7 +31,7 @@ const commands = { "add-task-page-description": addTaskWithPageInDescription, }; -type CommandId = keyof typeof commands; +export type CommandId = keyof typeof commands; export const registerCommands = (plugin: TodoistPlugin) => { const i18n = t().commands; diff --git a/plugin/src/i18n/langs/en.ts b/plugin/src/i18n/langs/en.ts index 8b1ab2d..ea72e60 100644 --- a/plugin/src/i18n/langs/en.ts +++ b/plugin/src/i18n/langs/en.ts @@ -53,6 +53,16 @@ export const en: Translations = { description: "When enabled, wraps Obsidian page links in Todoist tasks created from the command", }, + addTaskButtonAddsPageLink: { + label: "Add task button adds page link", + description: + "When enabled, the embedded add task button in queries will add a link to the page to the task in the specified place", + options: { + off: "Disabled", + description: "Task description", + content: "Task name", + }, + }, }, advanced: { header: "Advanced", diff --git a/plugin/src/i18n/translation.ts b/plugin/src/i18n/translation.ts index b361695..0a2abde 100644 --- a/plugin/src/i18n/translation.ts +++ b/plugin/src/i18n/translation.ts @@ -50,6 +50,15 @@ export type Translations = { label: string; description: string; }; + addTaskButtonAddsPageLink: { + label: string; + description: string; + options: { + off: string; + description: string; + content: string; + }; + }; }; advanced: { header: string; diff --git a/plugin/src/settings.ts b/plugin/src/settings.ts index fd30774..c3b6e35 100644 --- a/plugin/src/settings.ts +++ b/plugin/src/settings.ts @@ -1,5 +1,7 @@ import { create } from "zustand"; +export type AddPageLinkSetting = "off" | "description" | "content"; + const defaultSettings: Settings = { fadeToggle: true, @@ -11,6 +13,7 @@ const defaultSettings: Settings = { renderLabelsIcon: true, shouldWrapLinksInParens: false, + addTaskButtonAddsPageLink: "content", debugLogging: false, }; @@ -27,6 +30,7 @@ export type Settings = { renderLabelsIcon: boolean; shouldWrapLinksInParens: boolean; + addTaskButtonAddsPageLink: AddPageLinkSetting; debugLogging: boolean; }; diff --git a/plugin/src/ui/query/QueryHeader.tsx b/plugin/src/ui/query/QueryHeader.tsx index 4d61cfb..7bc270c 100644 --- a/plugin/src/ui/query/QueryHeader.tsx +++ b/plugin/src/ui/query/QueryHeader.tsx @@ -1,10 +1,22 @@ -import { fireCommand } from "@/commands"; +import { type CommandId, fireCommand } from "@/commands"; +import { type Settings, useSettingsStore } from "@/settings"; import { ObsidianIcon } from "@/ui/components/obsidian-icon"; import { MarkdownEditButtonContext, PluginContext } from "@/ui/context"; import classNames from "classnames"; import type React from "react"; import { Button } from "react-aria-components"; +const getAddTaskCommandId = (settings: Settings): CommandId => { + switch (settings.addTaskButtonAddsPageLink) { + case "content": + return "add-task-page-content"; + case "description": + return "add-task-page-description"; + case "off": + return "add-task"; + } +}; + type Props = { title: string; isFetching: boolean; @@ -15,6 +27,8 @@ export const QueryHeader: React.FC = ({ title, isFetching, refresh }) => const plugin = PluginContext.use(); const { click: editBlock } = MarkdownEditButtonContext.use()(); + const settings = useSettingsStore(); + return (
{title} @@ -22,7 +36,7 @@ export const QueryHeader: React.FC = ({ title, isFetching, refresh }) => fireCommand("add-task-page-content", plugin)} + action={() => fireCommand(getAddTaskCommandId(settings), plugin)} /> = ({ value, onClick }) => { return
; }; +type DropdownOptionValue = OptionHTMLAttributes["value"]; + +type DropdownControlProps = { + value: T; + options: { label: string; value: T }[]; + onClick: (val: T) => Promise; +}; + +const DropdownControl = ({ + value, + options, + onClick, +}: DropdownControlProps): React.ReactNode => { + const [selected, setSelected] = useState(value); + + const onChange = async (ev: React.ChangeEvent) => { + const val = ev.target.value as T; + setSelected(val); + await onClick(val); + }; + + return ( + + ); +}; + export const Setting = { Root: Root, ButtonControl: ButtonControl, ToggleControl: ToggleControl, + DropdownControl: DropdownControl, }; diff --git a/plugin/src/ui/settings/index.tsx b/plugin/src/ui/settings/index.tsx index 0ddefba..a753245 100644 --- a/plugin/src/ui/settings/index.tsx +++ b/plugin/src/ui/settings/index.tsx @@ -153,6 +153,33 @@ const SettingsRoot: React.FC = ({ plugin }) => { > + + { + await plugin.writeOptions({ + addTaskButtonAddsPageLink: val, + }); + }} + /> +

{i18n.advanced.header}