Melissa polish + Prontuario Visao Geral + agenda historico
Sprints B (05-03) e C (05-04) acumulados: - NotificationDrawer/Item redesign (visual mais limpo, ações inline) - Dock pins compose (useMelissaDockPins) + cache store global (melissaCacheStore) - MelissaAgenda: timeline FullCalendar parity + cards resumo, histórico card com useMelissaAgendaHistorico, MelissaEventoPanel ajustado - useFeriados: cache opt-in pra evitar fetch redundante de feriados - PatientProntuario: aba Visão Geral nova; PatientConversationsTab polish - AgendaClinicMosaic / AgendaTerapeutaPage / useAgendaSettings: ajustes de paridade com Melissa - DocumentsListPage: pequenos ajustes - DB migration 20260504000001: fix do trigger pra status 'excluido' nas cancel_notifications Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
import { ref, watch, onMounted, computed } from 'vue';
|
||||
import { supabase } from '@/lib/supabase/client';
|
||||
import { useTenantStore } from '@/stores/tenantStore';
|
||||
import { useMelissaCacheStore, MELISSA_CACHE_TTL } from '@/stores/melissaCacheStore';
|
||||
|
||||
// ── Cores por tipo/status (consistente com o resto do Melissa) ──
|
||||
function pickColor(tipo, status) {
|
||||
@@ -319,17 +320,49 @@ export function useMelissaTodasSessoesPaciente() {
|
||||
}
|
||||
|
||||
// ── COMPOSABLE 2: apenas hoje (MelissaLayout) ──────────────────
|
||||
export function useMelissaEventosHoje() {
|
||||
// opts: { autoFetch=true } — passar false pra adiar o fetch inicial
|
||||
// (MelissaLayout faz isso quando a URL inicial já tem uma seção, pra
|
||||
// não competir com o fetch da seção que vai cobrir o resumo).
|
||||
export function useMelissaEventosHoje(opts = {}) {
|
||||
const autoFetch = opts.autoFetch !== false;
|
||||
const cache = useMelissaCacheStore();
|
||||
const eventos = ref([]);
|
||||
const loading = ref(false);
|
||||
const error = ref(null);
|
||||
|
||||
async function fetch() {
|
||||
async function _doFetch(cacheKey) {
|
||||
const { start, end } = rangeHoje();
|
||||
const data = await _fetchRange(start, end);
|
||||
cache.set('eventosHoje', data, cacheKey);
|
||||
eventos.value = data;
|
||||
return data;
|
||||
}
|
||||
|
||||
// useCache=true (boot/auto): stale-while-revalidate.
|
||||
// useCache=false (refetch pós-mutation: status sessão, etc): força.
|
||||
async function _fetch({ useCache = true } = {}) {
|
||||
const today = new Date();
|
||||
// Cache key amarra ao dia — depois de 00:00 vira automaticamente outro slot.
|
||||
const cacheKey = `${today.getFullYear()}-${today.getMonth()}-${today.getDate()}`;
|
||||
|
||||
if (useCache) {
|
||||
const cached = cache.get('eventosHoje', cacheKey, MELISSA_CACHE_TTL.eventosHoje);
|
||||
if (cached) {
|
||||
eventos.value = cached;
|
||||
_doFetch(cacheKey).catch((e) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn('[useMelissaEventosHoje] revalidate', e);
|
||||
});
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
cache.invalidate('eventosHoje');
|
||||
}
|
||||
|
||||
loading.value = true;
|
||||
error.value = null;
|
||||
try {
|
||||
const { start, end } = rangeHoje();
|
||||
eventos.value = await _fetchRange(start, end);
|
||||
await _doFetch(cacheKey);
|
||||
} catch (e) {
|
||||
error.value = e?.message || 'Erro ao carregar agenda';
|
||||
eventos.value = [];
|
||||
@@ -340,7 +373,15 @@ export function useMelissaEventosHoje() {
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(fetch);
|
||||
if (autoFetch) onMounted(() => _fetch({ useCache: true }));
|
||||
|
||||
return { eventos, loading, error, refetch: fetch };
|
||||
return {
|
||||
eventos,
|
||||
loading,
|
||||
error,
|
||||
// refetch força query nova (após status update etc).
|
||||
refetch: () => _fetch({ useCache: false }),
|
||||
// fetchCached é stale-while-revalidate (idle/defer).
|
||||
fetchCached: () => _fetch({ useCache: true })
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user