6.4.3: Фоновое обновление досок при наличии кеша
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m4s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m4s
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "play-life-web",
|
"name": "play-life-web",
|
||||||
"version": "6.4.2",
|
"version": "6.4.3",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@@ -110,10 +110,21 @@ function ShoppingList({ onNavigate, refreshTrigger = 0, isActive = false, initia
|
|||||||
return null
|
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 [selectedBoardId, setSelectedBoardIdState] = useState(getInitialBoardId)
|
||||||
const [items, setItems] = useState([])
|
const [items, setItems] = useState([])
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [boardsLoading, setBoardsLoading] = useState(true)
|
const [boardsLoading, setBoardsLoading] = useState(!hasBoardsCache())
|
||||||
const [error, setError] = useState('')
|
const [error, setError] = useState('')
|
||||||
const [selectedItemForDetail, setSelectedItemForDetail] = useState(null)
|
const [selectedItemForDetail, setSelectedItemForDetail] = useState(null)
|
||||||
const [selectedItemForPostpone, setSelectedItemForPostpone] = useState(null)
|
const [selectedItemForPostpone, setSelectedItemForPostpone] = useState(null)
|
||||||
@@ -142,8 +153,8 @@ function ShoppingList({ onNavigate, refreshTrigger = 0, isActive = false, initia
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Загрузка досок
|
// Загрузка досок
|
||||||
const fetchBoards = async () => {
|
const fetchBoards = async (showLoading = true) => {
|
||||||
setBoardsLoading(true)
|
if (showLoading) setBoardsLoading(true)
|
||||||
try {
|
try {
|
||||||
const res = await authFetch('/api/shopping/boards')
|
const res = await authFetch('/api/shopping/boards')
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
@@ -218,7 +229,8 @@ function ShoppingList({ onNavigate, refreshTrigger = 0, isActive = false, initia
|
|||||||
|
|
||||||
// Начальная загрузка
|
// Начальная загрузка
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchBoards()
|
const hasCache = hasBoardsCache()
|
||||||
|
fetchBoards(!hasCache)
|
||||||
initialFetchDoneRef.current = true
|
initialFetchDoneRef.current = true
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
@@ -235,7 +247,7 @@ function ShoppingList({ onNavigate, refreshTrigger = 0, isActive = false, initia
|
|||||||
// Рефреш при возврате на таб
|
// Рефреш при возврате на таб
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isActive && !prevIsActiveRef.current && initialFetchDoneRef.current) {
|
if (isActive && !prevIsActiveRef.current && initialFetchDoneRef.current) {
|
||||||
fetchBoards()
|
fetchBoards(false)
|
||||||
if (selectedBoardId) fetchItems(selectedBoardId)
|
if (selectedBoardId) fetchItems(selectedBoardId)
|
||||||
}
|
}
|
||||||
prevIsActiveRef.current = isActive
|
prevIsActiveRef.current = isActive
|
||||||
@@ -244,7 +256,7 @@ function ShoppingList({ onNavigate, refreshTrigger = 0, isActive = false, initia
|
|||||||
// Рефреш по триггеру
|
// Рефреш по триггеру
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (refreshTrigger > 0) {
|
if (refreshTrigger > 0) {
|
||||||
fetchBoards()
|
fetchBoards(false)
|
||||||
if (selectedBoardId) fetchItems(selectedBoardId)
|
if (selectedBoardId) fetchItems(selectedBoardId)
|
||||||
}
|
}
|
||||||
}, [refreshTrigger])
|
}, [refreshTrigger])
|
||||||
|
|||||||
Reference in New Issue
Block a user