mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-02-19 15:27:16 -05:00
Remove toasts
This commit is contained in:
@@ -171,7 +171,6 @@ function ProfilePreview(props: {
|
||||
onHidden={onHide}
|
||||
className="ml-2"
|
||||
stopPropagation
|
||||
suppressToast
|
||||
/>
|
||||
)}
|
||||
</Row>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {useEffect, useMemo, useRef, useState} from 'react'
|
||||
import {useEffect, useMemo, useState} from 'react'
|
||||
import {Modal, MODAL_CLASS, SCROLLABLE_MODAL_CLASS} from 'web/components/layout/modal'
|
||||
import {Col} from 'web/components/layout/col'
|
||||
import {Row} from 'web/components/layout/row'
|
||||
@@ -30,9 +30,6 @@ export function HiddenProfilesModal(props: {
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [hidden, setHidden] = useState<HiddenUser[] | null>(null)
|
||||
const [busyIds, setBusyIds] = useState<Record<string, boolean>>({})
|
||||
// Throttle/batch success toasts when unhiding multiple profiles quickly
|
||||
const [pendingUnhideCount, setPendingUnhideCount] = useState(0)
|
||||
const toastTimerRef = useRef<number | ReturnType<typeof setTimeout> | null>(null)
|
||||
|
||||
const empty = useMemo(() => (hidden ? hidden.length === 0 : false), [hidden])
|
||||
|
||||
@@ -49,60 +46,20 @@ export function HiddenProfilesModal(props: {
|
||||
.catch((e) => {
|
||||
console.error('Failed to load hidden profiles', e)
|
||||
if (!alive) return
|
||||
setError(
|
||||
t(
|
||||
'settings.hidden_profiles.load_error',
|
||||
'Failed to load hidden profiles.'
|
||||
)
|
||||
)
|
||||
setError(t('settings.hidden_profiles.load_error', 'Failed to load hidden profiles.'))
|
||||
})
|
||||
.finally(() => alive && setLoading(false))
|
||||
return () => {
|
||||
alive = false
|
||||
// Reset toast batching state on close/unmount
|
||||
if (toastTimerRef.current) {
|
||||
clearTimeout(toastTimerRef.current as number)
|
||||
toastTimerRef.current = null
|
||||
}
|
||||
setPendingUnhideCount(0)
|
||||
}
|
||||
}, [open])
|
||||
|
||||
const flushUnhideToast = () => {
|
||||
if (pendingUnhideCount <= 0) return
|
||||
if (pendingUnhideCount === 1) {
|
||||
toast.success(
|
||||
t(
|
||||
'settings.hidden_profiles.unhidden_success',
|
||||
'Profile unhidden. You will start seeing this person again in results.'
|
||||
)
|
||||
)
|
||||
} else {
|
||||
toast.success(
|
||||
t(
|
||||
'settings.hidden_profiles.unhidden_success_many',
|
||||
'Unhid {n} profiles.',
|
||||
// Simple param replacement; if your i18n library supports interpolation, it will use it.
|
||||
).replace('{n}', String(pendingUnhideCount))
|
||||
)
|
||||
}
|
||||
setPendingUnhideCount(0)
|
||||
}
|
||||
|
||||
const unhide = async (userId: string) => {
|
||||
if (busyIds[userId]) return
|
||||
setBusyIds((b) => ({...b, [userId]: true}))
|
||||
try {
|
||||
await api('unhide-profile', {hiddenUserId: userId})
|
||||
setHidden((list) => (list ? list.filter((u) => u.id !== userId) : list))
|
||||
// Batch/throttle the success toast
|
||||
setPendingUnhideCount((c) => c + 1)
|
||||
if (!toastTimerRef.current) {
|
||||
toastTimerRef.current = setTimeout(() => {
|
||||
flushUnhideToast()
|
||||
toastTimerRef.current = null
|
||||
}, 600)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to unhide profile', e)
|
||||
toast.error(t('settings.hidden_profiles.unhide_failed', 'Failed to unhide'))
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import clsx from 'clsx'
|
||||
import {useState} from 'react'
|
||||
import {EyeOffIcon} from '@heroicons/react/outline'
|
||||
import {EyeIcon, EyeOffIcon} from '@heroicons/react/outline'
|
||||
import {Tooltip} from 'web/components/widgets/tooltip'
|
||||
import {api} from 'web/lib/api'
|
||||
import toast from 'react-hot-toast'
|
||||
import {useT} from 'web/lib/locale'
|
||||
|
||||
export type HideProfileButtonProps = {
|
||||
@@ -14,7 +13,6 @@ export type HideProfileButtonProps = {
|
||||
tooltip?: string
|
||||
ariaLabel?: string
|
||||
stopPropagation?: boolean
|
||||
suppressToast?: boolean
|
||||
}
|
||||
|
||||
export function HideProfileButton(props: HideProfileButtonProps) {
|
||||
@@ -26,7 +24,6 @@ export function HideProfileButton(props: HideProfileButtonProps) {
|
||||
tooltip,
|
||||
ariaLabel,
|
||||
stopPropagation,
|
||||
suppressToast,
|
||||
} = props
|
||||
|
||||
const t = useT()
|
||||
@@ -42,30 +39,29 @@ export function HideProfileButton(props: HideProfileButtonProps) {
|
||||
try {
|
||||
await api('hide-profile', {hiddenUserId})
|
||||
onHidden?.(hiddenUserId)
|
||||
if (!suppressToast)
|
||||
toast.success(
|
||||
t(
|
||||
'profiles.hidden_success',
|
||||
'Profile hidden. You will no longer see this person in search results.'
|
||||
)
|
||||
)
|
||||
} finally {
|
||||
setSubmitting(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Tooltip text={!clicked ? (tooltip ?? t('profile_grid.hide_profile', "Don't show again in search results")) : ''}
|
||||
noTap>
|
||||
<Tooltip
|
||||
text={!clicked ? (tooltip ?? t('profile_grid.hide_profile', "Don't show again in search results")) : t('profile_grid.unhide_profile', "Show again in search results")}
|
||||
noTap>
|
||||
<button
|
||||
className={clsx(
|
||||
'rounded-full p-1 hover:bg-canvas-200 shadow focus:outline-none',
|
||||
className
|
||||
)}
|
||||
onClick={onClick}
|
||||
aria-label={ariaLabel ?? t('profile_grid.hide_profile', 'Hide this profile')}
|
||||
aria-label={
|
||||
ariaLabel ?? (!clicked
|
||||
? t('profile_grid.hide_profile', 'Hide this profile')
|
||||
: t('profile_grid.unhide_profile', 'Unhide this profile'))
|
||||
}
|
||||
>
|
||||
<EyeOffIcon className={clsx('h-5 w-5 guidance', iconClassName)}/>
|
||||
{clicked || submitting ? <EyeIcon className={clsx('h-5 w-5 guidance', iconClassName)}/> :
|
||||
<EyeOffIcon className={clsx('h-5 w-5 guidance', iconClassName)}/>}
|
||||
</button>
|
||||
</Tooltip>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user