From cf8ca176e28d5f40389fa706858e044e9527f4c2 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 10 Sep 2019 16:07:01 +0200 Subject: [PATCH] remove labels and add join/view & preview button instead in directory --- src/components/structures/RoomDirectory.js | 159 ++++++++++++--------- src/i18n/strings/en_EN.json | 2 + 2 files changed, 93 insertions(+), 68 deletions(-) diff --git a/src/components/structures/RoomDirectory.js b/src/components/structures/RoomDirectory.js index 83827acfae..82b0e84bd6 100644 --- a/src/components/structures/RoomDirectory.js +++ b/src/components/structures/RoomDirectory.js @@ -322,7 +322,7 @@ module.exports = React.createClass({ } }, - onJoinClick: function(alias) { + onJoinFromSearchClick: function(alias) { // If we don't have a particular instance id selected, just show that rooms alias if (!this.state.instanceId) { // If the user specified an alias without a domain, add on whichever server is selected @@ -364,6 +364,34 @@ module.exports = React.createClass({ } }, + onPreviewClick: function(room) { + this.props.onFinished(); + dis.dispatch({ + action: 'view_room', + room_id: room.room_id, + should_peek: true, + }); + }, + + onViewClick: function(room) { + this.props.onFinished(); + dis.dispatch({ + action: 'view_room', + room_id: room.room_id, + should_peek: false, + }); + }, + + onJoinClick: function(room) { + this.props.onFinished(); + MatrixClientPeg.get().joinRoom(room.room_id); + dis.dispatch({ + action: 'view_room', + room_id: room.room_id, + joining: true, + }); + }, + showRoomAlias: function(alias, autoJoin=false) { this.showRoom(null, alias, autoJoin); }, @@ -408,74 +436,69 @@ module.exports = React.createClass({ dis.dispatch(payload); }, - getRows: function() { + getRow(room) { + const client = MatrixClientPeg.get(); + const clientRoom = client.getRoom(room.room_id); + const hasJoinedRoom = clientRoom && clientRoom.getMyMembership() === "join"; + const isGuest = client.isGuest(); const BaseAvatar = sdk.getComponent('avatars.BaseAvatar'); + const AccessibleButton = sdk.getComponent('elements.AccessibleButton'); + let previewButton; + let joinOrViewButton; - if (!this.state.publicRooms) return []; - - const rooms = this.state.publicRooms; - const rows = []; - const self = this; - let guestRead; let guestJoin; let perms; - for (let i = 0; i < rooms.length; i++) { - guestRead = null; - guestJoin = null; - - if (rooms[i].world_readable) { - guestRead = ( -
{ _t('World readable') }
- ); - } - if (rooms[i].guest_can_join) { - guestJoin = ( -
{ _t('Guests can join') }
- ); - } - - perms = null; - if (guestRead || guestJoin) { - perms =
{guestRead}{guestJoin}
; - } - - let name = rooms[i].name || get_display_alias_for_room(rooms[i]) || _t('Unnamed room'); - if (name.length > MAX_NAME_LENGTH) { - name = `${name.substring(0, MAX_NAME_LENGTH)}...`; - } - - let topic = rooms[i].topic || ''; - if (topic.length > MAX_TOPIC_LENGTH) { - topic = `${topic.substring(0, MAX_TOPIC_LENGTH)}...`; - } - topic = linkifyAndSanitizeHtml(topic); - - rows.push( - {ev.preventDefault();}} - > - - - - -
{ name }
  - { perms } -
-
{ get_display_alias_for_room(rooms[i]) }
- - - { rooms[i].num_joined_members } - - , + if (room.world_readable && !hasJoinedRoom) { + previewButton = ( + this.onPreviewClick(room)}>{_t("Preview")} ); } - return rows; + if (hasJoinedRoom) { + joinOrViewButton = ( + this.onViewClick(room)}>{_t("View")} + ); + } else if (!isGuest || room.guest_can_join) { + joinOrViewButton = ( + this.onJoinClick(room)}>{_t("Join")} + ); + } + + let name = room.name || get_display_alias_for_room(room) || _t('Unnamed room'); + if (name.length > MAX_NAME_LENGTH) { + name = `${name.substring(0, MAX_NAME_LENGTH)}...`; + } + + let topic = room.topic || ''; + if (topic.length > MAX_TOPIC_LENGTH) { + topic = `${topic.substring(0, MAX_TOPIC_LENGTH)}...`; + } + topic = linkifyAndSanitizeHtml(topic); + + return ( + this.onRoomClicked(room)} + // cancel onMouseDown otherwise shift-clicking highlights text + onMouseDown={(ev) => {ev.preventDefault();}} + > + + + + +
{ name }
  +
+
{ get_display_alias_for_room(room) }
+ + + { room.num_joined_members } + + {previewButton} + {joinOrViewButton} + + ); }, collectScrollPanel: function(element) { @@ -529,7 +552,7 @@ module.exports = React.createClass({ } else if (this.state.protocolsLoading || this.state.loading) { content = ; } else { - const rows = this.getRows(); + const rows = (this.state.publicRooms || []).map(room => this.getRow(room)); // we still show the scrollpanel, at least for now, because // otherwise we don't fetch more because we don't get a fill // request from the scrollpanel because there isn't one @@ -539,7 +562,7 @@ module.exports = React.createClass({ } else { scrollpanel_content = - { this.getRows() } + { rows }
; } @@ -591,7 +614,7 @@ module.exports = React.createClass({ listHeader =
diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index ca19fb8fe1..02bf52a2a4 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1512,6 +1512,8 @@ "Couldn't find a matching Matrix room": "Couldn't find a matching Matrix room", "Fetching third party location failed": "Fetching third party location failed", "Unable to look up room ID from server": "Unable to look up room ID from server", + "Preview": "Preview", + "View": "View", "Search for a room": "Search for a room", "Search for a room like #example": "Search for a room like #example", "Message not sent due to unknown devices being present": "Message not sent due to unknown devices being present",