|
1 | | -import { Profile } from 'common/love/profile' |
2 | | -import { useState } from 'react' |
3 | | -import { Col } from 'web/components/layout/col' |
4 | | -import { Subtitle } from '../widgets/profile-subtitle' |
5 | | -import { BioBlock } from './profile-bio-block' |
| 1 | +import {Profile} from 'common/love/profile' |
| 2 | +import {useEffect, useState} from 'react' |
| 3 | +import {Col} from 'web/components/layout/col' |
| 4 | +import {Subtitle} from '../widgets/profile-subtitle' |
| 5 | +import {BioBlock} from './profile-bio-block' |
| 6 | +import {MAX_INT, MIN_BIO_LENGTH} from "common/constants"; |
| 7 | +import {useTextEditor} from "web/components/widgets/editor"; |
| 8 | +import {JSONContent} from "@tiptap/core" |
6 | 9 |
|
7 | 10 | export function ProfileBio(props: { |
8 | 11 | isCurrentUser: boolean |
9 | 12 | profile: Profile |
10 | 13 | refreshProfile: () => void |
11 | 14 | fromProfilePage?: Profile |
12 | 15 | }) { |
13 | | - const { isCurrentUser, profile, refreshProfile, fromProfilePage } = props |
| 16 | + const {isCurrentUser, profile, refreshProfile, fromProfilePage} = props |
14 | 17 | const [edit, setEdit] = useState(false) |
15 | 18 |
|
16 | 19 | if (!isCurrentUser && !profile.bio) return null |
17 | 20 | if (fromProfilePage && !profile.bio) return null |
18 | 21 |
|
| 22 | + const editor = useTextEditor({defaultValue: ''}) |
| 23 | + const [textLength, setTextLength] = useState(editor?.getText().length ?? MAX_INT) |
| 24 | + |
| 25 | + useEffect(() => { |
| 26 | + if (!editor) return |
| 27 | + editor.commands.setContent(profile.bio as JSONContent) |
| 28 | + setTextLength(editor.getText().length) |
| 29 | + }, [profile.bio, editor]) |
| 30 | + |
19 | 31 | return ( |
20 | 32 | <Col> |
| 33 | + {textLength < MIN_BIO_LENGTH && !edit && ( |
| 34 | + <div className="group relative inline-block"> |
| 35 | + <p className="text-red-600 cursor-help flex items-center gap-1"> |
| 36 | + Bio too short. Profile may be filtered from search results. |
| 37 | + <span className="text-xs border border-red-600 rounded px-1 animate-pulse"> |
| 38 | + Hover for details |
| 39 | + </span> |
| 40 | + </p> |
| 41 | + <div |
| 42 | + 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"> |
| 43 | + <p className="text-sm"> |
| 44 | + Since your bio is too short, Compass' algorithm filters out your profile from search results (unless |
| 45 | + "Include short bios" is selected). This ensures searches show meaningful profiles. |
| 46 | + </p> |
| 47 | + </div> |
| 48 | + </div> |
| 49 | + )} |
21 | 50 | <Subtitle className="mb-4">About Me</Subtitle> |
22 | 51 | <BioBlock |
23 | 52 | isCurrentUser={isCurrentUser} |
|
0 commit comments