Skip to content

Commit a6bbce9

Browse files
committed
clear file cache on startup
1 parent a904d95 commit a6bbce9

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

client/src/App.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,44 @@
1+
import { useEffect, useState } from 'react'
2+
import localforage from 'localforage'
13
import './App.css'
24
import Views from './views/Views'
35
import { ContextWrapper } from './contexts/GlobalContext'
46
import { YamlContextWrapper } from './contexts/YamlContext'
57

8+
const FILE_CACHE_KEYS = [
9+
'files',
10+
'fileList',
11+
'imageFileList',
12+
'labelFileList',
13+
'currentImage',
14+
'currentLabel',
15+
'inputImage',
16+
'inputLabel'
17+
]
18+
619
function App () {
20+
const [isCacheCleared, setIsCacheCleared] = useState(false)
21+
22+
useEffect(() => {
23+
const clearFileCache = async () => {
24+
try {
25+
await Promise.all(
26+
FILE_CACHE_KEYS.map((key) => localforage.removeItem(key))
27+
)
28+
} catch (error) {
29+
console.error('Failed to clear file cache on startup:', error)
30+
} finally {
31+
setIsCacheCleared(true)
32+
}
33+
}
34+
35+
clearFileCache()
36+
}, [])
37+
38+
if (!isCacheCleared) {
39+
return null
40+
}
41+
742
return (
843
<ContextWrapper>
944
<YamlContextWrapper>

0 commit comments

Comments
 (0)