444 use websocket to trigger reloads (#458)
* [#444] added refresh on sync token calendar update * [#444] added refresh on register and tests * [#444] extracted logic for useEffects and updates * [#444] refactored code structure to use absolute paths
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { getCalendarRange } from "./dateUtils";
|
||||
|
||||
class CalendarRangeManager {
|
||||
private static instance: CalendarRangeManager;
|
||||
private displayedDate: Date = new Date();
|
||||
private displayedCalendarRange: { start: Date; end: Date } = getCalendarRange(
|
||||
new Date()
|
||||
);
|
||||
|
||||
private constructor() {}
|
||||
|
||||
public static getInstance(): CalendarRangeManager {
|
||||
if (!CalendarRangeManager.instance) {
|
||||
CalendarRangeManager.instance = new CalendarRangeManager();
|
||||
}
|
||||
return CalendarRangeManager.instance;
|
||||
}
|
||||
|
||||
public getDate(): Date {
|
||||
return new Date(this.displayedDate);
|
||||
}
|
||||
|
||||
public setDate(date: Date) {
|
||||
this.displayedDate = new Date(date);
|
||||
this.displayedCalendarRange = getCalendarRange(new Date(date));
|
||||
}
|
||||
|
||||
public getRange(): { start: Date; end: Date } {
|
||||
return {
|
||||
start: this.displayedCalendarRange.start,
|
||||
end: this.displayedCalendarRange.end,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export const calendarRangeManager = CalendarRangeManager.getInstance();
|
||||
|
||||
export const getDisplayedDate = (): Date => calendarRangeManager.getDate();
|
||||
|
||||
export const setDisplayedDateAndRange = (date: Date) =>
|
||||
calendarRangeManager.setDate(date);
|
||||
|
||||
export const getDisplayedCalendarRange = (): { start: Date; end: Date } =>
|
||||
calendarRangeManager.getRange();
|
||||
@@ -0,0 +1,17 @@
|
||||
import { RootState } from "../app/store";
|
||||
import { Calendar } from "../features/Calendars/CalendarTypes";
|
||||
|
||||
export function findCalendarById(
|
||||
state: Partial<RootState>,
|
||||
calendarId: string
|
||||
): { calendar: Calendar; type?: "temp" } | undefined {
|
||||
if (calendarId.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (state.calendars?.list?.[calendarId]) {
|
||||
return { calendar: state.calendars.list[calendarId] };
|
||||
}
|
||||
if (state.calendars?.templist?.[calendarId]) {
|
||||
return { calendar: state.calendars.templist[calendarId], type: "temp" };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
export {
|
||||
getDisplayedDate,
|
||||
setDisplayedDateAndRange,
|
||||
getDisplayedCalendarRange,
|
||||
calendarRangeManager,
|
||||
} from "./CalendarRangeManager";
|
||||
|
||||
export { findCalendarById } from "./findCalendarById";
|
||||
Reference in New Issue
Block a user