Skip to content

Commit 4dc0693

Browse files
committed
feat: add daily cache for UP42 data to reduce API calls
1 parent ad336a0 commit 4dc0693

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/control-panel/control-panel.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,15 @@ function ControlPanel(props: ControlPanelProps): React.ReactElement {
174174

175175
// Load UP42 data on component mount
176176
React.useEffect(() => {
177-
if (dataCollection.length > 0) return;
178177
(async () => {
178+
const lastFetched = localStorage.getItem('dataCollectionLastEdited');
179+
const today = new Date().toDateString();
180+
181+
if (lastFetched === today && dataCollection.length > 0) {
182+
console.log('UP42 data already fresh for today, skipping fetch');
183+
return;
184+
}
185+
179186
const { up42Email, up42Password } = apiKeys[Providers.UP42];
180187
setIsUp42Loading(true);
181188
try {
@@ -189,6 +196,8 @@ function ControlPanel(props: ControlPanelProps): React.ReactElement {
189196
}
190197
return data;
191198
});
199+
200+
localStorage.setItem('dataCollectionLastEdited', today);
192201
} catch (error) {
193202
console.error('UP42 CORS Error:', error);
194203
} finally {

0 commit comments

Comments
 (0)