From 0232f3ee9828f8d305cdd66b644d0c180f289dd3 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 22 Sep 2022 21:49:03 -0400 Subject: [PATCH] fix: Don't show colored ring on inactive collaborators, closes #4130 --- app/components/Avatar/AvatarWithPresence.tsx | 183 ++++++++----------- app/components/Collaborators.tsx | 1 - 2 files changed, 78 insertions(+), 106 deletions(-) diff --git a/app/components/Avatar/AvatarWithPresence.tsx b/app/components/Avatar/AvatarWithPresence.tsx index 0f4d9c5d1..a66278d7a 100644 --- a/app/components/Avatar/AvatarWithPresence.tsx +++ b/app/components/Avatar/AvatarWithPresence.tsx @@ -1,141 +1,114 @@ -import { observable } from "mobx"; import { observer } from "mobx-react"; import * as React from "react"; -import { WithTranslation, withTranslation } from "react-i18next"; +import { useTranslation } from "react-i18next"; import styled, { css } from "styled-components"; import User from "~/models/User"; -import UserProfile from "~/scenes/UserProfile"; import Avatar from "~/components/Avatar"; import Tooltip from "~/components/Tooltip"; -type Props = WithTranslation & { +type Props = { user: User; isPresent: boolean; isEditing: boolean; isObserving: boolean; isCurrentUser: boolean; - profileOnClick: boolean; onClick?: React.MouseEventHandler; }; -@observer -class AvatarWithPresence extends React.Component { - @observable - isOpen = false; +function AvatarWithPresence({ + onClick, + user, + isPresent, + isEditing, + isObserving, + isCurrentUser, +}: Props) { + const { t } = useTranslation(); + const status = isPresent + ? isEditing + ? t("currently editing") + : t("currently viewing") + : t("previously edited"); - handleOpenProfile = () => { - this.isOpen = true; - }; - - handleCloseProfile = () => { - this.isOpen = false; - }; - - render() { - const { - onClick, - user, - isPresent, - isEditing, - isObserving, - isCurrentUser, - t, - } = this.props; - const status = isPresent - ? isEditing - ? t("currently editing") - : t("currently viewing") - : t("previously edited"); - - return ( - <> - - {user.name} {isCurrentUser && `(${t("You")})`} - {status && ( - <> -
- {status} - - )} - - } - placement="bottom" + return ( + <> + + {user.name} {isCurrentUser && `(${t("You")})`} + {status && ( + <> +
+ {status} + + )} + + } + placement="bottom" + > + - - - -
- {this.props.profileOnClick && ( - - )} - - ); - } + + +
+ + ); } const Centered = styled.div` text-align: center; `; -const AvatarWrapper = styled.div<{ +type AvatarWrapperProps = { $isPresent: boolean; $isObserving: boolean; $color: string; -}>` +}; + +const AvatarWrapper = styled.div` opacity: ${(props) => (props.$isPresent ? 1 : 0.5)}; transition: opacity 250ms ease-in-out; border-radius: 50%; position: relative; - &:after { - content: ""; - position: absolute; - top: 0; - left: 0; - right: 0; - bottom: 0; - border-radius: 50%; - transition: border-color 100ms ease-in-out; - border: 2px solid transparent; - pointer-events: none; + ${(props) => + props.$isPresent && + css` + &:after { + content: ""; + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + border-radius: 50%; + transition: border-color 100ms ease-in-out; + border: 2px solid transparent; + pointer-events: none; - ${(props) => - props.$isObserving && - css` - border: 2px solid ${props.$color}; - box-shadow: inset 0 0 0 2px ${props.theme.background}; + ${(props) => + props.$isObserving && + css` + border: 2px solid ${props.$color}; + box-shadow: inset 0 0 0 2px ${props.theme.background}; - &:hover { - top: -1px; - left: -1px; - right: -1px; - bottom: -1px; - } - `} - } + &:hover { + top: -1px; + left: -1px; + right: -1px; + bottom: -1px; + } + `} + } - &:hover:after { - border: 2px solid ${(props) => props.$color}; - box-shadow: inset 0 0 0 2px ${(props) => props.theme.background}; - } + &:hover:after { + border: 2px solid ${(props) => props.$color}; + box-shadow: inset 0 0 0 2px ${(props) => props.theme.background}; + } + `} `; -export default withTranslation()(AvatarWithPresence); +export default observer(AvatarWithPresence); diff --git a/app/components/Collaborators.tsx b/app/components/Collaborators.tsx index 05afe16b8..eb3ed0ba4 100644 --- a/app/components/Collaborators.tsx +++ b/app/components/Collaborators.tsx @@ -90,7 +90,6 @@ function Collaborators(props: Props) { isEditing={isEditing} isObserving={isObserving} isCurrentUser={currentUserId === collaborator.id} - profileOnClick={false} onClick={ isObservable ? (ev) => {