Files
Compass/web/components/widgets/hide-profile-button.tsx
Okechi Jones-Williams 549eba0bbe [User functionality] Messages UI page and messaging helpers added for end-to-end scenarios (#53)
* Added Database checks to the onboarding flow

* Added compatibility page setup
Added more compatibility questions

* Finished up the onboarding flow suite
Added compatibility question tests and verifications
Updated tests to cover Keywords and Headline changes recently made
Updated tests to cover all of the big5 personality traits

* .

* Fix: Merge conflict

* .

* Fix: Added fix for None discriptive error issue #36
Updated signUp.spec.ts to use new fixture
Updated Account information variable names
Deleted "deleteUserFixture.ts" as it was incorporated into the "base.ts" file

* Linting and Prettier

* Minor cleaning

* Added Google account to the Onboarding flow

* Added account cleanup for google accounts

* Started work on Sign-in tests
Updated seedDatabase.ts to throw an error if the user already exists, to also add display names and usernames so they seedUser func acts like a normal basic user
Some organising of the google auth code

* Linting and Prettier

* Added checks to the deleteUser func to check if the accout exists
Added account deletion checks

* Linting and Prettier

* Formatting update, fixed homePage locator for signin

* .

* .

* .

* Coderabbitai fix's

* Fix

* Improve test utilities and stabilize onboarding flow tests

* Changes requested

* Changed POM/Fixture structure to use an app class to instantiate the page objects

* Apply suggestion from @MartinBraquet

* Delete .vscode/settings.json

* Apply suggestion from @MartinBraquet

* Apply suggestion from @MartinBraquet

* Apply suggestion from @MartinBraquet

* Linting and Prettier

* Updated People page

* Fix app.ts

* Updated peoplePage.ts: continued adding functions to use filters
Updated filters.tsx: added data testid

* Coderabbitai fix's

* .

* Updated People page
Added data test attributes to search.tsx and profile-grid.tsx

* Lint and Prettier

* .

* Continued work on filter tests
Added testid attributes to people page so the info from the results can be accessed

* Added more filter tests

* Added tests for hiding profiles

* Added a context manager to test with multiple accounts interacting with each other
Added an option to verify the users email when creating an account

* Added Tests for sending/recieving messages
Added tests for staring/favoriting profiles
Added testIds where necessary
Added messagesPage.ts
Updated peoplePage.ts

* Linting and Prettier

* Coderabbit suggestions

* CodeRabbit suggestion #2

* Fix #1

* Minor fixes

* TC fix

---------

Co-authored-by: MartinBraquet <martin.braquet@gmail.com>
2026-05-29 01:00:57 +02:00

105 lines
3.0 KiB
TypeScript

import {EyeIcon, EyeSlashIcon} from '@heroicons/react/24/outline'
import clsx from 'clsx'
import {useMemo, useState} from 'react'
import {Tooltip} from 'web/components/widgets/tooltip'
import {useHiddenProfiles} from 'web/hooks/use-hidden-profiles'
import {api} from 'web/lib/api'
import {useT} from 'web/lib/locale'
export type HideProfileButtonProps = {
hiddenUserId: string
onHidden?: (userId: string) => void
className?: string
iconClassName?: string
tooltip?: string
ariaLabel?: string
stopPropagation?: boolean
eyeOff?: boolean
onPointerDown?: () => void
}
export function HideProfileButton(props: HideProfileButtonProps) {
const {
hiddenUserId,
onHidden,
className,
iconClassName,
tooltip,
ariaLabel,
stopPropagation,
eyeOff,
onPointerDown,
} = props
const t = useT()
const [submitting, setSubmitting] = useState(false)
const {hiddenProfiles, refreshHiddenProfiles} = useHiddenProfiles()
const [optimisticHidden, setOptimisticHidden] = useState<boolean | undefined>(undefined)
const hidden = useMemo(() => {
if (optimisticHidden !== undefined) return optimisticHidden
return hiddenProfiles?.some((u) => u.id === hiddenUserId) ?? false
}, [hiddenProfiles, hiddenUserId, optimisticHidden])
const onClick = async (e: React.MouseEvent) => {
e.preventDefault()
if (stopPropagation) e.stopPropagation()
if (submitting) return
setSubmitting(true)
// Optimistically update hidden state
setOptimisticHidden(!hidden)
try {
if (hidden) {
await api('unhide-profile', {hiddenUserId})
} else {
await api('hide-profile', {hiddenUserId})
}
refreshHiddenProfiles()
onHidden?.(hiddenUserId)
} catch (e) {
console.error('Failed to toggle hide profile', e)
// Revert optimistic update on failure
setOptimisticHidden(hidden)
} finally {
setSubmitting(false)
}
}
return (
<Tooltip
text={
hidden
? t('profile_grid.unhide_profile', 'Show again in search results')
: (tooltip ?? t('profile_grid.hide_profile', "Don't show again in search results"))
}
noTap
>
<button
data-testid="hide-profile-button"
className={clsx(
'relative inline-flex items-center justify-center border bg-canvas-50 border-canvas-300 text-ink-300 hover:border-primary-400 hover:bg-primary-50 rounded-lg h-7 w-7',
className,
)}
disabled={submitting}
onClick={onClick}
onPointerDown={onPointerDown}
aria-label={
ariaLabel ??
(hidden
? t('profile_grid.unhide_profile', 'Unhide this profile')
: t('profile_grid.hide_profile', 'Hide this profile'))
}
>
{hidden || eyeOff ? (
<EyeSlashIcon className={clsx('h-4 w-4 text-ink-500', iconClassName)} />
) : (
<EyeIcon className={clsx('h-4 w-4 text-ink-500', iconClassName)} />
)}
</button>
</Tooltip>
)
}
export default HideProfileButton