Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazily load events as they come into view (OFC-5) #326

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/core/EventCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const eventsAreDifferent = (
export type CachedEvent = Pick<StoredEvent, "event" | "id">;

export type OFCEventSource = {
// events: (start: Date, end: Date) => CachedEvent[];
events: CachedEvent[];
editable: boolean;
color: string;
Expand Down
27 changes: 27 additions & 0 deletions src/core/EventStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,33 @@ export default class EventStore {
return this.fetch([...inFile].filter((id) => inCalendar.has(id)));
}

/**
* Get all events in a calendar within a specified range.
* @param calendar Calendar to filter on.
* @param start Start of the date range.
* @param end End of the date range.
* @returns All events in the calendar within the date range.
*/
getEventsInCalendarWithinRange(
calendar: Calendar,
start: Date,
end: Date
): StoredEvent[] {
const between = (start: Date, x: Date, end: Date) =>
start.valueOf() <= x.valueOf() && x.valueOf() <= end.valueOf();

const getDate = (e: OFCEvent) => {
if (e.type === "single" || e.type === undefined) {
return new Date(e.date);
}
return null;
};
return this.getEventsInCalendar(calendar).filter(({ event }) => {
const date = getDate(event);
return !date || between(start, date, end);
});
}

get eventsByCalendar(): Map<string, StoredEvent[]> {
const result = new Map();
for (const [k, vs] of this.calendarIndex.groupByRelated) {
Expand Down