Rename TextualEvent to TextualEventView

This commit is contained in:
R Midhun Suresh 2025-07-31 15:26:24 +05:30
parent e8e50816f1
commit 2b366e82c5
No known key found for this signature in database
6 changed files with 15 additions and 14 deletions

View File

@ -8,7 +8,7 @@ Please see LICENSE files in the repository root for full details.
import React from "react";
import { type Meta, type StoryFn } from "@storybook/react-vite";
import { TextualEvent as TextualEventComponent } from "./TextualEvent";
import { TextualEventView as TextualEventComponent } from "./TextualEventView";
import { MockViewModel } from "../../MockViewModel";
export default {
@ -16,7 +16,7 @@ export default {
component: TextualEventComponent,
tags: ["autodocs"],
args: {
vm: new MockViewModel("Dummy textual event text"),
vm: new MockViewModel({ content: "Dummy textual event text" }),
},
} as Meta<typeof TextualEventComponent>;

View File

@ -9,11 +9,11 @@ import { composeStories } from "@storybook/react-vite";
import { render } from "jest-matrix-react";
import React from "react";
import * as stories from "./TextualEvent.stories.tsx";
import * as stories from "./TextualEventView.stories.tsx";
const { Default } = composeStories(stories);
describe("TextualEvent", () => {
describe("TextualEventView", () => {
it("renders a textual event", () => {
const { container } = render(<Default />);
expect(container).toMatchSnapshot();

View File

@ -10,14 +10,15 @@ import React, { type ReactNode, type JSX } from "react";
import { type ViewModel } from "../../ViewModel";
import { useViewModel } from "../../useViewModel";
export type TextualEventViewSnapshot = string | ReactNode;
export type TextualEventViewSnapshot = {
content: string | ReactNode;
};
export interface Props {
vm: ViewModel<TextualEventViewSnapshot>;
}
export function TextualEvent({ vm }: Props): JSX.Element {
const contents = useViewModel(vm);
return <div className="mx_TextualEvent">{contents}</div>;
export function TextualEventView({ vm }: Props): JSX.Element {
const snapshot = useViewModel(vm);
return <div className="mx_TextualEvent">{snapshot.content}</div>;
}

View File

@ -5,4 +5,4 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
Please see LICENSE files in the repository root for full details.
*/
export { TextualEvent } from "./TextualEvent";
export { TextualEventView } from "./TextualEventView";

View File

@ -10,18 +10,18 @@ import { MatrixEventEvent } from "matrix-js-sdk/src/matrix";
import { type EventTileTypeProps } from "../../events/EventTileFactory";
import { MatrixClientPeg } from "../../MatrixClientPeg";
import { textForEvent } from "../../TextForEvent";
import { type TextualEventViewSnapshot } from "../../shared-components/event-tiles/TextualEvent/TextualEvent";
import { type TextualEventViewSnapshot } from "../../shared-components/event-tiles/TextualEvent/TextualEventView";
import { BaseViewModel } from "../base/BaseViewModel";
export class TextualEventViewModel extends BaseViewModel<TextualEventViewSnapshot, EventTileTypeProps> {
public constructor(props: EventTileTypeProps) {
super(props, "");
super(props, { content: "" });
this.setTextFromEvent();
}
private setTextFromEvent = (): void => {
const text = textForEvent(this.props.mxEvent, MatrixClientPeg.safeGet(), true, this.props.showHiddenEvents);
this.snapshot.set(text);
const content = textForEvent(this.props.mxEvent, MatrixClientPeg.safeGet(), true, this.props.showHiddenEvents);
this.snapshot.set({ content });
};
protected addDownstreamSubscription = (): void => {