6.4.3: Фоновое обновление досок при наличии кеша
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m4s

This commit is contained in:
poignatov
2026-03-08 19:30:56 +03:00
parent c8fead4034
commit 4169285394
3 changed files with 20 additions and 8 deletions

View File

@@ -110,10 +110,21 @@ function ShoppingList({ onNavigate, refreshTrigger = 0, isActive = false, initia
return null
}
const hasBoardsCache = () => {
try {
const cached = localStorage.getItem(BOARDS_CACHE_KEY)
if (cached) {
const data = JSON.parse(cached)
return !!(data.boards && data.boards.length >= 0)
}
} catch (err) {}
return false
}
const [selectedBoardId, setSelectedBoardIdState] = useState(getInitialBoardId)
const [items, setItems] = useState([])
const [loading, setLoading] = useState(true)
const [boardsLoading, setBoardsLoading] = useState(true)
const [boardsLoading, setBoardsLoading] = useState(!hasBoardsCache())
const [error, setError] = useState('')
const [selectedItemForDetail, setSelectedItemForDetail] = useState(null)
const [selectedItemForPostpone, setSelectedItemForPostpone] = useState(null)
@@ -142,8 +153,8 @@ function ShoppingList({ onNavigate, refreshTrigger = 0, isActive = false, initia
}
// Загрузка досок
const fetchBoards = async () => {
setBoardsLoading(true)
const fetchBoards = async (showLoading = true) => {
if (showLoading) setBoardsLoading(true)
try {
const res = await authFetch('/api/shopping/boards')
if (res.ok) {
@@ -218,7 +229,8 @@ function ShoppingList({ onNavigate, refreshTrigger = 0, isActive = false, initia
// Начальная загрузка
useEffect(() => {
fetchBoards()
const hasCache = hasBoardsCache()
fetchBoards(!hasCache)
initialFetchDoneRef.current = true
}, [])
@@ -235,7 +247,7 @@ function ShoppingList({ onNavigate, refreshTrigger = 0, isActive = false, initia
// Рефреш при возврате на таб
useEffect(() => {
if (isActive && !prevIsActiveRef.current && initialFetchDoneRef.current) {
fetchBoards()
fetchBoards(false)
if (selectedBoardId) fetchItems(selectedBoardId)
}
prevIsActiveRef.current = isActive
@@ -244,7 +256,7 @@ function ShoppingList({ onNavigate, refreshTrigger = 0, isActive = false, initia
// Рефреш по триггеру
useEffect(() => {
if (refreshTrigger > 0) {
fetchBoards()
fetchBoards(false)
if (selectedBoardId) fetchItems(selectedBoardId)
}
}, [refreshTrigger])