Skip to content

Commit 4cb29d2

Browse files
committed
Add floating info box
1 parent df55d63 commit 4cb29d2

File tree

3 files changed

+80
-18
lines changed

3 files changed

+80
-18
lines changed

web/components/bio/profile-bio.tsx

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,61 @@
11
import {Profile} from 'common/love/profile'
2-
import {useEffect, useState} from 'react'
2+
import React, {useEffect, useState} from 'react'
33
import {Col} from 'web/components/layout/col'
44
import {Subtitle} from '../widgets/profile-subtitle'
55
import {BioBlock} from './profile-bio-block'
66
import {MAX_INT, MIN_BIO_LENGTH} from "common/constants";
77
import {useTextEditor} from "web/components/widgets/editor";
88
import {JSONContent} from "@tiptap/core"
9+
import {flip, offset, shift, useFloating} from "@floating-ui/react-dom";
10+
11+
export default function TooShortBio() {
12+
const [open, setOpen] = useState(false);
13+
const {y, refs, strategy} = useFloating({
14+
placement: "bottom", // place below the trigger
15+
middleware: [
16+
offset(8), // small gap between ? and box
17+
flip(),
18+
shift({padding: 8}), // prevent viewport clipping
19+
],
20+
});
21+
22+
return (
23+
<p className="text-red-600">
24+
Bio too short. Profile may be filtered from search results.{" "}
25+
<span
26+
className="inline-flex align-middle"
27+
onMouseEnter={() => setOpen(true)}
28+
onMouseLeave={() => setOpen(false)}
29+
ref={refs.setReference}
30+
>
31+
<span
32+
className="cursor-help text-red-600 border border-red-600 rounded-full w-5 h-5 inline-flex items-center justify-center align-middle">
33+
?
34+
</span>
35+
</span>
36+
37+
{open && (
38+
<div
39+
ref={refs.setFloating}
40+
style={{
41+
position: strategy,
42+
top: y ?? 0,
43+
left: "50%",
44+
transform: `translateX(-50%)`,
45+
}}
46+
className="p-3 bg-canvas-50 rounded-lg shadow-lg border border-gray-200 dark:border-gray-700 z-50 transition-opacity w-72 max-w-[calc(100vw-1rem)] whitespace-normal break-words"
47+
>
48+
<p className="text-sm text-gray-800 dark:text-gray-100">
49+
Since your bio is too short, Compass' algorithm filters out your
50+
profile from search results (unless "Include short bios" is
51+
selected). This ensures searches show meaningful profiles.
52+
</p>
53+
</div>
54+
)}
55+
</p>
56+
);
57+
}
58+
959

