v1.3.12: dia anterior robusto — hasTauri check em todas as chamadas
This commit is contained in:
+34
-24
@@ -1930,9 +1930,12 @@ if (btnAnterior) {
|
|||||||
console.log('[DEBUG] btn-anterior clicado');
|
console.log('[DEBUG] btn-anterior clicado');
|
||||||
const loja = val('f-loja') || 'União';
|
const loja = val('f-loja') || 'União';
|
||||||
console.log('[DEBUG] btn-anterior loja:', loja);
|
console.log('[DEBUG] btn-anterior loja:', loja);
|
||||||
|
const hasTauri = !!(window.__TAURI__ && window.__TAURI__.core);
|
||||||
|
|
||||||
// Salva rascunho atual antes de tudo
|
// Salva rascunho atual antes de tudo
|
||||||
await tauriSaveLocal();
|
if (hasTauri) {
|
||||||
|
try { await window.__TAURI__.core.invoke('salvar_rascunho_local', {}); } catch(e) { console.warn('salvar_rascunho_local:', e); }
|
||||||
|
}
|
||||||
|
|
||||||
// Calcula dia anterior
|
// Calcula dia anterior
|
||||||
const prevDate = new Date(estado.data);
|
const prevDate = new Date(estado.data);
|
||||||
@@ -1948,11 +1951,15 @@ if (btnAnterior) {
|
|||||||
|
|
||||||
// Carrega lista de fechamentos recentes do Supabase com uuid
|
// Carrega lista de fechamentos recentes do Supabase com uuid
|
||||||
let recentList = [];
|
let recentList = [];
|
||||||
try {
|
if (hasTauri) {
|
||||||
recentList = await window.__TAURI__.core.invoke('sb_listar_recentes', { loja, limite: 20 });
|
try {
|
||||||
console.log('[DEBUG] sb_listar_recentes retornou:', recentList?.length, 'itens');
|
recentList = await window.__TAURI__.core.invoke('sb_listar_recentes', { loja, limite: 20 });
|
||||||
} catch(e) {
|
console.log('[DEBUG] sb_listar_recentes retornou:', recentList?.length, 'itens');
|
||||||
console.warn('sb_listar_recentes falhou:', e);
|
} catch(e) {
|
||||||
|
console.warn('sb_listar_recentes falhou:', e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.warn('Tauri não disponível, pulando sb_listar_recentes');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extrai datas únicas ordenadas + mapeamento data→id
|
// Extrai datas únicas ordenadas + mapeamento data→id
|
||||||
@@ -1997,24 +2004,27 @@ if (btnAnterior) {
|
|||||||
|
|
||||||
// Tenta Supabase primeiro (com id se disponível), senão local
|
// Tenta Supabase primeiro (com id se disponível), senão local
|
||||||
let rascunho = null;
|
let rascunho = null;
|
||||||
if (selectedId) {
|
if (hasTauri) {
|
||||||
try {
|
if (selectedId) {
|
||||||
rascunho = await window.__TAURI__.core.invoke('sb_buscar_por_id', { id: selectedId });
|
try {
|
||||||
console.log('[DEBUG] sb_buscar_por_id retornou:', !!rascunho);
|
rascunho = await window.__TAURI__.core.invoke('sb_buscar_por_id', { id: selectedId });
|
||||||
} catch(e) { console.warn('sb_buscar_por_id falhou:', e); }
|
console.log('[DEBUG] sb_buscar_por_id retornou:', !!rascunho);
|
||||||
}
|
} catch(e) { console.warn('sb_buscar_por_id falhou:', e); }
|
||||||
if (!rascunho) {
|
}
|
||||||
try {
|
if (!rascunho) {
|
||||||
rascunho = await window.__TAURI__.core.invoke('sb_carregar_rascunho', { loja, data: selectedDate });
|
try {
|
||||||
console.log('[DEBUG] sb_carregar_rascunho retornou:', !!rascunho);
|
rascunho = await window.__TAURI__.core.invoke('sb_carregar_rascunho', { loja, data: selectedDate });
|
||||||
} catch(e) { console.warn('sb_carregar_rascunho falhou:', e); }
|
console.log('[DEBUG] sb_carregar_rascunho retornou:', !!rascunho);
|
||||||
}
|
} catch(e) { console.warn('sb_carregar_rascunho falhou:', e); }
|
||||||
|
}
|
||||||
if (!rascunho) {
|
if (!rascunho) {
|
||||||
try {
|
try {
|
||||||
rascunho = await window.__TAURI__.core.invoke('carregar_rascunho', { loja, data: selectedDate });
|
rascunho = await window.__TAURI__.core.invoke('carregar_rascunho', { loja, data: selectedDate });
|
||||||
console.log('[DEBUG] carregar_rascunho local retornou:', !!rascunho);
|
console.log('[DEBUG] carregar_rascunho local retornou:', !!rascunho);
|
||||||
} catch(e) { console.warn('carregar_rascunho local falhou:', e); }
|
} catch(e) { console.warn('carregar_rascunho local falhou:', e); }
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.warn('Tauri não disponível, não foi possível carregar rascunho');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rascunho) {
|
if (rascunho) {
|
||||||
|
|||||||
Reference in New Issue
Block a user