Skip to content

Commit

Permalink
feat: add setting to control task status on creation
Browse files Browse the repository at this point in the history
Resolves #449
  • Loading branch information
ivan-lednev committed Sep 2, 2024
1 parent 0d4ded1 commit 2efd462
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface DayPlannerSettings {
icals: Array<IcalConfig>;
colorOverrides: Array<ColorOverride>;
releaseNotes: boolean;
taskStatusOnCreation: string;
}

export const defaultSettings: DayPlannerSettings = {
Expand Down Expand Up @@ -77,6 +78,7 @@ export const defaultSettings: DayPlannerSettings = {
icals: [],
colorOverrides: [],
releaseNotes: true,
taskStatusOnCreation: " ",
};

export const defaultSettingsForTests = {
Expand Down
9 changes: 8 additions & 1 deletion src/ui/hooks/use-edit/create-edit-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getDateFromPath } from "obsidian-daily-notes-interface";
import { get, Readable, Writable } from "svelte/store";

import { ObsidianFacade } from "../../../service/obsidian-facade";
import { DayPlannerSettings } from "../../../settings";
import { Task, UnscheduledTask } from "../../../types";
import { createTask } from "../../../util/task-utils";

Expand All @@ -15,6 +16,7 @@ export interface UseEditHandlersProps {
obsidianFacade: ObsidianFacade;
cursorMinutes: Readable<number>;
editOperation: Writable<EditOperation>;
settings: Readable<DayPlannerSettings>;
}

export function createEditHandlers({
Expand All @@ -23,9 +25,14 @@ export function createEditHandlers({
startEdit,
cursorMinutes,
editOperation,
settings,
}: UseEditHandlersProps) {
function handleContainerMouseDown() {
const newTask = createTask(day, get(cursorMinutes));
const newTask = createTask(
day,
get(cursorMinutes),
get(settings).taskStatusOnCreation,
);

startEdit({
task: { ...newTask, isGhost: true },
Expand Down
1 change: 1 addition & 0 deletions src/ui/hooks/use-edit/use-edit-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export function useEditContext({
startEdit,
cursorMinutes,
editOperation,
settings,
});

return {
Expand Down
21 changes: 21 additions & 0 deletions src/ui/settings-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@ export class DayPlannerSettingsTab extends PluginSettingTab {
}),
);

new Setting(containerEl)
.setName("Default task status on creation")
.setDesc(
"You can use custom statuses for more advanced workflows. E.g.: '- [>] Task'",
)
.addText((el) =>
el
.setPlaceholder("Empty")
.setValue(this.plugin.settings().taskStatusOnCreation)
.onChange((value: string) => {
this.settingsStore.update((previous) => {
const newValue = value.length > 0 ? value.substring(0, 1) : " ";

return {
...previous,
taskStatusOnCreation: newValue,
};
});
}),
);

new Setting(containerEl)
.setName("Round time to minutes")
.setDesc("While editing, tasks are going to get rounded to this number")
Expand Down
8 changes: 6 additions & 2 deletions src/util/task-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,19 @@ export function offsetYToMinutes(
return (offsetY + hiddenHoursSize) / zoomLevel;
}

export function createTask(day: Moment, startMinutes: number): Task {
export function createTask(
day: Moment,
startMinutes: number,
status: string,
): Task {
return {
id: getId(),
startMinutes,
durationMinutes: defaultDurationMinutes,
text: "New item",
startTime: minutesToMomentOfDay(startMinutes, day),
symbol: "-",
status: " ",
status,
placing: {
widthPercent: 100,
xOffsetPercent: 0,
Expand Down

0 comments on commit 2efd462

Please sign in to comment.