import {Profile} from 'common/profiles/profile' import {User} from 'common/user' import {groupBy, orderBy} from 'lodash' import {useState} from 'react' import {toast} from 'react-hot-toast' import {Col} from 'web/components/layout/col' import {Row} from 'web/components/layout/row' import {ProfileCommentInput, ProfileProfileCommentThread} from 'web/components/profile-comments' import ShortToggle from 'web/components/widgets/short-toggle' import {Tooltip} from 'web/components/widgets/tooltip' import {useLiveCommentsOnProfile} from 'web/hooks/use-comments-on-profile' import {updateProfile} from 'web/lib/api' import {useT} from 'web/lib/locale' import {Subtitle} from './widgets/profile-subtitle' export const ProfileCommentSection = (props: { onUser: User profile: Profile currentUser: User | null | undefined simpleView?: boolean }) => { const {onUser, currentUser, simpleView} = props const t = useT() const comments = useLiveCommentsOnProfile(onUser.id).filter((c) => !c.hidden) const parentComments = comments.filter((c) => !c.replyToCommentId) const commentsByParent = groupBy(comments, (c) => c.replyToCommentId ?? '_') const [profile, setProfile] = useState(props.profile) const isCurrentUser = currentUser?.id === onUser.id if (!currentUser && (!profile.comments_enabled || parentComments.length == 0)) return null return ( {t('profile.comments.section_title', 'Endorsements')} {isCurrentUser && !simpleView && ( { const update = {comments_enabled: on} setProfile((l) => ({...l, ...update})) toast.promise(updateProfile(update), { loading: on ? t('profile.comments.enabling', 'Enabling endorsements from others') : t('profile.comments.disabling', 'Disabling endorsements from others'), success: on ? t('profile.comments.enabled', 'Endorsements enabled from others') : t('profile.comments.disabled', 'Endorsements disabled from others'), error: t('profile.comments.update_error', 'Failed to update endorsement status'), }) }} /> )} {!simpleView && ( <> {currentUser && profile.comments_enabled && ( <>
{isCurrentUser ? ( <> {t( 'profile.comments.current_user_hint', 'Other users can write endorsements of you here.', )} ) : ( <> {t( 'profile.comments.other_user_hint', 'If you know them, write something nice that adds to their profile.', )} )}
{!isCurrentUser && ( )} )} {!profile.comments_enabled && (isCurrentUser ? ( {t('profile.comments.feature_disabled_self', 'This feature is disabled')} ) : ( {t( 'profile.comments.feature_disabled_other', '{name} has disabled endorsements from others.', {name: onUser.name}, )} ))} )} {profile.comments_enabled && orderBy(parentComments, 'createdTime', 'desc').map((c) => ( ))} ) }