diff --git a/src/components/search/GlobalSearch.vue b/src/components/search/GlobalSearch.vue index e108fbc..e3a5a24 100644 --- a/src/components/search/GlobalSearch.vue +++ b/src/components/search/GlobalSearch.vue @@ -15,9 +15,11 @@ import InputText from 'primevue/inputtext'; import { supabase } from '@/lib/supabase/client'; import { useTenantStore } from '@/stores/tenantStore'; import { searchPages } from './pagesIndex'; +import { useRecentPatients } from '@/composables/useRecentPatients'; const router = useRouter(); const tenantStore = useTenantStore(); +const { items: recentPatients, hasItems: hasRecentPatients } = useRecentPatients(); // ──────────────────────────────────────────────────────────── // State @@ -67,9 +69,14 @@ const filteredPages = computed(() => { // ──────────────────────────────────────────────────────────── // Flat list pra navegação por teclado // ──────────────────────────────────────────────────────────── +// Recently-viewed só aparece quando a query está vazia — não polui resultados de busca. +const showRecent = computed(() => !query.value.trim() && hasRecentPatients.value); +const recentItems = computed(() => showRecent.value ? (recentPatients.value || []).slice(0, 5) : []); + const flatList = computed(() => { const out = []; filteredActions.value.forEach((a, i) => out.push({ group: 'actions', item: a, idx: i })); + recentItems.value.forEach((p, i) => out.push({ group: 'recent', item: p, idx: i })); results.value.patients.forEach((p, i) => out.push({ group: 'patients', item: p, idx: i })); results.value.intakes.forEach((r, i) => out.push({ group: 'intakes', item: r, idx: i })); results.value.appointments.forEach((a, i) => out.push({ group: 'appointments', item: a, idx: i })); @@ -195,6 +202,16 @@ function onInputKeydown(e) { } async function goTo(entry) { + // Recent patients: usa id pra navegar pro prontuário do paciente + if (entry?.group === 'recent' && entry?.item?.id) { + showPanel.value = false; + query.value = ''; + resetResults(); + activeIndex.value = -1; + await router.push({ path: '/therapist/patients/' + entry.item.id }); + return; + } + const target = entry?.item?.to || entry?.item?.deeplink || entry?.item?.path; if (!target) return; showPanel.value = false; @@ -266,6 +283,27 @@ const kbdModifier = kbdIsMac ? '⌘' : 'Ctrl';