mirror of
https://github.com/Novattz/creamlinux-installer.git
synced 2026-08-01 19:18:25 -04:00
types & hooks
This commit is contained in:
@@ -1,29 +1,20 @@
|
|||||||
import { useState, useCallback, useEffect, useRef } from 'react'
|
import { useState, useCallback } from 'react'
|
||||||
import { useAppContext } from '@/contexts/useAppContext'
|
import { useAppContext } from '@/contexts/useAppContext'
|
||||||
|
|
||||||
interface UseAppLogicOptions {
|
|
||||||
autoLoad?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main application logic hook
|
* Main application logic hook
|
||||||
* Combines various aspects of the app's behavior
|
* Combines various aspects of the app's behavior
|
||||||
*/
|
*/
|
||||||
export function useAppLogic(options: UseAppLogicOptions = {}) {
|
export function useAppLogic() {
|
||||||
const { autoLoad = true } = options
|
// Get values from app context. isInitialLoad/scanProgress are driven by the
|
||||||
|
// real scan_steam_games call and its scan-progress events (see useGames),
|
||||||
// Get values from app context
|
// not a simulated one, useGames already kicks off the initial scan itself.
|
||||||
const { games, loadGames, isLoading, error, showToast } = useAppContext()
|
const { games, loadGames, isLoading, isInitialLoad, scanProgress, error, showToast } =
|
||||||
|
useAppContext()
|
||||||
|
|
||||||
// Local state for filtering and UI
|
// Local state for filtering and UI
|
||||||
const [filter, setFilter] = useState('all')
|
const [filter, setFilter] = useState('overview')
|
||||||
const [searchQuery, setSearchQuery] = useState('')
|
const [searchQuery, setSearchQuery] = useState('')
|
||||||
const [isInitialLoad, setIsInitialLoad] = useState(true)
|
|
||||||
const isInitializedRef = useRef(false)
|
|
||||||
const [scanProgress, setScanProgress] = useState({
|
|
||||||
message: 'Initializing...',
|
|
||||||
progress: 0,
|
|
||||||
})
|
|
||||||
|
|
||||||
// Filter games based on current filter and search
|
// Filter games based on current filter and search
|
||||||
const filteredGames = useCallback(() => {
|
const filteredGames = useCallback(() => {
|
||||||
@@ -47,36 +38,6 @@ export function useAppLogic(options: UseAppLogicOptions = {}) {
|
|||||||
setSearchQuery(query)
|
setSearchQuery(query)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// Handle initial loading with simulated progress
|
|
||||||
useEffect(() => {
|
|
||||||
if (!autoLoad || !isInitialLoad || isInitializedRef.current) return
|
|
||||||
|
|
||||||
isInitializedRef.current = true
|
|
||||||
console.log('[APP LOGIC #2] Starting initialization')
|
|
||||||
|
|
||||||
const initialLoad = async () => {
|
|
||||||
try {
|
|
||||||
setScanProgress({ message: 'Scanning for games...', progress: 20 })
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 800))
|
|
||||||
|
|
||||||
setScanProgress({ message: 'Loading game information...', progress: 50 })
|
|
||||||
await loadGames()
|
|
||||||
|
|
||||||
setScanProgress({ message: 'Finishing up...', progress: 90 })
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 500))
|
|
||||||
|
|
||||||
setScanProgress({ message: 'Ready!', progress: 100 })
|
|
||||||
setTimeout(() => setIsInitialLoad(false), 500)
|
|
||||||
} catch (error) {
|
|
||||||
setScanProgress({ message: `Error: ${error}`, progress: 100 })
|
|
||||||
showToast(`Failed to load: ${error}`, 'error')
|
|
||||||
setTimeout(() => setIsInitialLoad(false), 2000)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
initialLoad()
|
|
||||||
}, [autoLoad, isInitialLoad, loadGames, showToast])
|
|
||||||
|
|
||||||
// Force a refresh
|
// Force a refresh
|
||||||
const handleRefresh = useCallback(async () => {
|
const handleRefresh = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
@@ -93,7 +54,6 @@ export function useAppLogic(options: UseAppLogicOptions = {}) {
|
|||||||
searchQuery,
|
searchQuery,
|
||||||
handleSearchChange,
|
handleSearchChange,
|
||||||
isInitialLoad,
|
isInitialLoad,
|
||||||
setIsInitialLoad,
|
|
||||||
scanProgress,
|
scanProgress,
|
||||||
filteredGames: filteredGames(),
|
filteredGames: filteredGames(),
|
||||||
handleRefresh,
|
handleRefresh,
|
||||||
|
|||||||
@@ -7,4 +7,6 @@ export interface Config {
|
|||||||
show_disclaimer: boolean
|
show_disclaimer: boolean
|
||||||
reporting_opted_in: boolean
|
reporting_opted_in: boolean
|
||||||
reporting_has_seen_prompt: boolean
|
reporting_has_seen_prompt: boolean
|
||||||
|
/** Extra Steam library folders to scan, beyond the auto-detected ones */
|
||||||
|
custom_steam_paths: string[]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user