1060
export function ProfileBio(props: {
1161
isCurrentUser: boolean
@@ -29,23 +79,7 @@ export function ProfileBio(props: {
2979

3080
return (
3181
<Col>
32-
{textLength < MIN_BIO_LENGTH && !edit && (
33-
<div className="group relative inline-block">
34-
<p className="text-red-600 cursor-help flex items-center gap-1">
35-
Bio too short. Profile may be filtered from search results.
36-
<span className="text-xs border border-red-600 rounded px-1 animate-pulse">
37-
Hover for details
38-
</span>
39-
</p>
40-
<div
41-
className="invisible group-hover:visible absolute left-0 top-full mt-2 p-3 bg-canvas-50 rounded-lg shadow-lg border border-gray-200 dark:border-gray-700 w-72 z-10">
42-
<p className="text-sm">
43-
Since your bio is too short, Compass' algorithm filters out your profile from search results (unless
44-
"Include short bios" is selected). This ensures searches show meaningful profiles.
45-
</p>
46-
</div>
47-
</div>
48-
)}
82+
{textLength < MIN_BIO_LENGTH && !edit && <TooShortBio/>}
4983
<Subtitle className="mb-4">About Me</Subtitle>
5084
<BioBlock
5185
isCurrentUser={isCurrentUser}

web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
},
2121
"dependencies": {
2222
"@floating-ui/react": "0.19.0",
23+
"@floating-ui/react-dom": "2.1.6",
2324
"@google-cloud/secret-manager": "4.2.1",
2425
"@headlessui/react": "1.7.11",
2526
"@heroicons/react": "1.0.6",

yarn.lock

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,6 +1612,13 @@
16121612
dependencies:
16131613
"@floating-ui/utils" "^0.2.0"
16141614

1615+
"@floating-ui/core@^1.7.3":
1616+
version "1.7.3"
1617+
resolved "https://registry.yarnpkg.com/@floating-ui/core/-/core-1.7.3.tgz#462d722f001e23e46d86fd2bd0d21b7693ccb8b7"
1618+
integrity sha512-sGnvb5dmrJaKEZ+LDIpguvdX3bDlEllmv4/ClQ9awcmCZrlx5jQyyMWFM5kBI+EyNOCDDiKk8il0zeuX3Zlg/w==
1619+
dependencies:
1620+
"@floating-ui/utils" "^0.2.10"
1621+
16151622
"@floating-ui/dom@^1.2.1":
16161623
version "1.6.5"
16171624
resolved "https://registry.yarnpkg.com/@floating-ui/dom/-/dom-1.6.5.tgz#323f065c003f1d3ecf0ff16d2c2c4d38979f4cb9"
@@ -1620,6 +1627,21 @@
16201627
"@floating-ui/core" "^1.0.0"
16211628
"@floating-ui/utils" "^0.2.0"
16221629

1630+
"@floating-ui/dom@^1.7.4":
1631+
version "1.7.4"
1632+
resolved "https://registry.yarnpkg.com/@floating-ui/dom/-/dom-1.7.4.tgz#ee667549998745c9c3e3e84683b909c31d6c9a77"
1633+
integrity sha512-OOchDgh4F2CchOX94cRVqhvy7b3AFb+/rQXyswmzmGakRfkMgoWVjfnLWkRirfLEfuD4ysVW16eXzwt3jHIzKA==
1634+
dependencies:
1635+
"@floating-ui/core" "^1.7.3"
1636+
"@floating-ui/utils" "^0.2.10"
1637+
1638+
"@floating-ui/[email protected]":
1639+
version "2.1.6"
1640+
resolved "https://registry.yarnpkg.com/@floating-ui/react-dom/-/react-dom-2.1.6.tgz#189f681043c1400561f62972f461b93f01bf2231"
1641+
integrity sha512-4JX6rEatQEvlmgU80wZyq9RT96HZJa88q8hp0pBd+LrczeDI4o6uA2M+uvxngVHo4Ihr8uibXxH6+70zhAFrVw==
1642+
dependencies:
1643+
"@floating-ui/dom" "^1.7.4"
1644+
16231645
"@floating-ui/react-dom@^1.2.2":
16241646
version "1.3.0"
16251647
resolved "https://registry.yarnpkg.com/@floating-ui/react-dom/-/react-dom-1.3.0.tgz#4d35d416eb19811c2b0e9271100a6aa18c1579b3"
@@ -1641,6 +1663,11 @@
16411663
resolved "https://registry.yarnpkg.com/@floating-ui/utils/-/utils-0.2.2.tgz#d8bae93ac8b815b2bd7a98078cf91e2724ef11e5"
16421664
integrity sha512-J4yDIIthosAsRZ5CPYP/jQvUAQtlZTTD/4suA08/FEnlxqW3sKS9iAhgsa9VYLZ6vDHn/ixJgIqRQPotoBjxIw==
16431665

1666+
"@floating-ui/utils@^0.2.10":
1667+
version "0.2.10"
1668+
resolved "https://registry.yarnpkg.com/@floating-ui/utils/-/utils-0.2.10.tgz#a2a1e3812d14525f725d011a73eceb41fef5bc1c"
1669+
integrity sha512-aGTxbpbg8/b5JfU1HXSrbH3wXZuLPJcNEcZQFMxLs3oSzgtVu6nFPkbbGGUvBcUjKV2YyB9Wxxabo+HEH9tcRQ==
1670+
16441671
"@google-cloud/firestore@^7.11.0":
16451672
version "7.11.3"
16461673
resolved "https://registry.yarnpkg.com/@google-cloud/firestore/-/firestore-7.11.3.tgz#87cc3a58c5c297d6c9ca0e486fbf16b403585721"

0 commit comments

Comments
 (0)