pass viewClassForTile to tile views, so they can create reply view with correct subtile

This commit is contained in:
Bruno Windels 2022-04-08 15:02:07 +02:00
parent 57f50cc416
commit 1f0cb542c8
4 changed files with 18 additions and 10 deletions

View file

@ -28,7 +28,11 @@ export interface TileView extends IView {
readonly value: SimpleTile;
onClick(event: UIEvent);
}
export type TileViewConstructor = new (tile: SimpleTile) => TileView;
export type TileViewConstructor = new (
tile: SimpleTile,
viewClassForTile: ViewClassForEntryFn,
renderFlags?: { reply?: boolean, interactive?: boolean }
) => TileView;
export type ViewClassForEntryFn = (tile: SimpleTile) => TileViewConstructor;
//import {TimelineViewModel} from "../../../../../domain/session/room/timeline/TimelineViewModel.js";
@ -188,9 +192,9 @@ class TilesListView extends ListView<SimpleTile, TileView> {
super({
list: tiles,
onItemClick: (tileView, evt) => tileView.onClick(evt),
}, entry => {
const View = viewClassForTile(entry);
return new View(entry);
}, tile => {
const TileView = viewClassForTile(tile);
return new TileView(tile, viewClassForTile);
});
this.onChanged = onChanged;
}

View file

@ -24,10 +24,11 @@ import {Menu} from "../../../general/Menu.js";
import {ReactionsView} from "./ReactionsView.js";
export class BaseMessageView extends TemplateView {
constructor(value, renderFlags, tagName = "li") {
constructor(value, viewClassForTile, renderFlags, tagName = "li") {
super(value);
this._menuPopup = null;
this._tagName = tagName;
this._viewClassForTile = viewClassForTile;
// TODO An enum could be nice to make code easier to read at call sites.
this._renderFlags = renderFlags;
}

View file

@ -16,15 +16,18 @@ limitations under the License.
import {renderStaticAvatar} from "../../../avatar";
import {TemplateView} from "../../../general/TemplateView";
import {viewClassForTile} from "../common";
export class ReplyPreviewView extends TemplateView {
constructor(vm, viewClassForTile) {
super(vm);
this._viewClassForTile = viewClassForTile;
}
render(t, vm) {
const viewClass = viewClassForTile(vm);
if (!viewClass) {
const TileView = this._viewClassForTile(vm);
if (!TileView) {
throw new Error(`Shape ${vm.shape} is unrecognized.`)
}
const view = new viewClass(vm, { reply: true, interactive: false });
const view = new TileView(vm, this._viewClassForTile, { reply: true, interactive: false });
return t.div(
{ className: "ReplyPreviewView" },
t.blockquote([

View file

@ -35,7 +35,7 @@ export class TextMessageView extends BaseMessageView {
return new ReplyPreviewError();
}
else if (replyTile) {
return new ReplyPreviewView(replyTile);
return new ReplyPreviewView(replyTile, this._viewClassForTile);
}
else {
return null;