From c9e967f05cb3abd9884064bcfb5f7dabaae8f0b7 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 25 Aug 2020 14:23:18 -0600 Subject: [PATCH 1/5] Don't override UserMenu with group changes --- src/components/structures/UserMenu.tsx | 43 ++------------------------ 1 file changed, 2 insertions(+), 41 deletions(-) diff --git a/src/components/structures/UserMenu.tsx b/src/components/structures/UserMenu.tsx index 839d4bccda..30be71abcb 100644 --- a/src/components/structures/UserMenu.tsx +++ b/src/components/structures/UserMenu.tsx @@ -42,9 +42,6 @@ import IconizedContextMenu, { IconizedContextMenuOption, IconizedContextMenuOptionList } from "../views/context_menus/IconizedContextMenu"; -import TagOrderStore from "../../stores/TagOrderStore"; -import * as fbEmitter from "fbemitter"; -import FlairStore from "../../stores/FlairStore"; interface IProps { isMinimized: boolean; @@ -55,16 +52,11 @@ type PartialDOMRect = Pick; interface IState { contextMenuPosition: PartialDOMRect; isDarkTheme: boolean; - selectedCommunityProfile: { - displayName: string; - avatarMxc: string; - }; } export default class UserMenu extends React.Component { private dispatcherRef: string; private themeWatcherRef: string; - private tagStoreRef: fbEmitter.EventSubscription; private buttonRef: React.RefObject = createRef(); constructor(props: IProps) { @@ -73,7 +65,6 @@ export default class UserMenu extends React.Component { this.state = { contextMenuPosition: null, isDarkTheme: this.isUserOnDarkTheme(), - selectedCommunityProfile: null, }; OwnProfileStore.instance.on(UPDATE_EVENT, this.onProfileUpdate); @@ -86,7 +77,6 @@ export default class UserMenu extends React.Component { public componentDidMount() { this.dispatcherRef = defaultDispatcher.register(this.onAction); this.themeWatcherRef = SettingsStore.watchSetting("theme", null, this.onThemeChanged); - this.tagStoreRef = TagOrderStore.addListener(this.onTagStoreUpdate); } public componentWillUnmount() { @@ -103,25 +93,6 @@ export default class UserMenu extends React.Component { return theme === "dark"; } - private onTagStoreUpdate = async () => { - if (!SettingsStore.getValue("feature_communities_v2_prototypes")) { - return; - } - - const selectedId = TagOrderStore.getSelectedTags()[0]; - if (!selectedId) { - this.setState({selectedCommunityProfile: null}); - return; - } - - // For some reason the group's profile info isn't on the js-sdk Group object but - // is in the flair store, so get it from there. - const profile = await FlairStore.getGroupProfileCached(MatrixClientPeg.get(), selectedId); - const displayName = profile.name || selectedId; - const avatarMxc = profile.avatarUrl; - this.setState({selectedCommunityProfile: {displayName, avatarMxc}}); - }; - private onProfileUpdate = async () => { // the store triggered an update, so force a layout update. We don't // have any state to store here for that to magically happen. @@ -324,18 +295,8 @@ export default class UserMenu extends React.Component { public render() { const avatarSize = 32; // should match border-radius of the avatar - let displayName = OwnProfileStore.instance.displayName || MatrixClientPeg.get().getUserId(); - let avatarUrl = OwnProfileStore.instance.getHttpAvatarUrl(avatarSize); - - if (this.state.selectedCommunityProfile) { - displayName = this.state.selectedCommunityProfile.displayName - const mxc = this.state.selectedCommunityProfile.avatarMxc; - if (mxc) { - avatarUrl = MatrixClientPeg.get().mxcUrlToHttp(mxc, avatarSize, avatarSize); - } else { - avatarUrl = null; - } - } + const displayName = OwnProfileStore.instance.displayName || MatrixClientPeg.get().getUserId(); + const avatarUrl = OwnProfileStore.instance.getHttpAvatarUrl(avatarSize); let name = {displayName}; let buttons = ( From 20c562c2086fed80fd4dfa111c4e7e7f06507e85 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 25 Aug 2020 21:45:38 -0600 Subject: [PATCH 2/5] Change user avatar to a home icon --- res/css/structures/_TagPanel.scss | 44 +++++++++++++++++-- res/img/element-icons/home.svg | 3 ++ src/components/views/elements/TagTile.js | 4 +- src/components/views/elements/UserTagTile.tsx | 31 ++++--------- 4 files changed, 54 insertions(+), 28 deletions(-) create mode 100644 res/img/element-icons/home.svg diff --git a/res/css/structures/_TagPanel.scss b/res/css/structures/_TagPanel.scss index 6c85341aaf..e7f67c8ace 100644 --- a/res/css/structures/_TagPanel.scss +++ b/res/css/structures/_TagPanel.scss @@ -75,6 +75,7 @@ limitations under the License. .mx_TagPanel .mx_TagTile { // opacity: 0.5; position: relative; + padding: 3px; } .mx_TagPanel .mx_TagTile:focus, .mx_TagPanel .mx_TagTile:hover, @@ -82,6 +83,45 @@ limitations under the License. // opacity: 1; } +.mx_TagPanel .mx_TagTile.mx_TagTile_selected_prototype { + background-color: $primary-bg-color; + border-radius: 6px; +} + +.mx_TagTile_selected_prototype { + .mx_TagTile_homeIcon::before { + background-color: $primary-fg-color; // dark-on-light + } +} + +.mx_TagTile:not(.mx_TagTile_selected_prototype) .mx_TagTile_homeIcon { + background-color: $icon-button-color; // XXX: Variable abuse + border-radius: 48px; + + &::before { + background-color: $primary-bg-color; // light-on-grey + } +} + +.mx_TagTile_homeIcon { + width: 32px; + height: 32px; + position: relative; + + &::before { + mask-image: url('$(res)/img/element-icons/home.svg'); + mask-position: center; + mask-repeat: no-repeat; + width: 21px; + height: 21px; + content: ''; + display: inline-block; + position: absolute; + top: calc(50% - 10.5px); + left: calc(50% - 10.5px); + } +} + .mx_TagPanel .mx_TagTile_plus { margin-bottom: 12px; height: 32px; @@ -116,10 +156,6 @@ limitations under the License. border-radius: 0 3px 3px 0; } -.mx_TagPanel .mx_TagTile.mx_TagTile_large.mx_TagTile_selected::before { - left: -10px; -} - .mx_TagPanel .mx_TagTile.mx_AccessibleButton:focus { filter: none; } diff --git a/res/img/element-icons/home.svg b/res/img/element-icons/home.svg new file mode 100644 index 0000000000..d65812cafd --- /dev/null +++ b/res/img/element-icons/home.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/components/views/elements/TagTile.js b/src/components/views/elements/TagTile.js index 49b336a577..562a478976 100644 --- a/src/components/views/elements/TagTile.js +++ b/src/components/views/elements/TagTile.js @@ -141,9 +141,11 @@ export default createReactClass({ profile.avatarUrl, avatarHeight, avatarHeight, "crop", ) : null; + const isPrototype = SettingsStore.getValue("feature_communities_v2_prototypes"); const className = classNames({ mx_TagTile: true, - mx_TagTile_selected: this.props.selected, + mx_TagTile_selected: this.props.selected && !isPrototype, + mx_TagTile_selected_prototype: this.props.selected && isPrototype, }); const badge = TagOrderStore.getGroupBadge(this.props.tag); diff --git a/src/components/views/elements/UserTagTile.tsx b/src/components/views/elements/UserTagTile.tsx index c652423753..635c537324 100644 --- a/src/components/views/elements/UserTagTile.tsx +++ b/src/components/views/elements/UserTagTile.tsx @@ -16,16 +16,14 @@ limitations under the License. import React from "react"; import defaultDispatcher from "../../../dispatcher/dispatcher"; -import { OwnProfileStore } from "../../../stores/OwnProfileStore"; -import { UPDATE_EVENT } from "../../../stores/AsyncStore"; import * as fbEmitter from "fbemitter"; import TagOrderStore from "../../../stores/TagOrderStore"; import AccessibleTooltipButton from "./AccessibleTooltipButton"; -import BaseAvatar from "../avatars/BaseAvatar"; -import { MatrixClientPeg } from "../../../MatrixClientPeg"; import classNames from "classnames"; +import { _t } from "../../../languageHandler"; -interface IProps{} +interface IProps { +} interface IState { selected: boolean; @@ -43,18 +41,13 @@ export default class UserTagTile extends React.PureComponent { } public componentDidMount() { - OwnProfileStore.instance.on(UPDATE_EVENT, this.onProfileUpdate); this.tagStoreRef = TagOrderStore.addListener(this.onTagStoreUpdate); } public componentWillUnmount() { - OwnProfileStore.instance.off(UPDATE_EVENT, this.onProfileUpdate); + this.tagStoreRef.remove(); } - private onProfileUpdate = () => { - this.forceUpdate(); - }; - private onTagStoreUpdate = () => { const selected = TagOrderStore.getSelectedTags().length === 0; this.setState({selected}); @@ -71,27 +64,19 @@ export default class UserTagTile extends React.PureComponent { public render() { // XXX: We reuse TagTile classes for ease of demonstration - we should probably generify // TagTile instead if we continue to use this component. - const avatarHeight = 36; - const name = OwnProfileStore.instance.displayName || MatrixClientPeg.get().getUserId(); const className = classNames({ mx_TagTile: true, - mx_TagTile_selected: this.state.selected, - mx_TagTile_large: true, + mx_TagTile_selected_prototype: this.state.selected, + mx_TagTile_home: true, }); return (
- +
); From 55001f319327d16acbbed92ecdd1da023bd3c52b Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 25 Aug 2020 21:52:48 -0600 Subject: [PATCH 3/5] Select the general chat for a community when viewing it --- src/stores/TagOrderStore.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/stores/TagOrderStore.js b/src/stores/TagOrderStore.js index 2b72a963b0..f02fce0769 100644 --- a/src/stores/TagOrderStore.js +++ b/src/stores/TagOrderStore.js @@ -166,6 +166,25 @@ class TagOrderStore extends Store { selectedTags: newTags, }); + if (!allowMultiple && newTags.length === 1) { + // We're in prototype behaviour: select the general chat for the community + const rooms = GroupStore.getGroupRooms(newTags[0]) + .map(r => MatrixClientPeg.get().getRoom(r.roomId)) + .filter(r => !!r); + let chat = rooms.find(r => { + const idState = r.currentState.getStateEvents("im.vector.general_chat", ""); + if (!idState || idState.getContent()['groupId'] !== newTags[0]) return false; + return true; + }); + if (!chat) chat = rooms[0]; + if (chat) { + dis.dispatch({ + action: 'view_room', + room_id: chat.roomId, + }); + } + } + Analytics.trackEvent('FilterStore', 'select_tag'); } break; From c68636bd32c4d2bae47d8efc5d7020542232f48a Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 25 Aug 2020 21:59:09 -0600 Subject: [PATCH 4/5] i18n updates --- src/i18n/strings/en_EN.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index c12b57c033..1fed9e0619 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1555,6 +1555,7 @@ "And %(count)s more...|other": "And %(count)s more...", "ex. @bob:example.com": "ex. @bob:example.com", "Add User": "Add User", + "Home": "Home", "Enter a server name": "Enter a server name", "Looks good": "Looks good", "Can't find this server or its room list": "Can't find this server or its room list", @@ -2097,7 +2098,6 @@ "Uploading %(filename)s and %(count)s others|other": "Uploading %(filename)s and %(count)s others", "Uploading %(filename)s and %(count)s others|zero": "Uploading %(filename)s", "Uploading %(filename)s and %(count)s others|one": "Uploading %(filename)s and %(count)s other", - "Home": "Home", "Switch to light mode": "Switch to light mode", "Switch to dark mode": "Switch to dark mode", "Switch theme": "Switch theme", From 0c67a42b0f16283bb7354b5868246240d308feeb Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 26 Aug 2020 08:42:26 -0600 Subject: [PATCH 5/5] Make padding only on the prototype tag panel --- res/css/structures/_TagPanel.scss | 4 ++++ src/components/views/elements/TagTile.js | 1 + src/components/views/elements/UserTagTile.tsx | 1 + 3 files changed, 6 insertions(+) diff --git a/res/css/structures/_TagPanel.scss b/res/css/structures/_TagPanel.scss index e7f67c8ace..2683a32dae 100644 --- a/res/css/structures/_TagPanel.scss +++ b/res/css/structures/_TagPanel.scss @@ -75,8 +75,12 @@ limitations under the License. .mx_TagPanel .mx_TagTile { // opacity: 0.5; position: relative; +} + +.mx_TagPanel .mx_TagTile.mx_TagTile_prototype { padding: 3px; } + .mx_TagPanel .mx_TagTile:focus, .mx_TagPanel .mx_TagTile:hover, .mx_TagPanel .mx_TagTile.mx_TagTile_selected { diff --git a/src/components/views/elements/TagTile.js b/src/components/views/elements/TagTile.js index 562a478976..db5eedc274 100644 --- a/src/components/views/elements/TagTile.js +++ b/src/components/views/elements/TagTile.js @@ -144,6 +144,7 @@ export default createReactClass({ const isPrototype = SettingsStore.getValue("feature_communities_v2_prototypes"); const className = classNames({ mx_TagTile: true, + mx_TagTile_prototype: isPrototype, mx_TagTile_selected: this.props.selected && !isPrototype, mx_TagTile_selected_prototype: this.props.selected && isPrototype, }); diff --git a/src/components/views/elements/UserTagTile.tsx b/src/components/views/elements/UserTagTile.tsx index 635c537324..912f54edc7 100644 --- a/src/components/views/elements/UserTagTile.tsx +++ b/src/components/views/elements/UserTagTile.tsx @@ -66,6 +66,7 @@ export default class UserTagTile extends React.PureComponent { // TagTile instead if we continue to use this component. const className = classNames({ mx_TagTile: true, + mx_TagTile_prototype: true, mx_TagTile_selected_prototype: this.state.selected, mx_TagTile_home: true, });