dynamically update calendar

This commit is contained in:
marlon-erler
2024-07-26 03:52:05 +02:00
parent d0131ce3f1
commit a14a275f1f
3 changed files with 33 additions and 3 deletions
+14 -1
View File
@@ -1522,6 +1522,7 @@
this.boardViewModel.updateTaskIndices(); this.boardViewModel.updateTaskIndices();
} }
if (this.calendarPageViewModel != null) { if (this.calendarPageViewModel != null) {
this.calendarPageViewModel.showTask(newTaskFileContent);
} }
}; };
deleteTask = () => { deleteTask = () => {
@@ -1531,6 +1532,7 @@
this.boardViewModel.removeTaskFromList(this.task.fileId); this.boardViewModel.removeTaskFromList(this.task.fileId);
} }
if (this.calendarPageViewModel != null) { if (this.calendarPageViewModel != null) {
this.calendarPageViewModel.removeTaskFromView(this.task);
} }
}; };
// load // load
@@ -1591,6 +1593,11 @@
bulkSubscribe([this.selectedYear, this.selectedMonth], () => { bulkSubscribe([this.selectedYear, this.selectedMonth], () => {
this.loadTasks(); this.loadTasks();
}); });
boardAndTasksModel.taskHandlerManager.addHandler(
(taskFileContent) => {
this.showTask(taskFileContent);
}
);
} }
storageModel; storageModel;
calendarModel; calendarModel;
@@ -1621,6 +1628,12 @@
return this.monthGrid.value.days[dateString]; return this.monthGrid.value.days[dateString];
}; };
showTask = (taskFileContent) => { showTask = (taskFileContent) => {
const monthString = CalendarModel.isoToMonthString(
taskFileContent.date ?? ""
);
if (monthString == void 0 || monthString != this.monthString) {
return;
}
const taskViewModel = new TaskViewModel( const taskViewModel = new TaskViewModel(
this.coreViewModel, this.coreViewModel,
this.boardsAndTasksModel, this.boardsAndTasksModel,
@@ -1631,7 +1644,7 @@
const mapState = this.getTaskMapState(taskFileContent); const mapState = this.getTaskMapState(taskFileContent);
mapState?.set(taskFileContent.fileId, taskViewModel); mapState?.set(taskFileContent.fileId, taskViewModel);
}; };
removeTaskFromList = (taskFileContent) => { removeTaskFromView = (taskFileContent) => {
const mapState = this.getTaskMapState(taskFileContent); const mapState = this.getTaskMapState(taskFileContent);
mapState?.remove(taskFileContent.fileId); mapState?.remove(taskFileContent.fileId);
}; };
+17 -2
View File
@@ -49,6 +49,14 @@ export default class CalendarPageViewModel {
}; };
showTask = (taskFileContent: TaskFileContent): void => { showTask = (taskFileContent: TaskFileContent): void => {
const monthString: string | undefined = CalendarModel.isoToMonthString(
taskFileContent.date ?? ""
);
if (monthString == undefined || monthString != this.monthString) {
// TODO remove
return;
}
const taskViewModel: TaskViewModel = new TaskViewModel( const taskViewModel: TaskViewModel = new TaskViewModel(
this.coreViewModel, this.coreViewModel,
this.boardsAndTasksModel, this.boardsAndTasksModel,
@@ -61,7 +69,7 @@ export default class CalendarPageViewModel {
mapState?.set(taskFileContent.fileId, taskViewModel); mapState?.set(taskFileContent.fileId, taskViewModel);
}; };
removeTaskFromList = (taskFileContent: TaskFileContent): void => { removeTaskFromView = (taskFileContent: TaskFileContent): void => {
const mapState: React.MapState<TaskViewModel> | null = const mapState: React.MapState<TaskViewModel> | null =
this.getTaskMapState(taskFileContent); this.getTaskMapState(taskFileContent);
mapState?.remove(taskFileContent.fileId); mapState?.remove(taskFileContent.fileId);
@@ -121,7 +129,7 @@ export default class CalendarPageViewModel {
public coreViewModel: CoreViewModel, public coreViewModel: CoreViewModel,
storageModel: StorageModel, storageModel: StorageModel,
calendarModel: CalendarModel, calendarModel: CalendarModel,
boardAndTasksModel: BoardsAndTasksModel, boardAndTasksModel: BoardsAndTasksModel
) { ) {
this.storageModel = storageModel; this.storageModel = storageModel;
this.calendarModel = calendarModel; this.calendarModel = calendarModel;
@@ -130,6 +138,13 @@ export default class CalendarPageViewModel {
React.bulkSubscribe([this.selectedYear, this.selectedMonth], () => { React.bulkSubscribe([this.selectedYear, this.selectedMonth], () => {
this.loadTasks(); this.loadTasks();
}); });
// handlers
boardAndTasksModel.taskHandlerManager.addHandler(
(taskFileContent: TaskFileContent) => {
this.showTask(taskFileContent);
}
);
} }
} }
+2
View File
@@ -121,6 +121,7 @@ export default class TaskViewModel {
this.boardViewModel.updateTaskIndices(); this.boardViewModel.updateTaskIndices();
} }
if (this.calendarPageViewModel != null) { if (this.calendarPageViewModel != null) {
this.calendarPageViewModel.showTask(newTaskFileContent);
} }
}; };
@@ -132,6 +133,7 @@ export default class TaskViewModel {
this.boardViewModel.removeTaskFromList(this.task.fileId); this.boardViewModel.removeTaskFromList(this.task.fileId);
} }
if (this.calendarPageViewModel != null) { if (this.calendarPageViewModel != null) {
this.calendarPageViewModel.removeTaskFromView(this.task);
} }
}; };