Skip to content

Commit

Permalink
Fixing build error and remaining type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
salty2011 committed Jan 15, 2025
1 parent 0e39efd commit b5426d9
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 96 deletions.
35 changes: 20 additions & 15 deletions src/components/AdminSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useState, ChangeEvent } from 'react';
import {
Box,
TextField,
Expand All @@ -14,8 +14,7 @@ import {
} from '@mui/material';
import { Visibility, VisibilityOff } from '@mui/icons-material';
import { AdminConfig } from '../types/config';
import Logger from '../services/LogService';
import { SteamService } from '../services/SteamService';
import { LogService, SteamService } from '../services';

interface AdminSettingsProps {
config: AdminConfig;
Expand All @@ -36,10 +35,10 @@ export const AdminSettings: React.FC<AdminSettingsProps> = ({ config, onSave })
setShowError(null);
await onSave(settings);
setShowSuccess(true);
Logger.info('Admin settings saved successfully');
LogService.info('Admin settings saved successfully');
} catch (error) {
setShowError('Failed to save admin settings');
Logger.error('Failed to save admin settings', error);
LogService.error('Failed to save admin settings', error);
} finally {
setIsSaving(false);
}
Expand All @@ -51,15 +50,24 @@ export const AdminSettings: React.FC<AdminSettingsProps> = ({ config, onSave })
setShowError(null);
await SteamService.refreshAllArtwork();
setShowSuccess(true);
Logger.info('Artwork refresh completed successfully');
LogService.info('Artwork refresh completed successfully');
} catch (error) {
setShowError('Failed to refresh artwork');
Logger.error('Failed to refresh artwork', error);
LogService.error('Failed to refresh artwork', error);
} finally {
setIsRefreshing(false);
}
};

const handleTextFieldChange = (field: keyof AdminConfig) => (e: ChangeEvent<HTMLInputElement>) => {
setSettings({ ...settings, [field]: e.target.value });
};

const handleDebugToggle = (e: ChangeEvent<HTMLInputElement>) => {
setSettings({ ...settings, debugEnabled: e.target.checked });
LogService.debug('Debug mode toggled', 'AdminSettings', { enabled: e.target.checked });
};

