add chron to coreVM
This commit is contained in:
@@ -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<void>();
|
||||
todayDate = new React.State<Date>(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<any> = new React.State<any>(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
|
||||
|
||||
@@ -28,6 +28,7 @@ export default class CalendarPageViewModel extends TaskContainingPageViewModel {
|
||||
};
|
||||
|
||||
// state
|
||||
currentTodayDate: string | undefined = undefined;
|
||||
selectedYear: React.State<number> = new React.State(0);
|
||||
selectedMonth: React.State<number> = new React.State(0);
|
||||
selectedDate: React.State<number> = 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();
|
||||
|
||||
Reference in New Issue
Block a user