From 72c27e339ccbe7ee88f59497bc27b60ec18d3c82 Mon Sep 17 00:00:00 2001 From: Felipe Bueno Date: Fri, 3 May 2024 18:39:21 -0300 Subject: [PATCH] UserPopover (#1094) * WIP UserPopover * Add show delay on UserPopover * UserDetails -> StackingSince on UserPopover * Make UserPopover hoverable * Add felipe to contributors.txt * Remove export from SocialLink * Remove @ outside of UserPopover * userQuery -> useLazyQuery + Handling user not found * Move styles to user-popover.module.css * Update components/user-popover.module.css Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Remove poll + SSR check from useLazyQuery * USER_FULL -> USER (we are only using stacking since, for now) * refine user popover --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com> Co-authored-by: keyan --- components/item-info.js | 11 ++-- components/text.js | 14 ++++- components/user-list.js | 90 ++++++++++++++++++------------ components/user-popover.js | 82 +++++++++++++++++++++++++++ components/user-popover.module.css | 8 +++ contributors.txt | 3 +- 6 files changed, 165 insertions(+), 43 deletions(-) create mode 100644 components/user-popover.js create mode 100644 components/user-popover.module.css diff --git a/components/item-info.js b/components/item-info.js index c8fa5224..a0422e82 100644 --- a/components/item-info.js +++ b/components/item-info.js @@ -21,6 +21,7 @@ import MuteDropdownItem from './mute' import { DropdownItemUpVote } from './upvote' import { useRoot } from './root' import { MuteSubDropdownItem, PinSubDropdownItem } from './territory-header' +import UserPopover from './user-popover' export default function ItemInfo ({ item, full, commentsText = 'comments', @@ -101,10 +102,12 @@ export default function ItemInfo ({ \ - - @{item.user.name} - {embellishUser} - + + + @{item.user.name} + {embellishUser} + + {timeSince(new Date(item.createdAt))} diff --git a/components/text.js b/components/text.js index d130ce76..551b565a 100644 --- a/components/text.js +++ b/components/text.js @@ -21,6 +21,7 @@ import { useRouter } from 'next/router' import Link from 'next/link' import { UNKNOWN_LINK_REL } from '@/lib/constants' import isEqual from 'lodash/isEqual' +import UserPopover from './user-popover' export function SearchText ({ text }) { return ( @@ -196,7 +197,18 @@ export default memo(function Text ({ rel, imgproxyUrls, children, tab, itemId, o ) } - if (href.startsWith('/') || url?.origin === internalURL) { + if (text.startsWith('@')) { + return ( + + + {text} + + + ) + } else if (href.startsWith('/') || url?.origin === internalURL) { return ( (user.optional.stacked !== null && {abbrNum(user.optional.stacked)} stacked) @@ -39,7 +40,29 @@ function seperate (arr, seperator) { return arr.flatMap((x, i) => i < arr.length - 1 ? [x, seperator] : [x]) } -function User ({ user, rank, statComps, Embellish, nymActionDropdown = false }) { +export function UserBase ({ user, className, children, nymActionDropdown }) { + return ( +
+ + + +
+
+ + @{user.name} + + {nymActionDropdown && } +
+ {children} +
+
+ ) +} + +export function User ({ user, rank, statComps, className = 'mb-2', Embellish, nymActionDropdown = false }) { const me = useMe() const showStatComps = statComps && statComps.length > 0 return ( @@ -50,27 +73,12 @@ function User ({ user, rank, statComps, Embellish, nymActionDropdown = false }) {rank} ) :
} -
- - - -
-
- - @{user.name} - - {nymActionDropdown && } -
- {showStatComps && -
- {statComps.map((Comp, i) => )} -
} - {Embellish && } -
-
+ + {showStatComps && +
+ {statComps.map((Comp, i) => )} +
} +
) } @@ -152,23 +160,31 @@ export function UsersSkeleton () { return (
{users.map((_, i) => ( -
- -
-
-
- - - - -
+ +
+ + + +
-
+ ))}
) } + +export function UserSkeleton ({ children, className }) { + return ( +
+ +
+
+ {children} +
+
+ ) +} diff --git a/components/user-popover.js b/components/user-popover.js new file mode 100644 index 00000000..445ec2c7 --- /dev/null +++ b/components/user-popover.js @@ -0,0 +1,82 @@ +import { USER } from '@/fragments/users' +import errorStyles from '@/styles/error.module.css' +import { useLazyQuery } from '@apollo/client' +import Link from 'next/link' +import { useRef, useState } from 'react' +import { Popover } from 'react-bootstrap' +import OverlayTrigger from 'react-bootstrap/OverlayTrigger' +import { UserBase, UserSkeleton } from './user-list' +import styles from './user-popover.module.css' +import classNames from 'classnames' + +function StackingSince ({ since }) { + return ( + + stacking since:{' '} + {since + ? #{since} + : never} + + ) +} + +export default function UserPopover ({ name, children }) { + const [showOverlay, setShowOverlay] = useState(false) + + const [getUser, { loading, data }] = useLazyQuery( + USER, + { + variables: { name }, + fetchPolicy: 'cache-first' + } + ) + + const timeoutId = useRef(null) + + const handleMouseEnter = () => { + clearTimeout(timeoutId.current) + getUser() + timeoutId.current = setTimeout(() => { + setShowOverlay(true) + }, 500) + } + + const handleMouseLeave = () => { + clearTimeout(timeoutId.current) + timeoutId.current = setTimeout(() => setShowOverlay(false), 100) + } + + return ( + + + {!data || loading + ? + : !data.user + ?

USER NOT FOUND

+ : ( + + + + )} +
+ + } + > + + {children} + +
+ ) +} diff --git a/components/user-popover.module.css b/components/user-popover.module.css new file mode 100644 index 00000000..20d8ca76 --- /dev/null +++ b/components/user-popover.module.css @@ -0,0 +1,8 @@ +.userPopover { + border: 1px solid var(--theme-toolbarActive) +} + +.userPopBody { + font-weight: 500; + font-size: 0.9rem; +} diff --git a/contributors.txt b/contributors.txt index 97e27194..4fe905f1 100644 --- a/contributors.txt +++ b/contributors.txt @@ -7,4 +7,5 @@ bitcoinplebdev benthecarman stargut mz -btcbagehot \ No newline at end of file +btcbagehot +felipe