Skip to content

Commit

Permalink
fix: Disabling auto parsing now removes file-based events
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Nov 1, 2024
1 parent d7ed936 commit e83f639
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ export default class Calendarium extends Plugin {
return this.getStoreByCalendar(cal);
}

public flushFileEvents() {
for (const calendar of this.calendars) {
this.stores.get(calendar)?.flushFileEvents();
}
}

/**
* Integrations
*/
Expand Down
1 change: 1 addition & 0 deletions src/settings/settings.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ export default class CalendariumSettings extends PluginSettingTab {
.addToggle((t) => {
t.setValue(this.data.autoParse).onChange(async (v) => {
this.data.autoParse = v;
if (!v) this.plugin.flushFileEvents();
await this.settings$.save({
calendar: true,
watcher: true,
Expand Down
4 changes: 3 additions & 1 deletion src/stores/calendar.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ export function createCalendarStore(calendar: Calendar, plugin: Calendarium) {
},
updateCalendar: (calendar: Calendar) => update((cal) => calendar),
eventStore,

flushFileEvents() {
this.eventStore.removeAllFileEvents();
},
getEventsForDate: (date: CalDate): Readable<EventLike[]> => {
const events = eventStore.getEventsForDate(date);
const eras = yearCalculator
Expand Down
2 changes: 2 additions & 0 deletions src/stores/events.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ export class EventStore {
}
public removeAllFileEvents() {
this.#events.update((SAVED_EVENTS) => {
console.log("🚀 ~ file: events.store.ts:106 ~ SAVED_EVENTS:", SAVED_EVENTS);

for (const id of this.#fileEventSet) {
if (!SAVED_EVENTS.has(id)) continue;
const event = { ...SAVED_EVENTS.get(id)! };
Expand Down

0 comments on commit e83f639

Please sign in to comment.