diff --git a/src/sections/Chat/OnlineUsers/User/index.tsx b/src/components/Dot/index.tsx similarity index 53% rename from src/sections/Chat/OnlineUsers/User/index.tsx rename to src/components/Dot/index.tsx index 8bcd6fa..07ad8ed 100644 --- a/src/sections/Chat/OnlineUsers/User/index.tsx +++ b/src/components/Dot/index.tsx @@ -8,39 +8,65 @@ import { User } from 'store/types' type Props = { user: User + isDraft?: boolean + isPrivate?: boolean + isOnline?: boolean + pointOp?: boolean + showOverlay?: boolean } -export default ({ user }: Props) => { +export default ({ + user, + isDraft = false, + isPrivate = false, + isOnline = true, + showOverlay = false, + pointOp = false, +}: Props) => { const { state } = useGlobalState() const isCurrentUser = state.auth.user && user.user_id === state.auth.user.user_id + const isSystem = user.user_id === 'dotdot' + const userColor = user.contrastColor || `#${user.color}` let iconName: IconName = 'circle' let inactive = '' - // Set icon - if (user.icon) { - iconName = user.icon - } else if (isCurrentUser) { + // Icon name + if (isSystem) { + iconName = 'cog' + } else if (isDraft) { + iconName = 'circle-notch' + } else if (isPrivate) { + iconName = 'lock' + } else if (!isOnline || !user.isActive) { + iconName = 'meh' + } else if (isCurrentUser && pointOp) { iconName = 'dot-circle' + } else if (user.icon) { + iconName = user.icon } - // Set status if (!user.isActive) { - iconName = 'meh' inactive = ' (away)' } - // TODO: Do we need this? + // Set to far for other users let icon: IconProp = iconName - if (isCurrentUser) { + if (isCurrentUser && !isPrivate && !isDraft) { icon = ['far', iconName] } - const userColor = user.contrastColor || `#${user.color}` + const Icon = () => ( + + ) - return ( + const IconWithOverlay = () => ( { } > - + ) + + return showOverlay ? : } diff --git a/src/sections/Chat/Messages/Message/Heading/index.tsx b/src/sections/Chat/Messages/Message/Heading/index.tsx index 69ded75..5ef1479 100644 --- a/src/sections/Chat/Messages/Message/Heading/index.tsx +++ b/src/sections/Chat/Messages/Message/Heading/index.tsx @@ -6,6 +6,7 @@ import { OverlayTrigger, Tooltip } from 'react-bootstrap' import { User } from 'store/types' import styles from './index.module.scss' +import Dot from 'components/Dot' type Props = { user: User @@ -13,7 +14,6 @@ type Props = { isDraft: boolean isPrivate: boolean isOnline: boolean - isCurrentUser: boolean isReply?: boolean } @@ -23,65 +23,11 @@ const Heading = ({ isDraft, isPrivate, isOnline, - isCurrentUser, isReply, }: Props) => { - const userContrastColor = user.contrastColor || `#${user.color}` - const isSystem = user.user_id === 'dotdot' + const userColor = user.contrastColor || `#${user.color}` - let iconName: IconName = 'circle' - if (user.icon) { - iconName = user.icon - } else if (isCurrentUser) { - iconName = 'dot-circle' - } - - // special icons - if (isSystem) { - iconName = 'cog' - } else if (isDraft) { - iconName = 'circle-notch' - } else if (isPrivate) { - iconName = 'lock' - } else if (!isOnline) { - iconName = 'meh' - } - - let icon: IconProp = iconName - if (isCurrentUser && !isPrivate && !isDraft) { - icon = ['far', iconName] - } - - const UserIcon = () => { - const justIcon = ( - - ) - - return ( - - {isPrivate ? ( - - Private message from @{user.name} -
- Only you can see this. - - } - > - {justIcon} -
- ) : ( - justIcon - )} -
- ) - } - - const Username = () => ( - {user.name} - ) + const Username = () => {user.name} const TimeStamp = () => ( {timestamp.toLocaleTimeString([], { @@ -93,7 +39,17 @@ const Heading = ({ return ( <> - {!isReply && } + {!isReply && ( + + + + )}
diff --git a/src/sections/Chat/Messages/Message/index.tsx b/src/sections/Chat/Messages/Message/index.tsx index 34aaaf3..881f2c4 100644 --- a/src/sections/Chat/Messages/Message/index.tsx +++ b/src/sections/Chat/Messages/Message/index.tsx @@ -88,7 +88,6 @@ const MessageComponent = React.memo(({ message, onClick, reply }: Props) => { isOnline={isUserOnline} isDraft={message.attributes.draft} isPrivate={message.attributes.private} - isCurrentUser={userData.user_id === state.auth.user?.user_id} />
diff --git a/src/sections/Chat/OnlineUsers/index.tsx b/src/sections/Chat/OnlineUsers/index.tsx index eb7e307..1f41646 100644 --- a/src/sections/Chat/OnlineUsers/index.tsx +++ b/src/sections/Chat/OnlineUsers/index.tsx @@ -2,7 +2,7 @@ import React from 'react' import styles from './index.module.scss' import useGlobalState from 'store/state' -import User from './User' +import Dot from '../../../components/Dot' export default () => { const { state } = useGlobalState() @@ -12,7 +12,7 @@ export default () => { {state.onlineUsers.length} {state.onlineUsers.map((user) => ( - + ))} ) diff --git a/src/sections/Chat/Session/UserBadge/index.tsx b/src/sections/Chat/Session/UserBadge/index.tsx index 6d4148f..7063fda 100644 --- a/src/sections/Chat/Session/UserBadge/index.tsx +++ b/src/sections/Chat/Session/UserBadge/index.tsx @@ -4,6 +4,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import useGlobalState from 'store/state' import { IconProp } from '@fortawesome/fontawesome-svg-core' +import Dot from 'components/Dot' import styles from './index.module.scss' @@ -22,11 +23,8 @@ export default ({ onClick, small }: Props) => { return (