Skip to content

Commit

Permalink
fix: update tasks after filter update
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-lednev committed Oct 13, 2023
1 parent b2a1f16 commit 25a50c4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { FileView, Plugin, WorkspaceLeaf } from "obsidian";
import { getDateFromFile } from "obsidian-daily-notes-interface";
import { DataArray, getAPI, STask } from "obsidian-dataview";
import { get, readable, Readable, writable, Writable } from "svelte/store";
import {
derived,
get,
readable,
Readable,
writable,
Writable,
} from "svelte/store";

import { obsidianContext, viewTypeTimeline, viewTypeWeekly } from "./constants";
import { settings } from "./global-store/settings";
Expand Down Expand Up @@ -95,9 +102,18 @@ export default class DayPlanner extends Plugin {
);
document.addEventListener("keydown", delayUpdateTasks);

const source = derived(this.settingsStore, ($settings) => {
return $settings.dataviewSource;
});

const unsubscribeFromSettings = source.subscribe(() => {
updateTasks();
});

return () => {
this.app.metadataCache.off("dataview:metadata-change", updateTasks);
document.removeEventListener("keydown", delayUpdateTasks);
unsubscribeFromSettings();
};
});
}
Expand Down
1 change: 1 addition & 0 deletions src/regexp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const hourMinuteSeparator = `[:. ]`;
const time = `(${hours})(?:${hourMinuteSeparator}?(${minutes}))?\\s*([apAP][mM])?`;

export const timeRegExp = new RegExp(time);
export const timeFromStartRegExp = new RegExp(`^${time}`);
export const timestampRegExp = new RegExp(
`^(?<listTokens>${listToken}${checkboxOrNothing})(?<times>(?<start>${time})(?:${durationSeparator}(?<end>${time}))?)(?<text>.+)$`,
"im",
Expand Down
4 changes: 2 additions & 2 deletions src/util/get-tasks-for-day.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Moment } from "moment/moment";
import { getAllDailyNotes, getDailyNote } from "obsidian-daily-notes-interface";
import { DataArray, STask } from "obsidian-dataview";

import { timeRegExp } from "../regexp";
import { timeFromStartRegExp } from "../regexp";
import { sTaskToPlanItem } from "../service/dataview-facade";
import { PlanItem } from "../types";

Expand All @@ -15,7 +15,7 @@ export function getTasksForDay(day: Moment, dataviewTasks: DataArray<STask>) {

return dataviewTasks
.where((task: STask) => {
const timeIsSet = timeRegExp.test(task.text);
const timeIsSet = timeFromStartRegExp.test(task.text);

if (!timeIsSet) {
return false;
Expand Down

0 comments on commit 25a50c4

Please sign in to comment.