diff --git a/UI/app.tsx b/UI/app.tsx index 4e1c012..adbbaed 100644 --- a/UI/app.tsx +++ b/UI/app.tsx @@ -412,29 +412,23 @@ export function AppComponent(props: { ) { if (model.navigationModel.activeNav == "DM") { dmVNode = ( -
- {DirectMessageContainer({ - ...model.dm, - rightPanelModel: model.rightPanelModel, - bus: app.eventBus, - ctx: myAccountCtx, - profileGetter: app.database, - pool: props.pool, - conversationLists: app.conversationLists, - profilesSyncer: app.profileSyncer, - eventSyncer: app.eventSyncer, - pinListGetter: app.otherConfig, - groupChatController: app.groupChatController, - newMessageChecker: app.conversationLists, - messageGetter: model.dm.isGroupMessage ? app.groupChatController : app.dmController, - newMessageListener: model.dm.isGroupMessage - ? app.groupChatController - : app.dmController, - relayRecordGetter: app.database, - })} -
+ ); } @@ -446,7 +440,7 @@ export function AppComponent(props: { console.debug("AppComponent:2", Date.now() - t); const final = ( -
+
{ return (
-
+
, - ); +export class DirectMessageContainer extends Component { + changes?: PopChannel; - const canEditGroupProfile = props.groupChatController.getGroupAdminCtx(currentEditor.pubkey); - if (canEditGroupProfile) { + state: State = { + currentEditor: undefined, + }; + + componentWillUpdate(nextProps: Readonly): void { + this.setState({ + currentEditor: nextProps.currentEditor, + }); + } + + async componentDidMount() { + this.setState({ + currentEditor: this.props.currentEditor, + }); + + const changes = this.props.bus.onChange(); + this.changes = changes; + for await (const change of changes) { + if (change.type == "SelectConversation") { + // todo + } + } + } + + componentWillUnmount(): void { + if (this.changes) { + this.changes.close(); + } + } + + render(props: DirectMessageContainerProps) { + const t = Date.now(); + + const currentEditor = props.currentEditor; + let buttons = []; + if (currentEditor && IS_BETA_VERSION) { + if (props.isGroupMessage) { buttons.push( - // setting button , ); - } - } else { - buttons.push( - , - ); - } - } - const vDom = ( -
-
- -
- {props.currentEditor - ? ( -
-
{ + props.bus.emit({ + type: "StartEditGroupChatProfile", + ctx: canEditGroupProfile, + }); + }} > -
- - + , + ); + } + } else { + buttons.push( + , + ); + } + } + + const vDom = ( +
+
+ +
+ + {this.state.currentEditor + ? ( +
+ +
+ +
+
+ ) + : undefined} +
+ ); + console.debug("DirectMessageContainer:end", Date.now() - t); + return vDom; + } +} + +function TopBar(props: { + bus: EventBus; + currentEditor: EditorModel; + profileGetter: ProfileGetter; + showRightPanel: boolean; + buttons: VNode[]; +}) { + return ( +
+
+ + { - if (!props.currentEditor) { - return; - } - props.bus.emit({ - type: "ViewUserDetail", - pubkey: props.currentEditor.pubkey, - }); - }} - > - {props.profileGetter.getProfilesByPublicKey(props.currentEditor.pubkey) - ?.profile.name || - props.currentEditor.pubkey.bech32()} - -
-
- {buttons} + onClick={() => { + if (!props.currentEditor) { + return; + } + props.bus.emit({ + type: "ViewUserDetail", + pubkey: props.currentEditor.pubkey, + }); + }} + > + {props.profileGetter.getProfilesByPublicKey( + props.currentEditor.pubkey, + ) + ?.profile.name || + props.currentEditor.pubkey.bech32()} + +
+
+ {props.buttons} - {!props.rightPanelModel.show - ? ( - - ) - : undefined} -
-
-
- {props.currentEditor - ? ( - - ) - : undefined} -
-
- ) - : undefined} + {!props.showRightPanel + ? ( + + ) + : undefined} +
); - console.debug("DirectMessageContainer:end", Date.now() - t); - return vDom; }