diff --git a/dist/index.js b/dist/index.js index 8a23ba38..713f345d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -660,8 +660,8 @@ const monthPath = this.getMonthPath(monthString); return this.storageModel.list(monthPath); }; - this.generateMonthGrid = (year, month, defaultValueCreator) => { - const date = /* @__PURE__ */ new Date(); + this.generateMonthGrid = (coreViewModel2, year, month, defaultValueCreator) => { + const date = coreViewModel2.unwrappedTodayDate; const isCurrentMonth = year == date.getFullYear() && month == date.getMonth() + 1; date.setDate(1); date.setMonth(month - 1); @@ -2290,6 +2290,17 @@ if (isHandled == true) break; } }; + // CHRON + this.chronHandlerManager = new HandlerManager(); + this.todayDate = new State(/* @__PURE__ */ new Date()); + this.startChron = () => { + setInterval(this.chronHandlerManager.trigger, 2e3); + }; + this.handleChron = () => { + const newDate = /* @__PURE__ */ new Date(); + if (this.unwrappedTodayDate.toDateString() == newDate.toDateString()) return; + this.todayDate.value = /* @__PURE__ */ new Date(); + }; // DRAG & DROP this.draggedObject = new State(void 0); // SUGGESTIONS @@ -2302,6 +2313,11 @@ window.onpopstate = () => { this.closeContext(this.context.contextId, true); }; + this.startChron(); + this.chronHandlerManager.setHandler( + "core-view-model", + this.handleChron + ); } get contexts() { return [...this.contextStack.values()]; @@ -2314,6 +2330,9 @@ this.contextStack.set(context.contextId, context); history.pushState({ id: context.contextId }, ""); } + get unwrappedTodayDate() { + return new Date(this.todayDate.value); + } // util static checkIsKeystroke(e) { return (e.metaKey || e.altKey) && e.ctrlKey; @@ -2692,6 +2711,7 @@ return [...this.calendarModel.getViewPath()]; }; // state + this.currentTodayDate = void 0; this.selectedYear = new State(0); this.selectedMonth = new State(0); this.selectedDate = new State(0); @@ -2763,7 +2783,7 @@ this.taskViewModels.remove(taskFileContent.fileId); }; this.showToday = () => { - const today = /* @__PURE__ */ new Date(); + const today = this.coreViewModel.todayDate.value; this.selectedYear.value = today.getFullYear(); this.selectedMonth.value = today.getMonth() + 1; this.selectedDate.value = today.getDate(); @@ -2792,9 +2812,16 @@ if (draggedObject instanceof TaskViewModel == false) return; draggedObject.setDate(ISOString); }; + this.updateMonthGrid = () => { + if (this.currentTodayDate == this.coreViewModel.todayDate.value.toISOString()) + return; + this.loadMonthTasks(); + this.currentTodayDate = this.coreViewModel.todayDate.value.toISOString(); + }; // load this.loadMonthTasks = () => { this.monthGrid.value = this.calendarModel.generateMonthGrid( + this.coreViewModel, this.selectedYear.value, this.selectedMonth.value, () => new MapState() @@ -2823,6 +2850,10 @@ this.showTask(taskFileContent); } ); + this.coreViewModel.chronHandlerManager.setHandler( + `calendar-${this.chatViewModel.chatModel.id}`, + this.updateMonthGrid + ); this.showToday(); this.registerKeyStroke("-" /* Reset */, this.showToday); this.registerKeyStroke("k", this.showPreviousMonth); @@ -4000,7 +4031,12 @@ [selectedDate], () => selectedDate.value == parseInt(date) ); - const isToday = monthGrid.isCurrentMonth == true && parseInt(date) == (/* @__PURE__ */ new Date()).getDate(); + const isToday = createProxyState( + [coreViewModel2.todayDate], + () => { + return monthGrid.isCurrentMonth == true && date == coreViewModel2.unwrappedTodayDate.getDate().toString(); + } + ); const eventCount = createProxyState( [mapState], () => mapState.value.size diff --git a/src/Model/Files/calendarModel.ts b/src/Model/Files/calendarModel.ts index afcf8442..88e16b2d 100644 --- a/src/Model/Files/calendarModel.ts +++ b/src/Model/Files/calendarModel.ts @@ -5,6 +5,7 @@ import FileModel, { FileModelSubPath } from "./fileModel"; import SettingsModel from "../Global/settingsModel"; import StorageModel from "../Global/storageModel"; import { TaskFileContent } from "./boardsAndTasksModel"; +import CoreViewModel from "../../ViewModel/Global/coreViewModel"; export default class CalendarModel { readonly storageModel: StorageModel; @@ -57,12 +58,13 @@ export default class CalendarModel { }; generateMonthGrid = ( + coreViewModel: CoreViewModel, year: number, month: number, defaultValueCreator: () => T, ): MonthGrid => { // get today - const date: Date = new Date(); + const date = coreViewModel.unwrappedTodayDate; const isCurrentMonth: boolean = year == date.getFullYear() && month == date.getMonth() + 1; diff --git a/src/View/Components/monthGrid.tsx b/src/View/Components/monthGrid.tsx index 761536ad..b103be2b 100644 --- a/src/View/Components/monthGrid.tsx +++ b/src/View/Components/monthGrid.tsx @@ -63,9 +63,16 @@ export function MonthGrid( () => selectedDate.value == parseInt(date), ); - const isToday: boolean = - monthGrid.isCurrentMonth == true && - parseInt(date) == new Date().getDate(); + const isToday = React.createProxyState( + [coreViewModel.todayDate], + () => { + return ( + monthGrid.isCurrentMonth == true && + date == + coreViewModel.unwrappedTodayDate.getDate().toString() + ); + }, + ); const eventCount: React.State = React.createProxyState( diff --git a/src/ViewModel/Global/coreViewModel.ts b/src/ViewModel/Global/coreViewModel.ts index 38b66d14..7344a36e 100644 --- a/src/ViewModel/Global/coreViewModel.ts +++ b/src/ViewModel/Global/coreViewModel.ts @@ -6,9 +6,10 @@ import ConnectionModel from "../../Model/Global/connectionModel"; import ChatListModel from "../../Model/Chat/chatListModel"; import FileTransferModel from "../../Model/Global/fileTransferModel"; import { v4 } from "uuid"; +import { HandlerManager } from "../../Model/Utility/utility"; export default class CoreViewModel { - readonly BUILD = "Build 26.04.15.B"; + readonly BUILD = "Build 26.04.16.A"; translations: Translations; @@ -58,6 +59,23 @@ export default class CoreViewModel { } }; + // CHRON + chronHandlerManager = new HandlerManager(); + todayDate = new React.State(new Date()); + get unwrappedTodayDate() { + return new Date(this.todayDate.value); + } + + startChron = (): void => { + setInterval(this.chronHandlerManager.trigger, 2000); + }; + + handleChron = (): void => { + const newDate = new Date(); + if (this.unwrappedTodayDate.toDateString() == newDate.toDateString()) return; + this.todayDate.value = new Date(); + }; + // DRAG & DROP draggedObject: React.State = new React.State(undefined); @@ -85,6 +103,12 @@ export default class CoreViewModel { window.onpopstate = () => { this.closeContext(this.context.contextId, true); }; + + this.startChron(); + this.chronHandlerManager.setHandler( + "core-view-model", + this.handleChron, + ); } // util diff --git a/src/ViewModel/Pages/calendarPageViewModel.ts b/src/ViewModel/Pages/calendarPageViewModel.ts index 99385e30..fd722bae 100644 --- a/src/ViewModel/Pages/calendarPageViewModel.ts +++ b/src/ViewModel/Pages/calendarPageViewModel.ts @@ -28,6 +28,7 @@ export default class CalendarPageViewModel extends TaskContainingPageViewModel { }; // state + currentTodayDate: string | undefined = undefined; selectedYear: React.State = new React.State(0); selectedMonth: React.State = new React.State(0); selectedDate: React.State = new React.State(0); @@ -121,7 +122,7 @@ export default class CalendarPageViewModel extends TaskContainingPageViewModel { }; showToday = (): void => { - const today: Date = new Date(); + const today: Date = this.coreViewModel.todayDate.value; this.selectedYear.value = today.getFullYear(); this.selectedMonth.value = today.getMonth() + 1; this.selectedDate.value = today.getDate(); @@ -158,9 +159,21 @@ export default class CalendarPageViewModel extends TaskContainingPageViewModel { draggedObject.setDate(ISOString); }; + updateMonthGrid = (): void => { + if ( + this.currentTodayDate == + this.coreViewModel.todayDate.value.toISOString() + ) + return; + this.loadMonthTasks(); + this.currentTodayDate = + this.coreViewModel.todayDate.value.toISOString(); + }; + // load loadMonthTasks = (): void => { this.monthGrid.value = this.calendarModel.generateMonthGrid( + this.coreViewModel, this.selectedYear.value, this.selectedMonth.value, () => new React.MapState(), @@ -206,6 +219,10 @@ export default class CalendarPageViewModel extends TaskContainingPageViewModel { this.showTask(taskFileContent); }, ); + this.coreViewModel.chronHandlerManager.setHandler( + `calendar-${this.chatViewModel.chatModel.id}`, + this.updateMonthGrid, + ); // initiate this.showToday();