From 0423bff07a698ce037c1467ccd8e8a26730809f4 Mon Sep 17 00:00:00 2001 From: Tickbase Date: Sat, 11 Jul 2026 12:21:39 +0200 Subject: [PATCH] types & hooks --- src/hooks/useAppLogic.ts | 56 ++++++---------------------------------- src/types/Config.ts | 2 ++ 2 files changed, 10 insertions(+), 48 deletions(-) diff --git a/src/hooks/useAppLogic.ts b/src/hooks/useAppLogic.ts index 657d25c..959b3b7 100644 --- a/src/hooks/useAppLogic.ts +++ b/src/hooks/useAppLogic.ts @@ -1,29 +1,20 @@ -import { useState, useCallback, useEffect, useRef } from 'react' +import { useState, useCallback } from 'react' import { useAppContext } from '@/contexts/useAppContext' -interface UseAppLogicOptions { - autoLoad?: boolean -} - /** * Main application logic hook * Combines various aspects of the app's behavior */ -export function useAppLogic(options: UseAppLogicOptions = {}) { - const { autoLoad = true } = options - - // Get values from app context - const { games, loadGames, isLoading, error, showToast } = useAppContext() +export function useAppLogic() { + // Get values from app context. isInitialLoad/scanProgress are driven by the + // real scan_steam_games call and its scan-progress events (see useGames), + // not a simulated one, useGames already kicks off the initial scan itself. + const { games, loadGames, isLoading, isInitialLoad, scanProgress, error, showToast } = + useAppContext() // Local state for filtering and UI - const [filter, setFilter] = useState('all') + const [filter, setFilter] = useState('overview') 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 const filteredGames = useCallback(() => { @@ -47,36 +38,6 @@ export function useAppLogic(options: UseAppLogicOptions = {}) { 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 const handleRefresh = useCallback(async () => { try { @@ -93,7 +54,6 @@ export function useAppLogic(options: UseAppLogicOptions = {}) { searchQuery, handleSearchChange, isInitialLoad, - setIsInitialLoad, scanProgress, filteredGames: filteredGames(), handleRefresh, diff --git a/src/types/Config.ts b/src/types/Config.ts index f8aad62..d41a234 100644 --- a/src/types/Config.ts +++ b/src/types/Config.ts @@ -7,4 +7,6 @@ export interface Config { show_disclaimer: boolean reporting_opted_in: boolean reporting_has_seen_prompt: boolean + /** Extra Steam library folders to scan, beyond the auto-detected ones */ + custom_steam_paths: string[] } \ No newline at end of file