Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 4 additions & 23 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ import {
type PathToListProps,
} from "./redux/dataview/dataview-slice";
import { editCanceled, visibleDaysUpdated } from "./redux/global-slice";
import {
icalRefreshRequested,
type IcalState,
initialIcalState,
} from "./redux/ical/ical-slice";
import { icalRefreshRequested } from "./redux/ical/ical-slice";
import { settingsUpdated } from "./redux/settings-slice";
import { type AppDispatch, createReactor } from "./redux/store";
import { createUseSelector } from "./redux/use-selector";
Expand All @@ -59,11 +55,7 @@ import { PeriodicNotes } from "./service/periodic-notes";
import { STaskEditor } from "./service/stask-editor";
import { VaultFacade } from "./service/vault-facade";
import { WorkspaceFacade } from "./service/workspace-facade";
import {
type DayPlannerSettings,
defaultSettings,
type PluginData,
} from "./settings";
import { type DayPlannerSettings, defaultSettings } from "./settings";
import type { RemoteTask } from "./task-types";
import { createGetTasksApi } from "./tasks-plugin";
import type { ObsidianContext, OnUpdateFn, PointerDateTime } from "./types";
Expand Down Expand Up @@ -96,7 +88,7 @@ export default class DayPlanner extends Plugin {
private transactionWriter!: TransactionWriter;

async onload() {
const initialPluginData: PluginData = {
const initialSettings: DayPlannerSettings = {
...defaultSettings,
...(await this.loadData()),
};
Expand All @@ -120,11 +112,6 @@ export default class DayPlanner extends Plugin {
this.app.vault,
);

const icalStateWithCachedRawIcals: IcalState = {
...initialIcalState,
plainTextIcals: initialPluginData.rawIcals || [],
};

const {
getState,
dispatch,
Expand All @@ -137,14 +124,8 @@ export default class DayPlanner extends Plugin {
pointerDateTime,
dataviewRefreshSignal,
} = createReactor({
preloadedState: {
ical: icalStateWithCachedRawIcals,
},
dataviewFacade: this.dataviewFacade,
listPropsParser,
onIcalsFetched: async (rawIcals) => {
await this.saveData({ ...this.settings(), rawIcals });
},
});

this.sTaskEditor = new STaskEditor(
Expand All @@ -158,7 +139,7 @@ export default class DayPlanner extends Plugin {
listenerMiddleware.clearListeners();
});

this.initSettingsStore({ initialSettings: initialPluginData, dispatch });
this.initSettingsStore({ initialSettings, dispatch });
this.registerViews({
dispatch,
remoteTasks,
Expand Down
9 changes: 1 addition & 8 deletions src/redux/listener-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createBackgroundBatchScheduler } from "../util/scheduler";

import { dataviewChange } from "./dataview/dataview-slice";
import { createListPropsParseListener } from "./dataview/init-dataview-listeners";
import { icalRefreshRequested, icalsFetched } from "./ical/ical-slice";
import { icalRefreshRequested } from "./ical/ical-slice";
import {
checkIcalEventsChanged,
checkVisibleDaysChanged,
Expand Down Expand Up @@ -50,13 +50,6 @@ export function initListenerMiddleware(props: { extra: ReduxExtraArgument }) {
}),
});

listenerMiddleware.startListening({
actionCreator: icalsFetched,
effect: async (action, listenerApi) => {
await listenerApi.extra.onIcalsFetched(action.payload);
},
});

listenerMiddleware.startListening({
actionCreator: dataviewChange,
effect: createListPropsParseListener({ listPropsParser }),
Expand Down
9 changes: 3 additions & 6 deletions src/redux/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
selectListProps,
} from "./dataview/dataview-slice";
import { editCanceled, globalSlice } from "./global-slice";
import { icalSlice, type RawIcal, selectRemoteTasks } from "./ical/ical-slice";
import { icalSlice, selectRemoteTasks } from "./ical/ical-slice";
import { initListenerMiddleware } from "./listener-middleware";
import { searchSlice } from "./search-slice";
import { selectDataviewSource, settingsSlice } from "./settings-slice";
Expand Down Expand Up @@ -57,19 +57,16 @@ export const makeStore = (
};

export function createReactor(props: {
preloadedState: Partial<RootState>;
preloadedState?: Partial<RootState>;
dataviewFacade: DataviewFacade;
listPropsParser: ListPropsParser;
onIcalsFetched: (rawIcals: RawIcal[]) => Promise<void>;
}) {
const { preloadedState, dataviewFacade, listPropsParser, onIcalsFetched } =
props;
const { preloadedState = {}, dataviewFacade, listPropsParser } = props;

const listenerMiddleware = initListenerMiddleware({
extra: {
dataviewFacade,
listPropsParser,
onIcalsFetched,
},
});

Expand Down
7 changes: 0 additions & 7 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { HexString } from "obsidian";

import { defaultDayFormat } from "./constants";
import type { RawIcal } from "./redux/ical/ical-slice";

export interface IcalConfig {
name: string;
Expand Down Expand Up @@ -69,12 +68,6 @@ export interface DayPlannerSettings {
timelineColumns: TimelineColumns;
}

export interface Cache {
rawIcals: Array<RawIcal>;
}

export type PluginData = DayPlannerSettings & Cache;

export const defaultSettings: DayPlannerSettings = {
snapStepMinutes: 10,
progressIndicator: "mini-timeline",
Expand Down
2 changes: 0 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type Fraction from "fraction.js";
import type { Moment } from "moment";
import type { Readable, Writable } from "svelte/store";

import type { RawIcal } from "./redux/ical/ical-slice";
import { type AppDispatch } from "./redux/store";
import type { UseSelector } from "./redux/use-selector";
import type { DataviewFacade } from "./service/dataview-facade";
Expand Down Expand Up @@ -91,5 +90,4 @@ export type DateRange = Writable<Moment[]> & { untrack: () => void };
export type ReduxExtraArgument = {
dataviewFacade: DataviewFacade;
listPropsParser: ListPropsParser;
onIcalsFetched: (rawIcals: RawIcal[]) => Promise<void>;
};
3 changes: 0 additions & 3 deletions tests/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ async function setUp(props: {

const onEditCanceled = vi.fn();
const onEditConfirmed = vi.fn();
const onIcalsFetched = vi.fn();

const defaultPreloadedStateForTests: Partial<RootState> = {
obsidian: {
...initialState,
Expand All @@ -207,7 +205,6 @@ async function setUp(props: {
},
},
dataviewFacade,
onIcalsFetched,
listPropsParser,
});

Expand Down
1 change: 0 additions & 1 deletion tests/store/ical.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ function makeStoreForTests(props?: { preloadedState?: Partial<RootState> }) {
new InMemoryVault([]) as unknown as Vault,
new FakeMetadataCache({}) as unknown as MetadataCache,
),
onIcalsFetched: async () => {},
},
});

Expand Down
Loading