2022-08-30 18:10:57 -06:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { ViewModel } = require('hydrogen-view-sdk');
|
|
|
|
|
|
|
|
const assert = require('matrix-public-archive-shared/lib/assert');
|
|
|
|
|
|
|
|
class CalendarViewModel extends ViewModel {
|
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
2023-04-05 03:25:31 -06:00
|
|
|
const { activeDate, calendarDate, room, matrixPublicArchiveURLCreator } = options;
|
2022-08-30 18:10:57 -06:00
|
|
|
assert(activeDate);
|
|
|
|
assert(calendarDate);
|
|
|
|
assert(room);
|
2023-04-05 03:25:31 -06:00
|
|
|
assert(matrixPublicArchiveURLCreator);
|
2022-08-30 18:10:57 -06:00
|
|
|
|
2022-09-20 15:02:09 -06:00
|
|
|
// The day being shown in the archive
|
2022-08-30 18:10:57 -06:00
|
|
|
this._activeDate = activeDate;
|
2022-09-20 15:02:09 -06:00
|
|
|
// The month displayed in the calendar
|
2022-08-30 18:10:57 -06:00
|
|
|
this._calendarDate = calendarDate;
|
|
|
|
this._room = room;
|
2023-04-05 03:25:31 -06:00
|
|
|
this._matrixPublicArchiveURLCreator = matrixPublicArchiveURLCreator;
|
2022-08-30 18:10:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
get activeDate() {
|
|
|
|
return this._activeDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
get calendarDate() {
|
|
|
|
return this._calendarDate;
|
|
|
|
}
|
|
|
|
|
2022-09-20 15:02:09 -06:00
|
|
|
setActiveDate(newActiveDateInput) {
|
|
|
|
const newActiveDate = new Date(newActiveDateInput);
|
|
|
|
this._activeDate = newActiveDate;
|
|
|
|
this._calendarDate = newActiveDate;
|
|
|
|
this.emitChange('activeDate');
|
|
|
|
this.emitChange('calendarDate');
|
|
|
|
}
|
|
|
|
|
2022-08-30 18:10:57 -06:00
|
|
|
archiveUrlForDate(date) {
|
2022-10-27 00:09:13 -06:00
|
|
|
return this._matrixPublicArchiveURLCreator.archiveUrlForDate(
|
|
|
|
this._room.canonicalAlias || this._room.id,
|
|
|
|
date
|
|
|
|
);
|
2022-08-30 18:10:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
prevMonth() {
|
|
|
|
const prevMonthDate = new Date(this._calendarDate);
|
|
|
|
prevMonthDate.setUTCMonth(this._calendarDate.getUTCMonth() - 1);
|
|
|
|
this._calendarDate = prevMonthDate;
|
|
|
|
this.emitChange('calendarDate');
|
|
|
|
}
|
|
|
|
|
|
|
|
nextMonth() {
|
|
|
|
const nextMonthDate = new Date(this._calendarDate);
|
|
|
|
nextMonthDate.setUTCMonth(this._calendarDate.getUTCMonth() + 1);
|
|
|
|
console.log('nextMonthDate', nextMonthDate);
|
|
|
|
this._calendarDate = nextMonthDate;
|
|
|
|
this.emitChange('calendarDate');
|
|
|
|
}
|
|
|
|
|
|
|
|
onMonthInputChange(e) {
|
|
|
|
this._calendarDate = e.target.valueAsDate;
|
|
|
|
this.emitChange('calendarDate');
|
|
|
|
}
|
|
|
|
|
|
|
|
onYearFallbackSelectChange(e) {
|
|
|
|
const selectedDate = new Date(this._calendarDate);
|
|
|
|
selectedDate.setUTCFullYear(e.target.value);
|
|
|
|
this._calendarDate = selectedDate;
|
|
|
|
this.emitChange('calendarDate');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = CalendarViewModel;
|