mirror of
https://github.com/Novattz/creamlinux-installer.git
synced 2026-01-24 12:22:49 -05:00
Fixed
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useState, useCallback, useEffect } from 'react'
|
import { useState, useCallback, useEffect, useRef } from 'react'
|
||||||
import { useAppContext } from '@/contexts/useAppContext'
|
import { useAppContext } from '@/contexts/useAppContext'
|
||||||
|
|
||||||
interface UseAppLogicOptions {
|
interface UseAppLogicOptions {
|
||||||
@@ -25,6 +25,7 @@ export function useAppLogic(options: UseAppLogicOptions = {}) {
|
|||||||
const [filter, setFilter] = useState('all')
|
const [filter, setFilter] = useState('all')
|
||||||
const [searchQuery, setSearchQuery] = useState('')
|
const [searchQuery, setSearchQuery] = useState('')
|
||||||
const [isInitialLoad, setIsInitialLoad] = useState(true)
|
const [isInitialLoad, setIsInitialLoad] = useState(true)
|
||||||
|
const isInitializedRef = useRef(false)
|
||||||
const [scanProgress, setScanProgress] = useState({
|
const [scanProgress, setScanProgress] = useState({
|
||||||
message: 'Initializing...',
|
message: 'Initializing...',
|
||||||
progress: 0
|
progress: 0
|
||||||
@@ -54,43 +55,32 @@ export function useAppLogic(options: UseAppLogicOptions = {}) {
|
|||||||
|
|
||||||
// Handle initial loading with simulated progress
|
// Handle initial loading with simulated progress
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (autoLoad && isInitialLoad) {
|
if (!autoLoad || !isInitialLoad || isInitializedRef.current) return
|
||||||
const initialLoad = async () => {
|
|
||||||
try {
|
isInitializedRef.current = true
|
||||||
// Show scanning message
|
console.log("[APP LOGIC #2] Starting initialization")
|
||||||
setScanProgress({ message: 'Scanning for games...', progress: 20 })
|
|
||||||
|
const initialLoad = async () => {
|
||||||
// Small delay to show loading screen
|
try {
|
||||||
await new Promise(resolve => setTimeout(resolve, 800))
|
setScanProgress({ message: 'Scanning for games...', progress: 20 })
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 800))
|
||||||
// Update progress
|
|
||||||
setScanProgress({ message: 'Loading game information...', progress: 50 })
|
setScanProgress({ message: 'Loading game information...', progress: 50 })
|
||||||
|
await loadGames()
|
||||||
// Load games data
|
|
||||||
await loadGames()
|
setScanProgress({ message: 'Finishing up...', progress: 90 })
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 500))
|
||||||
// Update progress
|
|
||||||
setScanProgress({ message: 'Finishing up...', progress: 90 })
|
setScanProgress({ message: 'Ready!', progress: 100 })
|
||||||
|
setTimeout(() => setIsInitialLoad(false), 500)
|
||||||
// Small delay for animation
|
} catch (error) {
|
||||||
await new Promise(resolve => setTimeout(resolve, 500))
|
setScanProgress({ message: `Error: ${error}`, progress: 100 })
|
||||||
|
showToast(`Failed to load: ${error}`, 'error')
|
||||||
// Complete
|
setTimeout(() => setIsInitialLoad(false), 2000)
|
||||||
setScanProgress({ message: 'Ready!', progress: 100 })
|
|
||||||
|
|
||||||
// Exit loading screen after a moment
|
|
||||||
setTimeout(() => setIsInitialLoad(false), 500)
|
|
||||||
} catch (error) {
|
|
||||||
setScanProgress({ message: `Error: ${error}`, progress: 100 })
|
|
||||||
showToast(`Failed to load: ${error}`, 'error')
|
|
||||||
|
|
||||||
// Allow exit even on error
|
|
||||||
setTimeout(() => setIsInitialLoad(false), 2000)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
initialLoad()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initialLoad()
|
||||||
}, [autoLoad, isInitialLoad, loadGames, showToast])
|
}, [autoLoad, isInitialLoad, loadGames, showToast])
|
||||||
|
|
||||||
// Force a refresh
|
// Force a refresh
|
||||||
|
|||||||
Reference in New Issue
Block a user