Álvaro Valenzuela Valdes commited on
Commit ·
909f192
1
Parent(s): 63cdff5
fix: dual-layer persistence (Backend JSON + LocalStorage Backup) to survive environment restarts
Browse files- frontend/app/page.tsx +23 -2
frontend/app/page.tsx
CHANGED
|
@@ -118,7 +118,11 @@ export default function HomePage() {
|
|
| 118 |
}
|
| 119 |
|
| 120 |
try {
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
setAnalysisHistory(history);
|
| 123 |
} catch (e) {
|
| 124 |
console.error("History load error", e);
|
|
@@ -126,7 +130,11 @@ export default function HomePage() {
|
|
| 126 |
|
| 127 |
try {
|
| 128 |
const { fetchSearchHistory } = await import("../lib/api");
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
setSearchHistory(sHistory);
|
| 131 |
} catch (e) {
|
| 132 |
console.error("Search history load error", e);
|
|
@@ -143,6 +151,19 @@ export default function HomePage() {
|
|
| 143 |
init();
|
| 144 |
}, []);
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
const handleTenderSelect = (tender: Tender) => {
|
| 147 |
setSelectedTender(tender);
|
| 148 |
setActiveTab("Agent Analysis");
|
|
|
|
| 118 |
}
|
| 119 |
|
| 120 |
try {
|
| 121 |
+
let history = await fetchAnalysisHistory();
|
| 122 |
+
if (history.length === 0) {
|
| 123 |
+
const localHistory = localStorage.getItem('andes_analysis_history_backup');
|
| 124 |
+
if (localHistory) history = JSON.parse(localHistory);
|
| 125 |
+
}
|
| 126 |
setAnalysisHistory(history);
|
| 127 |
} catch (e) {
|
| 128 |
console.error("History load error", e);
|
|
|
|
| 130 |
|
| 131 |
try {
|
| 132 |
const { fetchSearchHistory } = await import("../lib/api");
|
| 133 |
+
let sHistory = await fetchSearchHistory();
|
| 134 |
+
if (sHistory.length === 0) {
|
| 135 |
+
const localSearch = localStorage.getItem('andes_search_history_backup');
|
| 136 |
+
if (localSearch) sHistory = JSON.parse(localSearch);
|
| 137 |
+
}
|
| 138 |
setSearchHistory(sHistory);
|
| 139 |
} catch (e) {
|
| 140 |
console.error("Search history load error", e);
|
|
|
|
| 151 |
init();
|
| 152 |
}, []);
|
| 153 |
|
| 154 |
+
// Backup history to localStorage to survive HF Space restarts
|
| 155 |
+
useEffect(() => {
|
| 156 |
+
if (analysisHistory.length > 0) {
|
| 157 |
+
localStorage.setItem('andes_analysis_history_backup', JSON.stringify(analysisHistory));
|
| 158 |
+
}
|
| 159 |
+
}, [analysisHistory]);
|
| 160 |
+
|
| 161 |
+
useEffect(() => {
|
| 162 |
+
if (searchHistory.length > 0) {
|
| 163 |
+
localStorage.setItem('andes_search_history_backup', JSON.stringify(searchHistory));
|
| 164 |
+
}
|
| 165 |
+
}, [searchHistory]);
|
| 166 |
+
|
| 167 |
const handleTenderSelect = (tender: Tender) => {
|
| 168 |
setSelectedTender(tender);
|
| 169 |
setActiveTab("Agent Analysis");
|