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

View file

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

View file

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

View file

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