Working calendar month navigation

This commit is contained in:
Eric Eastwood 2022-02-15 02:30:26 -06:00
parent 72a6297ae5
commit ae4b529879
2 changed files with 63 additions and 50 deletions

View File

@ -34,9 +34,6 @@ for (let i = 0; i < 7; i++) {
class CalendarView extends TemplateView { class CalendarView extends TemplateView {
render(t, vm) { render(t, vm) {
const date = vm.date;
console.log('CalendarView vm', vm);
return t.div({ className: { CalendarView: true } }, [ return t.div({ className: { CalendarView: true } }, [
t.div({ className: { CalendarView_heading: true } }, [ t.div({ className: { CalendarView_heading: true } }, [
t.button( t.button(
@ -62,7 +59,10 @@ class CalendarView extends TemplateView {
['\u276F'] ['\u276F']
), ),
]), ]),
t.ol( t.map(
(vm) => vm.date,
(date, t) => {
return t.ol(
{ className: { CalendarView_calendar: true } }, { className: { CalendarView_calendar: true } },
[].concat( [].concat(
Object.keys(DAYS_OF_WEEK).map((dayKey) => { Object.keys(DAYS_OF_WEEK).map((dayKey) => {
@ -94,6 +94,8 @@ class CalendarView extends TemplateView {
return dayNodes; return dayNodes;
})() })()
) )
);
}
), ),
]); ]);
} }

View File

@ -13,6 +13,7 @@ const {
TimelineView, TimelineView,
RoomView, RoomView,
RoomViewModel, RoomViewModel,
ViewModel,
} = require('hydrogen-view-sdk'); } = require('hydrogen-view-sdk');
const ArchiveView = require('matrix-public-archive-shared/ArchiveView'); const ArchiveView = require('matrix-public-archive-shared/ArchiveView');
@ -179,29 +180,39 @@ async function mountHydrogen() {
kind: 'none', kind: 'none',
}; };
class CalendarViewModel extends ViewModel {
constructor(options) {
super(options);
const { date } = options;
this._date = date;
}
get date() {
return this._date;
}
prevMonth() {
const prevMonthDate = new Date(this._date);
prevMonthDate.setMonth(this._date.getMonth() - 1);
this._date = prevMonthDate;
this.emitChange('date');
}
nextMonth() {
const nextMonthDate = new Date(this._date);
nextMonthDate.setMonth(this._date.getMonth() + 1);
this._date = nextMonthDate;
this.emitChange('date');
}
}
const archiveViewModel = { const archiveViewModel = {
roomViewModel, roomViewModel,
rightPanelModel: { rightPanelModel: {
activeViewModel: { activeViewModel: {
type: 'custom', type: 'custom',
customView: RightPanelContentView, customView: RightPanelContentView,
calendarViewModel: new CalendarViewModel({ date: new Date() }),
calendarViewModel: {
date: new Date(),
prevMonth: function () {
console.log('prevMonth');
const prevMonthDate = new Date(this.date);
prevMonthDate.setMonth(this.date.getMonth() - 1);
console.log('prevMonthDate', prevMonthDate);
this.date = prevMonthDate;
},
nextMonth: function () {
console.log('nextMonth');
const nextMonthDate = new Date(this.date);
nextMonthDate.setMonth(this.date.getMonth() + 1);
this.date = nextMonthDate;
},
},
}, },
}, },
}; };