Files
Momento/memento-note/hooks/use-auto-label-suggestion.ts
Antigravity e2672cd2c2
Some checks failed
CI / Lint, Test & Build (push) Failing after 1m19s
CI / Deploy production (on server) (push) Has been skipped
feat(notes): liens internes, onglet Réseau, living blocks et consentement IA
Rend les liens entre notes visibles et persistants (sync NoteLink au save, auto-save, graphe réseau rafraîchi), ajoute living blocks, Memory Echo, recherche globale, consentement IA explicite et consolide les prototypes design en architectural-grid.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-24 14:27:29 +00:00

65 lines
2.0 KiB
TypeScript

import { useState, useEffect } from 'react'
import { useSearchParams } from 'next/navigation'
import { useSession } from 'next-auth/react'
import { useAiConsent } from '@/components/legal/ai-consent-provider'
/**
* Hook to check if auto label suggestions should be shown for the current notebook
* Triggers when notebook has 15+ notes (IA4)
*/
export function useAutoLabelSuggestion() {
const { data: session } = useSession()
const { hasAiConsent } = useAiConsent()
const searchParams = useSearchParams()
const [shouldSuggest, setShouldSuggest] = useState(false)
const [notebookId, setNotebookId] = useState<string | null>(searchParams.get('notebook'))
const [hasChecked, setHasChecked] = useState(false)
useEffect(() => {
const currentNotebookId = searchParams.get('notebook')
// Reset when notebook changes
if (currentNotebookId !== notebookId) {
setNotebookId(currentNotebookId)
setHasChecked(false)
setShouldSuggest(false)
// Check if we should suggest labels for this notebook
if (currentNotebookId && session?.user?.id && hasAiConsent) {
checkNotebookForSuggestions(currentNotebookId)
}
}
}, [searchParams, notebookId, session, hasAiConsent])
const checkNotebookForSuggestions = async (nbId: string) => {
try {
// Check if notebook has 15+ notes
const response = await fetch('/api/ai/auto-labels', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify({ notebookId: nbId }),
})
const data = await response.json()
// Show suggestions if available
if (data.success && data.data) {
setShouldSuggest(true)
}
setHasChecked(true)
} catch (error) {
console.error('Failed to check for label suggestions:', error)
setHasChecked(true)
}
}
return {
shouldSuggest,
notebookId,
hasChecked,
dismiss: () => setShouldSuggest(false),
}
}