Download src/hooks/notifs/useAutoModeUnavailableNotification.ts from chenbhao/codev: direct link, hf CLI and curl.
- Browser
- Download file 1.97 kB
-
https://huggingface.co/chenbhao/codev/resolve/afbc7edaae4e6bb0102ba024b49ce8be89d2264c/src/hooks/notifs/useAutoModeUnavailableNotification.ts
- Command line
-
hf download hf://chenbhao/codev@afbc7edaae4e6bb0102ba024b49ce8be89d2264c/src/hooks/notifs/useAutoModeUnavailableNotification.ts
-
curl -L -o useAutoModeUnavailableNotification.ts https://huggingface.co/chenbhao/codev/resolve/afbc7edaae4e6bb0102ba024b49ce8be89d2264c/src/hooks/notifs/useAutoModeUnavailableNotification.ts
1.97 kB
| import { feature } from 'bun:bundle' | |
| import { useEffect, useRef } from 'react' | |
| import { useNotifications } from 'src/context/notifications.js' | |
| import { getIsRemoteMode } from '../../bootstrap/state.js' | |
| import { useAppState } from '../../state/AppState.js' | |
| import type { PermissionMode } from '../../utils/permissions/PermissionMode.js' | |
| import { | |
| getAutoModeUnavailableNotification, | |
| getAutoModeUnavailableReason, | |
| } from '../../utils/permissions/permissionSetup.js' | |
| import { hasAutoModeOptIn } from '../../utils/settings/settings.js' | |
| /** | |
| * Shows a one-shot notification when the shift-tab carousel wraps past where | |
| * auto mode would have been. Covers all reasons (settings, circuit-breaker, | |
| * org-allowlist). The startup case (defaultMode: auto silently downgraded) is | |
| * handled by verifyAutoModeGateAccess → checkAndDisableAutoModeIfNeeded. | |
| */ | |
| export function useAutoModeUnavailableNotification(): void { | |
| const { addNotification } = useNotifications() | |
| const mode = useAppState(s => s.toolPermissionContext.mode) | |
| const isAutoModeAvailable = useAppState( | |
| s => s.toolPermissionContext.isAutoModeAvailable, | |
| ) | |
| const shownRef = useRef(false) | |
| const prevModeRef = useRef<PermissionMode>(mode) | |
| useEffect(() => { | |
| const prevMode = prevModeRef.current | |
| prevModeRef.current = mode | |
| if (!feature('TRANSCRIPT_CLASSIFIER')) return | |
| if (getIsRemoteMode()) return | |
| if (shownRef.current) return | |
| const wrappedPastAutoSlot = | |
| mode === 'default' && | |
| prevMode !== 'default' && | |
| prevMode !== 'auto' && | |
| !isAutoModeAvailable && | |
| hasAutoModeOptIn() | |
| if (!wrappedPastAutoSlot) return | |
| const reason = getAutoModeUnavailableReason() | |
| if (!reason) return | |
| shownRef.current = true | |
| addNotification({ | |
| key: 'auto-mode-unavailable', | |
| text: getAutoModeUnavailableNotification(reason), | |
| color: 'warning', | |
| priority: 'medium', | |
| }) | |
| }, [mode, isAutoModeAvailable, addNotification]) | |
| } | |