return (
<Paper sx={{ p: 3, maxWidth: 600, mx: 'auto', mb: 3 }}>
<Typography variant="h5" gutterBottom>
Expand All @@ -70,29 +78,29 @@ export const AdminSettings: React.FC<AdminSettingsProps> = ({ config, onSave })
<TextField
label="Library Path"
value={settings.libraryPath}
onChange={(e) => setSettings({ ...settings, libraryPath: e.target.value })}
onChange={handleTextFieldChange('libraryPath')}
helperText="Path to your games directory"
/>

<TextField
label="Users Path"
value={settings.usersPath}
onChange={(e) => setSettings({ ...settings, usersPath: e.target.value })}
onChange={handleTextFieldChange('usersPath')}
helperText="Path where user data will be stored"
/>

<TextField
label="Cache Path"
value={settings.cachePath}
onChange={(e) => setSettings({ ...settings, cachePath: e.target.value })}
onChange={handleTextFieldChange('cachePath')}
helperText="Path where artwork and other cached files will be stored"
/>

<TextField
label="SteamGridDB API Key"
type={showGridDbKey ? 'text' : 'password'}
value={settings.steamGridDbApiKey}
onChange={(e) => setSettings({ ...settings, steamGridDbApiKey: e.target.value })}
onChange={handleTextFieldChange('steamGridDbApiKey')}
helperText="API key from SteamGridDB"
InputProps={{
endAdornment: (
Expand All @@ -112,10 +120,7 @@ export const AdminSettings: React.FC<AdminSettingsProps> = ({ config, onSave })
control={
<Switch
checked={settings.debugEnabled}
onChange={(e) => {
setSettings({ ...settings, debugEnabled: e.target.checked });
Logger.debug('Debug mode toggled', 'AdminSettings', { enabled: e.target.checked });
}}
onChange={handleDebugToggle}
/>
}
label={
Expand Down
17 changes: 8 additions & 9 deletions src/components/Configuration.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, { useState, useEffect } from 'react';
import { Box, CircularProgress, Tabs, Tab } from '@mui/material';
import { ConfigService } from '../services/ConfigService';
import { ConfigService, LogService } from '../services';
import { Config, AdminConfig, UserConfig } from '../types/config';
import Logger from '../services/LogService';
import { AdminSettings } from './AdminSettings';
import { UserSettings } from './UserSettings';
import { TaskManager } from './TaskManager';
Expand Down Expand Up @@ -52,10 +51,10 @@ export const Configuration: React.FC = () => {
setIsLoading(true);
await ConfigService.loadConfig();
const loadedConfig = ConfigService.getConfig();
Logger.debug('Config loaded successfully', 'Configuration', loadedConfig);
LogService.debug('Config loaded successfully', 'Configuration', loadedConfig);
setConfig(loadedConfig);
} catch (error) {
Logger.error('Failed to load config', error, 'Configuration');
LogService.error('Failed to load config', error, 'Configuration');
} finally {
setIsLoading(false);
}
Expand All @@ -72,9 +71,9 @@ export const Configuration: React.FC = () => {
await ConfigService.saveConfig(newConfig);
await ConfigService.loadConfig();
setConfig(ConfigService.getConfig());
Logger.info('Admin configuration saved successfully');
LogService.info('Admin configuration saved successfully');
} catch (error) {
Logger.error('Failed to save admin config', error);
LogService.error('Failed to save admin config', error);
throw error;
}
};
Expand All @@ -99,7 +98,7 @@ export const Configuration: React.FC = () => {
await ConfigService.loadConfig();
setConfig(ConfigService.getConfig());
} catch (error) {
Logger.error('Failed to add user', error);
LogService.error('Failed to add user', error);
throw error;
}
};
Expand All @@ -117,7 +116,7 @@ export const Configuration: React.FC = () => {
await ConfigService.loadConfig();
setConfig(ConfigService.getConfig());
} catch (error) {
Logger.error('Failed to delete user', error);
LogService.error('Failed to delete user', error);
throw error;
}
};
Expand All @@ -135,7 +134,7 @@ export const Configuration: React.FC = () => {
await ConfigService.loadConfig();
setConfig(ConfigService.getConfig());
} catch (error) {
Logger.error('Failed to select user', error);
LogService.error('Failed to select user', error);
throw error;
}
};
Expand Down
22 changes: 8 additions & 14 deletions src/components/GameLibrary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import {
CardMedia,
CardActionArea
} from '@mui/material';
import { SteamService } from '../services/SteamService';
import { ConfigService } from '../services/ConfigService';
import { SteamService, ConfigService, LogService } from '../services';
import { SteamGame } from '../types/config';
import Logger from '../services/LogService';

interface Props {
searchQuery: string;
Expand Down Expand Up @@ -42,7 +40,7 @@ export const GameLibrary: React.FC<Props> = ({ searchQuery }) => {
const fetchedGames = await SteamService.getOwnedGames();
setGames(fetchedGames);
} catch (error) {
Logger.error('Failed to load games', error);
LogService.error('Failed to load games', error);
setError('Failed to load games');
} finally {
setLoading(false);
Expand All @@ -55,7 +53,7 @@ export const GameLibrary: React.FC<Props> = ({ searchQuery }) => {
useEffect(() => {
const loadArtwork = async () => {
const unloadedGames = games.filter(game => !gameArtwork[game.appid]);
Logger.debug('Loading artwork for games', 'GameLibrary', {
LogService.debug('Loading artwork for games', 'GameLibrary', {
totalGames: games.length,
unloadedCount: unloadedGames.length,
loadedCount: Object.keys(gameArtwork).length
Expand All @@ -64,17 +62,17 @@ export const GameLibrary: React.FC<Props> = ({ searchQuery }) => {
for (const game of unloadedGames) {
try {
// First try to get cached artwork
let artwork = await SteamService.getCachedArtwork(game.appid);
let artwork = await SteamService.getGameArtwork(game.appid);

// If no cached artwork, try to fetch new artwork
if (!artwork) {
Logger.debug('No cached artwork found, fetching new artwork', 'GameLibrary', {
LogService.debug('No cached artwork found, fetching new artwork', 'GameLibrary', {
appId: game.appid,
name: game.name
});
artwork = await SteamService.getGameArtwork(game.appid);
} else {
Logger.debug('Using cached artwork', 'GameLibrary', {
LogService.debug('Using cached artwork', 'GameLibrary', {
appId: game.appid,
name: game.name
});
Expand All @@ -86,17 +84,13 @@ export const GameLibrary: React.FC<Props> = ({ searchQuery }) => {
[game.appid]: artwork
}));
} else {
Logger.warn('No artwork available for game', 'GameLibrary', {
LogService.warn('No artwork available for game', 'GameLibrary', {
appId: game.appid,
name: game.name
});
}
} catch (error) {
Logger.error('Failed to load artwork for game', {
appId: game.appid,
name: game.name,
error
}, 'GameLibrary');
LogService.error('Failed to load artwork for game', error, 'GameLibrary');
}
}
};
Expand Down
40 changes: 12 additions & 28 deletions src/components/LogViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import {
Refresh as RefreshIcon,
Delete as DeleteIcon
} from '@mui/icons-material';
import { LogEntry, LogLevel } from '../services/LogService';
import Logger from '../services/LogService';
import { LogService, LogEntry, LogLevel } from '../services';

interface LogFilter {
level: LogLevel | 'all';
Expand Down Expand Up @@ -67,7 +66,7 @@ export const LogViewer: React.FC = () => {
listRef.current.scrollTop = listRef.current.scrollHeight;
}
} catch (error) {
Logger.error('Failed to fetch logs', error, 'LogViewer');
LogService.error('Failed to fetch logs', error, 'LogViewer');
} finally {
setIsLoading(false);
}
Expand All @@ -78,28 +77,13 @@ export const LogViewer: React.FC = () => {
fetchLogs();

// Subscribe to new logs
const subscription = Logger.subscribe((newLogs) => {
setLogs(newLogs);
// Update components list
const uniqueComponents = new Set<string>();
newLogs.forEach(log => {
if (log.component) {
uniqueComponents.add(log.component);
}
});
setComponents(Array.from(uniqueComponents));

// Scroll to bottom when new logs arrive
if (listRef.current) {
listRef.current.scrollTop = listRef.current.scrollHeight;
}
});
const subscription = LogService.subscribe(setLogs);

// Set up polling for new logs every 5 seconds
const interval = setInterval(fetchLogs, 5000);

return () => {
subscription.unsubscribe();
subscription();
clearInterval(interval);
};
}, []);
Expand All @@ -120,12 +104,12 @@ export const LogViewer: React.FC = () => {
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
} catch (error) {
Logger.error('Failed to download logs', error, 'LogViewer');
LogService.error('Failed to download logs', error, 'LogViewer');
}
};

const handleClearLogs = () => {
Logger.clearLogs();
LogService.clearLogs();
};

const isWithinTimeRange = (timestamp: string) => {
Expand Down Expand Up @@ -160,13 +144,13 @@ export const LogViewer: React.FC = () => {

const getLevelColor = (level: LogLevel): "default" | "primary" | "secondary" | "error" | "info" | "success" | "warning" => {
switch (level) {
case 'error':
case LogLevel.ERROR:
return 'error';
case 'warn':
case LogLevel.WARN:
return 'warning';
case 'info':
case LogLevel.INFO:
return 'info';
case 'debug':
case LogLevel.DEBUG:
return 'default';
default:
return 'default';
Expand All @@ -175,9 +159,9 @@ export const LogViewer: React.FC = () => {

const getLogItemStyle = (level: LogLevel) => {
switch (level) {
case 'error':
case LogLevel.ERROR:
return { backgroundColor: 'rgba(211, 47, 47, 0.1)' };
case 'warn':
case LogLevel.WARN:
return { backgroundColor: 'rgba(237, 108, 2, 0.1)' };
default:
return {};
Expand Down
27 changes: 11 additions & 16 deletions src/components/TaskManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,26 @@ import {
LinearProgress,
Chip
} from '@mui/material';
import { TaskService, Task } from '../services/TaskService';
import Logger from '../services/LogService';
import { TaskService, Task, TaskStatus } from '../services';
import { LogService } from '../services';

export const TaskManager: React.FC = () => {
const [tasks, setTasks] = useState<Task[]>([]);

useEffect(() => {
const subscription = TaskService.subscribe((updatedTasks) => {
setTasks(updatedTasks);
});

return () => {
subscription.unsubscribe();
};
const subscription = TaskService.subscribe(setTasks);
return () => subscription();
}, []);

const getStatusColor = (status: string): "default" | "primary" | "secondary" | "error" | "info" | "success" | "warning" => {
const getStatusColor = (status: TaskStatus): "default" | "primary" | "secondary" | "error" | "info" | "success" | "warning" => {
switch (status) {
case 'completed':
case TaskStatus.COMPLETED:
return 'success';
case 'failed':
case TaskStatus.FAILED:
return 'error';
case 'running':
case TaskStatus.RUNNING:
return 'primary';
case 'queued':
case TaskStatus.PENDING:
return 'secondary';
default:
return 'default';
Expand All @@ -52,7 +47,7 @@ export const TaskManager: React.FC = () => {
</Typography>
) : (
<List>
{tasks.map((task) => (
{tasks.map((task: Task) => (
<ListItem key={task.id} divider>
<Box sx={{ width: '100%' }}>
<Box sx={{ display: 'flex', justifyContent: 'space-between', mb: 1 }}>
Expand All @@ -66,7 +61,7 @@ export const TaskManager: React.FC = () => {
/>
</Box>

{task.progress !== undefined && task.status === 'running' && (
{task.progress !== undefined && task.status === TaskStatus.RUNNING && (
<Box sx={{ width: '100%', mt: 1 }}>
<LinearProgress
variant="determinate"
Expand Down
Loading

0 comments on commit b5426d9

Please sign in to comment.