Skip to content

Commit

Permalink
fix: Switch input suggesters to centralized version
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Feb 29, 2024
1 parent 3facbcc commit e641ddc
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 35 deletions.
80 changes: 70 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"jest": "^29.7.0",
"moment": "2.29.4",
"monkey-around": "^2.3.0",
"obsidian": "^1.4.11",
"obsidian": "^1.5.7-1",
"obsidian-utilities": "^1.1.2",
"scripty": "^2.1.1",
"standard-version": "^9.5.0",
"svelte": "^4.2.1",
Expand Down
22 changes: 14 additions & 8 deletions src/settings/modals/event/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ import {
TextAreaComponent,
TFile,
} from "obsidian";
import type { CalDate, Calendar, CalEvent, CalEventDate } from "../../../@types";
import type {
CalDate,
Calendar,
CalEvent,
CalEventDate,
} from "../../../@types";

import { dateString, nanoid } from "../../../utils/functions";

import PathSuggestionModal from "../../../suggester/path";
import { FileInputSuggest } from "obsidian-utilities";

/* import EventCreator from "./EventCreator.svelte"; */

Expand Down Expand Up @@ -370,15 +376,15 @@ export class CreateEventModal extends CalendariumModal {
}
}

const modal = new PathSuggestionModal(this.app, text, [
...files,
]);
const modal = new FileInputSuggest(this.app, text, [...files]);

modal.onClose = async () => {
modal.onSelect(async (value) => {
text.inputEl.blur();
if (modal.file) this.event.note = modal.file.path;
if (modal.file) this.tryParse(modal.file);
};
if (value.item) {
this.event.note = value.item.path;
this.tryParse(value.item);
}
});
});

new Setting(this.infoEl).setName("Event name").addText((t) =>
Expand Down
39 changes: 25 additions & 14 deletions src/settings/settings.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import copy from "fast-copy";
import type Calendarium from "../main";
import Importer from "./import/importer";

import CalendarCreator from "./creator/Creator.svelte";

import type { Calendar, PresetCalendar } from "src/@types";
import { SyncBehavior } from "src/schemas";

Expand All @@ -35,7 +33,7 @@ import { DEFAULT_CALENDAR } from "./settings.constants";
import { nanoid } from "src/utils/functions";
import SettingsService from "./settings.service";
import { RestoreCalendarModal } from "./modals/restore";
import { FolderSuggestionModal } from "src/suggester/folder";
import { FolderInputSuggest } from "obsidian-utilities";
import { getPresetCalendar } from "./preset";
import CreatorController from "./creator/CreatorController.svelte";
import {
Expand Down Expand Up @@ -96,7 +94,8 @@ declare module "obsidian" {
};
};
setting: {
openTabById(id: string): void;
open(): void;
openTabById(id: string): CalendariumSettings;
};
}
}
Expand All @@ -111,6 +110,7 @@ export default class CalendariumSettings extends PluginSettingTab {
event: false,
advanced: false,
};
eventsEl: HTMLDetailsElement;
get data() {
return this.settings$.getData();
}
Expand Down Expand Up @@ -138,14 +138,13 @@ export default class CalendariumSettings extends PluginSettingTab {
},
});
this.buildCalendars();
this.buildEvents(
this.contentEl.createEl("details", {
cls: "calendarium-nested-settings",
attr: {
...(this.toggleState.event ? { open: `open` } : {}),
},
})
);
this.eventsEl = this.contentEl.createEl("details", {
cls: "calendarium-nested-settings",
attr: {
...(this.toggleState.event ? { open: `open` } : {}),
},
});
this.buildEvents(this.eventsEl);
this.buildAdvanced(
this.contentEl.createEl("details", {
cls: "calendarium-nested-settings",
Expand Down Expand Up @@ -531,6 +530,10 @@ export default class CalendariumSettings extends PluginSettingTab {
this.pathsEl = containerEl.createDiv("calendarium-event-paths");
this.buildPaths();
}
showPaths() {
this.eventsEl.setAttr("open", "open");
this.pathsEl.scrollIntoView();
}
#needsSort = true;
allFolders = this.app.vault
.getAllLoadedFiles()
Expand Down Expand Up @@ -714,7 +717,7 @@ export default class CalendariumSettings extends PluginSettingTab {
/** Validate no existing paths... */
validateAndSend(path);
});
const modal = new FolderSuggestionModal(this.app, text, [
/* const modal = new FolderSuggestionModal(this.app, text, [
...this.folders,
]);
Expand All @@ -723,7 +726,15 @@ export default class CalendariumSettings extends PluginSettingTab {
? text.inputEl.value.trim()
: "/";
validateAndSend(path);
};
}; */

const modal = new FolderInputSuggest(this.app, text, [...this.folders]);

modal.onSelect(async (value) => {
modal.close();
modal.setValue(value.item.path);
validateAndSend(value.item.path);
});
}
buildAdvanced(containerEl: HTMLDetailsElement) {
containerEl.empty();
Expand Down
2 changes: 0 additions & 2 deletions src/watcher/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ export class Watcher extends Component {
super();
}

tree: CalendarEventTree = new Map();

worker = new Worker();
onload() {
/** Rescan for events for all calendars */
Expand Down
3 changes: 3 additions & 0 deletions src/watcher/watcher.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ class Parser {
while (this.queue.length) {
const path = this.queue.shift();
if (!path) break;
if (!path.endsWith(".md")) {
continue;
}
await this.getFileData(path);
}
this.parsing = false;
Expand Down

0 comments on commit e641ddc

Please sign in to comment.