use t.view for room sub views

also move composer to own vm
This commit is contained in:
Bruno Windels 2020-05-04 22:23:43 +02:00
parent 28bed56b5a
commit d7a8b1616a
2 changed files with 21 additions and 15 deletions

View File

@ -14,6 +14,7 @@ export class RoomViewModel extends ViewModel {
this._timelineError = null;
this._sendError = null;
this._closeCallback = closeCallback;
this._composerVM = new ComposerViewModel(this);
}
async load() {
@ -73,7 +74,9 @@ export class RoomViewModel extends ViewModel {
return avatarInitials(this._room.name);
}
async sendMessage(message) {
async _sendMessage(message) {
if (message) {
try {
await this._room.sendEvent("m.room.message", {msgtype: "m.text", body: message});
@ -88,4 +91,18 @@ export class RoomViewModel extends ViewModel {
}
return false;
}
get composerViewModel() {
return this._composerVM;
}
}
class ComposerViewModel {
constructor(roomVM) {
this._roomVM = roomVM;
}
sendMessage(message) {
return this._roomVM._sendMessage(message);
}
}

View File

@ -9,6 +9,7 @@ export class RoomView extends TemplateView {
}
render(t, vm) {
this._timelineList = new TimelineList();
return t.div({className: "RoomView"}, [
t.div({className: "TimelinePanel"}, [
t.div({className: "RoomHeader"}, [
@ -19,24 +20,12 @@ export class RoomView extends TemplateView {
]),
]),
t.div({className: "RoomView_error"}, vm => vm.error),
this._timelineList.mount(),
this._composer.mount(),
t.view(this._timelineList),
t.view(new MessageComposer(this.value.composerViewModel)),
])
]);
}
mount() {
this._composer = new MessageComposer(this.value);
this._timelineList = new TimelineList();
return super.mount();
}
unmount() {
this._composer.unmount();
this._timelineList.unmount();
super.unmount();
}
update(value, prop) {
super.update(value, prop);
if (prop === "timelineViewModel") {