This commit is contained in:
42
frontend/src/App.css
Normal file
42
frontend/src/App.css
Normal file
@@ -0,0 +1,42 @@
|
||||
#root {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 6em;
|
||||
padding: 1.5em;
|
||||
will-change: filter;
|
||||
transition: filter 300ms;
|
||||
}
|
||||
.logo:hover {
|
||||
filter: drop-shadow(0 0 2em #646cffaa);
|
||||
}
|
||||
.logo.react:hover {
|
||||
filter: drop-shadow(0 0 2em #61dafbaa);
|
||||
}
|
||||
|
||||
@keyframes logo-spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
a:nth-of-type(2) .logo {
|
||||
animation: logo-spin infinite 20s linear;
|
||||
}
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 2em;
|
||||
}
|
||||
|
||||
.read-the-docs {
|
||||
color: #888;
|
||||
}
|
||||
13
frontend/src/App.tsx
Normal file
13
frontend/src/App.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import React from 'react';
|
||||
import { AccountsProvider } from './hooks/useAccounts';
|
||||
import Dashboard from './pages/Dashboard';
|
||||
|
||||
const App: React.FC = () => {
|
||||
return (
|
||||
<AccountsProvider>
|
||||
<Dashboard />
|
||||
</AccountsProvider>
|
||||
);
|
||||
};
|
||||
|
||||
export default App;
|
||||
1
frontend/src/assets/react.svg
Normal file
1
frontend/src/assets/react.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
18
frontend/src/components/NebulaBanner.tsx
Normal file
18
frontend/src/components/NebulaBanner.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
import React from 'react';
|
||||
import { Box } from '@mui/material';
|
||||
|
||||
const NebulaBanner: React.FC = () => {
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
height: 4,
|
||||
width: '100%',
|
||||
background: (theme) => `linear-gradient(90deg, ${theme.palette.primary.main} 0%, ${theme.palette.primary.dark || theme.palette.primary.main} 50%, ${theme.palette.primary.main} 100%)`,
|
||||
boxShadow: (theme) => `0 0 10px ${theme.palette.primary.main}`,
|
||||
zIndex: 2000
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default NebulaBanner;
|
||||
198
frontend/src/components/SteamCard.tsx
Normal file
198
frontend/src/components/SteamCard.tsx
Normal file
@@ -0,0 +1,198 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import {
|
||||
Card, CardContent, Typography, Box, Avatar, IconButton, Tooltip,
|
||||
Chip, Dialog, DialogTitle, DialogContent,
|
||||
TextField, DialogActions, Button
|
||||
} from '@mui/material';
|
||||
import BoltIcon from '@mui/icons-material/Bolt';
|
||||
import TimerIcon from '@mui/icons-material/Timer';
|
||||
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
|
||||
import DeleteIcon from '@mui/icons-material/Delete';
|
||||
|
||||
interface SteamCardProps {
|
||||
account: {
|
||||
_id: string;
|
||||
steamId: string;
|
||||
personaName: string;
|
||||
loginName?: string;
|
||||
steamLoginSecure?: string;
|
||||
autoCheckCooldown: boolean;
|
||||
accountType: 'owned' | 'watched';
|
||||
avatar: string;
|
||||
profileUrl?: string;
|
||||
status?: string;
|
||||
vacBanned: boolean;
|
||||
gameBans: number;
|
||||
lastBanCheck: string;
|
||||
cooldownExpiresAt?: string;
|
||||
};
|
||||
onDelete: (id: string) => void;
|
||||
onUpdate: (id: string, data: any) => void;
|
||||
onFastLogin: () => void;
|
||||
}
|
||||
|
||||
const SteamCard: React.FC<SteamCardProps> = ({ account, onDelete, onUpdate, onFastLogin }) => {
|
||||
const [timeLeft, setTimeLeft] = useState<string | null>(null);
|
||||
const [isLoginNameDialogOpen, setIsLoginNameDialogOpen] = useState(false);
|
||||
const [tempLoginName, setTempLoginName] = useState(account.loginName || '');
|
||||
|
||||
const isOwned = account.accountType === 'owned';
|
||||
const isPermanentlyBanned = account.vacBanned || account.gameBans > 0 || account.status === 'banned';
|
||||
const cooldownDate = account.cooldownExpiresAt ? new Date(account.cooldownExpiresAt) : null;
|
||||
const isCooldownActive = cooldownDate && !isNaN(cooldownDate.getTime()) && cooldownDate.getTime() > Date.now();
|
||||
|
||||
useEffect(() => {
|
||||
if (!isCooldownActive || !cooldownDate) {
|
||||
setTimeLeft(null);
|
||||
return;
|
||||
}
|
||||
|
||||
const timer = setInterval(() => {
|
||||
const now = new Date();
|
||||
const diff = cooldownDate.getTime() - now.getTime();
|
||||
|
||||
if (diff <= 0) {
|
||||
setTimeLeft(null);
|
||||
clearInterval(timer);
|
||||
return;
|
||||
}
|
||||
|
||||
const hours = Math.floor(diff / 3600000);
|
||||
const mins = Math.floor((diff % 3600000) / 60000);
|
||||
const secs = Math.floor((diff % 60000) / 1000);
|
||||
|
||||
setTimeLeft(`${hours}h ${mins}m ${secs}s`);
|
||||
}, 1000);
|
||||
|
||||
return () => clearInterval(timer);
|
||||
}, [account.cooldownExpiresAt, isCooldownActive, cooldownDate]);
|
||||
|
||||
const getStatusColor = () => {
|
||||
if (isPermanentlyBanned) return '#af3212';
|
||||
if (isCooldownActive) return '#ff9800';
|
||||
return '#5c7e10';
|
||||
};
|
||||
|
||||
const getStatusText = () => {
|
||||
if (account.vacBanned) return 'VAC BANNED';
|
||||
if (account.gameBans > 0) return `${account.gameBans} GAME BAN${account.gameBans > 1 ? 'S' : ''}`;
|
||||
if (isPermanentlyBanned) return 'BANNED';
|
||||
if (isCooldownActive) return 'COOLDOWN';
|
||||
return 'AVAILABLE';
|
||||
};
|
||||
|
||||
const handleFastLoginClick = () => {
|
||||
if (!account.loginName) {
|
||||
setIsLoginNameDialogOpen(true);
|
||||
return;
|
||||
}
|
||||
onFastLogin();
|
||||
};
|
||||
|
||||
return (
|
||||
<Card sx={{
|
||||
position: 'relative',
|
||||
transition: 'transform 0.2s, box-shadow 0.2s',
|
||||
'&:hover': {
|
||||
transform: 'translateY(-4px)',
|
||||
boxShadow: `0 0 20px rgba(102, 192, 244, 0.2)`
|
||||
},
|
||||
borderTop: `4px solid ${getStatusColor()}`
|
||||
}}>
|
||||
<CardContent sx={{ p: 2, '&:last-child': { pb: 2 } }}>
|
||||
<Box sx={{ display: 'flex', gap: 2, alignItems: 'flex-start' }}>
|
||||
<Avatar
|
||||
src={account.avatar}
|
||||
variant="square"
|
||||
sx={{
|
||||
width: 64,
|
||||
height: 64,
|
||||
border: `2px solid ${getStatusColor()}`,
|
||||
boxShadow: isPermanentlyBanned ? '0 0 10px rgba(175, 50, 18, 0.4)' : 'none'
|
||||
}}
|
||||
/>
|
||||
|
||||
<Box sx={{ flexGrow: 1, minWidth: 0 }}>
|
||||
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start' }}>
|
||||
<Typography variant="h6" noWrap sx={{ color: '#ffffff', mb: 0.5, maxWidth: '140px' }}>
|
||||
{account.personaName || 'Unknown'}
|
||||
</Typography>
|
||||
</Box>
|
||||
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
|
||||
<Chip
|
||||
label={getStatusText()}
|
||||
size="small"
|
||||
sx={{
|
||||
backgroundColor: getStatusColor(),
|
||||
color: '#ffffff',
|
||||
fontWeight: 'bold',
|
||||
fontSize: '0.65rem',
|
||||
height: 20
|
||||
}}
|
||||
/>
|
||||
{timeLeft && (
|
||||
<Typography variant="caption" sx={{ color: '#ff9800', fontWeight: 'bold', display: 'flex', alignItems: 'center' }}>
|
||||
<TimerIcon sx={{ fontSize: 12, mr: 0.5 }} /> {timeLeft}
|
||||
</Typography>
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<Box sx={{ mt: 2, display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
||||
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>
|
||||
{isOwned && (
|
||||
<Button
|
||||
variant="contained"
|
||||
size="small"
|
||||
onClick={handleFastLoginClick}
|
||||
sx={{
|
||||
minWidth: 'unset',
|
||||
px: 1,
|
||||
py: 0.2,
|
||||
fontSize: '0.7rem',
|
||||
background: account.loginName ? 'linear-gradient(to bottom, #8ed629 5%, #5c7e10 95%)' : 'rgba(255,255,255,0.1)'
|
||||
}}
|
||||
>
|
||||
<BoltIcon sx={{ fontSize: 14, mr: 0.5 }} /> LOGIN
|
||||
</Button>
|
||||
)}
|
||||
</Box>
|
||||
|
||||
<Box sx={{ display: 'flex', gap: 0.5 }}>
|
||||
<Tooltip title="View Profile">
|
||||
<IconButton size="small" component="a" href={account.profileUrl || '#'} target="_blank" rel="noopener noreferrer">
|
||||
<OpenInNewIcon fontSize="small" />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
<Tooltip title="Remove Tracker">
|
||||
<IconButton size="small" color="error" onClick={() => onDelete(account._id)}>
|
||||
<DeleteIcon fontSize="small" />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<Dialog open={isLoginNameDialogOpen} onClose={() => setIsLoginNameDialogOpen(false)}>
|
||||
<DialogTitle sx={{ backgroundColor: '#1b2838', color: '#ffffff' }}>Steam Login Name</DialogTitle>
|
||||
<DialogContent sx={{ backgroundColor: '#1b2838', pt: 2 }}>
|
||||
<TextField
|
||||
fullWidth
|
||||
autoFocus
|
||||
label="Steam Username"
|
||||
value={tempLoginName}
|
||||
onChange={(e) => setTempLoginName(e.target.value)}
|
||||
/>
|
||||
</DialogContent>
|
||||
<DialogActions sx={{ backgroundColor: '#1b2838', p: 2 }}>
|
||||
<Button onClick={() => setIsLoginNameDialogOpen(false)} color="inherit">Cancel</Button>
|
||||
<Button onClick={() => { onUpdate(account._id, { loginName: tempLoginName }); setIsLoginNameDialogOpen(false); }} variant="contained" color="primary">Save</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default SteamCard;
|
||||
175
frontend/src/hooks/useAccounts.tsx
Normal file
175
frontend/src/hooks/useAccounts.tsx
Normal file
@@ -0,0 +1,175 @@
|
||||
import React, { createContext, useContext, useState, useEffect } from 'react';
|
||||
|
||||
export interface Account {
|
||||
_id: string;
|
||||
steamId: string;
|
||||
personaName: string;
|
||||
loginName?: string;
|
||||
steamLoginSecure?: string;
|
||||
loginConfig?: any;
|
||||
sessionUpdatedAt?: string;
|
||||
autoCheckCooldown: boolean;
|
||||
avatar: string;
|
||||
localAvatar?: string;
|
||||
profileUrl: string;
|
||||
status: string;
|
||||
vacBanned: boolean;
|
||||
gameBans: number;
|
||||
lastBanCheck: string;
|
||||
lastScrapeTime?: string;
|
||||
cooldownExpiresAt?: string;
|
||||
authError?: boolean;
|
||||
notes?: string;
|
||||
}
|
||||
|
||||
export interface ServerConfig {
|
||||
url: string;
|
||||
token?: string;
|
||||
serverSteamId?: string;
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
interface AccountsContextType {
|
||||
accounts: Account[];
|
||||
serverConfig: ServerConfig | null;
|
||||
isLoading: boolean;
|
||||
isSyncing: boolean;
|
||||
addAccount: (data: { identifier: string }) => Promise<void>;
|
||||
updateAccount: (id: string, data: Partial<Account>) => Promise<void>;
|
||||
deleteAccount: (id: string) => Promise<void>;
|
||||
switchAccount: (loginName: string) => Promise<void>;
|
||||
openSteamLogin: (steamId: string) => Promise<void>;
|
||||
shareAccountWithUser: (steamId: string, targetSteamId: string) => Promise<any>;
|
||||
|
||||
// Server Methods
|
||||
updateServerConfig: (config: Partial<ServerConfig>) => Promise<void>;
|
||||
loginToServer: () => Promise<void>;
|
||||
syncNow: () => Promise<void>;
|
||||
getCommunityAccounts: () => Promise<any[]>;
|
||||
getServerUsers: () => Promise<any[]>;
|
||||
refreshAccounts: (showLoading?: boolean) => Promise<void>;
|
||||
}
|
||||
|
||||
const AccountsContext = createContext<AccountsContextType | undefined>(undefined);
|
||||
|
||||
export const AccountsProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||
const [accounts, setAccounts] = useState<Account[]>([]);
|
||||
const [serverConfig, setServerConfig] = useState<ServerConfig | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [isSyncing, setIsSyncing] = useState(false);
|
||||
|
||||
const refreshAccounts = async (showLoading = false) => {
|
||||
if (showLoading) setIsLoading(true);
|
||||
try {
|
||||
const api = (window as any).electronAPI;
|
||||
if (!api) {
|
||||
console.warn("[useAccounts] electronAPI not found in window");
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("[useAccounts] Fetching data from main process...");
|
||||
const accData = await api.getAccounts();
|
||||
const configData = await api.getServerConfig();
|
||||
|
||||
setAccounts(Array.isArray(accData) ? accData : []);
|
||||
setServerConfig(configData || null);
|
||||
} catch (error) {
|
||||
console.error("[useAccounts] Error loading accounts:", error);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
refreshAccounts(true);
|
||||
const api = (window as any).electronAPI;
|
||||
if (api?.onAccountsUpdated) {
|
||||
const cleanup = api.onAccountsUpdated((updatedAccounts: Account[]) => {
|
||||
setAccounts(Array.isArray(updatedAccounts) ? updatedAccounts : []);
|
||||
});
|
||||
return typeof cleanup === 'function' ? cleanup : undefined;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const syncNow = async () => {
|
||||
setIsSyncing(true);
|
||||
try {
|
||||
await (window as any).electronAPI.syncNow();
|
||||
await refreshAccounts();
|
||||
} catch (e) {
|
||||
console.error("[useAccounts] Sync failed", e);
|
||||
} finally {
|
||||
setIsSyncing(false);
|
||||
}
|
||||
};
|
||||
|
||||
const addAccount = async (data: { identifier: string }) => {
|
||||
await (window as any).electronAPI.addAccount(data);
|
||||
await refreshAccounts();
|
||||
await syncNow();
|
||||
};
|
||||
|
||||
const updateAccount = async (id: string, data: Partial<Account>) => {
|
||||
await (window as any).electronAPI.updateAccount(id, data);
|
||||
await refreshAccounts();
|
||||
};
|
||||
|
||||
const deleteAccount = async (id: string) => {
|
||||
if (!window.confirm("Are you sure you want to remove this account?")) return;
|
||||
await (window as any).electronAPI.deleteAccount(id);
|
||||
await refreshAccounts();
|
||||
};
|
||||
|
||||
const switchAccount = async (loginName: string) => {
|
||||
if (!loginName) return;
|
||||
await (window as any).electronAPI.switchAccount(loginName);
|
||||
};
|
||||
|
||||
const openSteamLogin = async (steamId: string) => {
|
||||
await (window as any).electronAPI.openSteamLogin(steamId);
|
||||
await syncNow();
|
||||
};
|
||||
|
||||
const shareAccountWithUser = async (steamId: string, targetSteamId: string) => {
|
||||
const res = await (window as any).electronAPI.shareAccountWithUser(steamId, targetSteamId);
|
||||
await syncNow();
|
||||
return res;
|
||||
};
|
||||
|
||||
const updateServerConfig = async (config: Partial<ServerConfig>) => {
|
||||
const updated = await (window as any).electronAPI.updateServerConfig(config);
|
||||
setServerConfig(updated);
|
||||
};
|
||||
|
||||
const loginToServer = async () => {
|
||||
await (window as any).electronAPI.loginToServer();
|
||||
await refreshAccounts();
|
||||
await syncNow();
|
||||
};
|
||||
|
||||
const getCommunityAccounts = async () => {
|
||||
return await (window as any).electronAPI.getCommunityAccounts();
|
||||
};
|
||||
|
||||
const getServerUsers = async () => {
|
||||
return await (window as any).electronAPI.getServerUsers();
|
||||
};
|
||||
|
||||
return (
|
||||
<AccountsContext.Provider value={{
|
||||
accounts, serverConfig, isLoading, isSyncing, addAccount, updateAccount, deleteAccount,
|
||||
switchAccount, openSteamLogin, updateServerConfig, loginToServer,
|
||||
getCommunityAccounts, getServerUsers, shareAccountWithUser, syncNow, refreshAccounts
|
||||
}}>
|
||||
{children}
|
||||
</AccountsContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useAccounts = () => {
|
||||
const context = useContext(AccountsContext);
|
||||
if (context === undefined) {
|
||||
throw new Error('useAccounts must be used within an AccountsProvider');
|
||||
}
|
||||
return context;
|
||||
};
|
||||
77
frontend/src/hooks/useAuth.tsx
Normal file
77
frontend/src/hooks/useAuth.tsx
Normal file
@@ -0,0 +1,77 @@
|
||||
import React, { createContext, useContext, useState, useEffect } from 'react';
|
||||
import axios from 'axios';
|
||||
|
||||
interface User {
|
||||
_id: string;
|
||||
steamId: string;
|
||||
personaName: string;
|
||||
avatar: string;
|
||||
role: string;
|
||||
}
|
||||
|
||||
interface AuthContextType {
|
||||
user: User | null;
|
||||
token: string | null;
|
||||
login: (token: string) => void;
|
||||
logout: () => void;
|
||||
isLoading: boolean;
|
||||
}
|
||||
|
||||
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
||||
|
||||
export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||
const [user, setUser] = useState<User | null>(null);
|
||||
const [token, setToken] = useState<string | null>(localStorage.getItem('token'));
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
const login = (newToken: string) => {
|
||||
localStorage.setItem('token', newToken);
|
||||
setIsLoading(true); // Start loading immediately
|
||||
setToken(newToken);
|
||||
};
|
||||
|
||||
const logout = () => {
|
||||
localStorage.removeItem('token');
|
||||
setToken(null);
|
||||
setUser(null);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const fetchUser = async () => {
|
||||
if (!token) {
|
||||
setIsLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const apiUrl = import.meta.env.VITE_API_URL || 'http://localhost:3001';
|
||||
const response = await axios.get(`${apiUrl}/api/auth/me`, {
|
||||
headers: { Authorization: `Bearer ${token}` }
|
||||
});
|
||||
setUser(response.data.user);
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch user:', error);
|
||||
logout();
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchUser();
|
||||
}, [token]);
|
||||
|
||||
return (
|
||||
<AuthContext.Provider value={{ user, token, login, logout, isLoading }}>
|
||||
{children}
|
||||
</AuthContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useAuth = () => {
|
||||
const context = useContext(AuthContext);
|
||||
if (context === undefined) {
|
||||
throw new Error('useAuth must be used within an AuthProvider');
|
||||
}
|
||||
return context;
|
||||
};
|
||||
22
frontend/src/index.css
Normal file
22
frontend/src/index.css
Normal file
@@ -0,0 +1,22 @@
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background-color: #171a21;
|
||||
color: white;
|
||||
font-family: "Motiva Sans", "Roboto", sans-serif;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#root {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
/* Remove default Vite styles that might interfere */
|
||||
:root {
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
color-scheme: dark;
|
||||
}
|
||||
65
frontend/src/main.tsx
Normal file
65
frontend/src/main.tsx
Normal file
@@ -0,0 +1,65 @@
|
||||
import React, { Component, type ErrorInfo, type ReactNode } from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import { Box, Typography, Button } from '@mui/material';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { AppThemeProvider } from './theme/ThemeContext';
|
||||
import App from './App';
|
||||
|
||||
console.log("[Renderer] Initializing React App...");
|
||||
|
||||
window.addEventListener('error', (event) => {
|
||||
console.error("[Global Error]", event.error);
|
||||
});
|
||||
|
||||
window.addEventListener('unhandledrejection', (event) => {
|
||||
console.error("[Unhandled Rejection]", event.reason);
|
||||
});
|
||||
|
||||
class ErrorBoundary extends Component<{ children: ReactNode }, { hasError: boolean, error: Error | null }> {
|
||||
constructor(props: any) {
|
||||
super(props);
|
||||
this.state = { hasError: false, error: null };
|
||||
}
|
||||
|
||||
static getDerivedStateFromError(error: Error) {
|
||||
return { hasError: true, error };
|
||||
}
|
||||
|
||||
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
||||
console.error("[Renderer] CRASH DETECTED:", error);
|
||||
console.error("[Renderer] Error Info:", errorInfo);
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.hasError) {
|
||||
return (
|
||||
<Box sx={{ p: 4, textAlign: 'center', backgroundColor: '#171a21', color: 'white', minHeight: '100vh', display: 'flex', flexDirection: 'column', justifyContent: 'center', alignItems: 'center' }}>
|
||||
<Typography variant="h4" color="error" gutterBottom>Application Error</Typography>
|
||||
<Typography variant="body1" sx={{ mb: 2, opacity: 0.8, maxWidth: '600px' }}>{this.state.error?.stack || this.state.error?.message}</Typography>
|
||||
<Button variant="contained" color="primary" onClick={() => window.location.reload()}>Retry App</Button>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
|
||||
const rootElement = document.getElementById('root');
|
||||
if (!rootElement) {
|
||||
console.error("[Renderer] Failed to find #root element!");
|
||||
} else {
|
||||
ReactDOM.createRoot(rootElement).render(
|
||||
<React.StrictMode>
|
||||
<ErrorBoundary>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<AppThemeProvider>
|
||||
<App />
|
||||
</AppThemeProvider>
|
||||
</QueryClientProvider>
|
||||
</ErrorBoundary>
|
||||
</React.StrictMode>
|
||||
);
|
||||
console.log("[Renderer] Render initiated.");
|
||||
}
|
||||
553
frontend/src/pages/Dashboard.tsx
Normal file
553
frontend/src/pages/Dashboard.tsx
Normal file
@@ -0,0 +1,553 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import {
|
||||
Box, Container, Typography, Button, TextField,
|
||||
InputAdornment, IconButton, AppBar, Toolbar, Avatar,
|
||||
Tooltip, Dialog, DialogTitle, DialogContent,
|
||||
DialogActions, CircularProgress, Paper, Chip,
|
||||
Table, TableBody, TableCell, TableContainer, TableHead, TableRow,
|
||||
Switch, FormControlLabel, Divider, List, ListItem, ListItemText, ListItemSecondaryAction,
|
||||
Tabs, Tab, Select, MenuItem, FormControl, InputLabel
|
||||
} from '@mui/material';
|
||||
import SearchIcon from '@mui/icons-material/Search';
|
||||
import AddIcon from '@mui/icons-material/Add';
|
||||
import SteamIcon from '@mui/icons-material/SportsEsports';
|
||||
import DeleteIcon from '@mui/icons-material/Delete';
|
||||
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
|
||||
import SyncIcon from '@mui/icons-material/Sync';
|
||||
import BoltIcon from '@mui/icons-material/Bolt';
|
||||
import TimerIcon from '@mui/icons-material/Timer';
|
||||
import LockResetIcon from '@mui/icons-material/LockReset';
|
||||
import SettingsIcon from '@mui/icons-material/Settings';
|
||||
import ShareIcon from '@mui/icons-material/Share';
|
||||
import GroupAddIcon from '@mui/icons-material/GroupAdd';
|
||||
import PublicIcon from '@mui/icons-material/Public';
|
||||
import ShieldIcon from '@mui/icons-material/Shield';
|
||||
import GppBadIcon from '@mui/icons-material/GppBad';
|
||||
import PeopleIcon from '@mui/icons-material/People';
|
||||
import { useAccounts, type Account } from '../hooks/useAccounts';
|
||||
import { useAppTheme } from '../theme/ThemeContext';
|
||||
import type { ThemeType } from '../theme/SteamTheme';
|
||||
import NebulaBanner from '../components/NebulaBanner';
|
||||
|
||||
const Dashboard: React.FC = () => {
|
||||
const { currentTheme, setTheme } = useAppTheme();
|
||||
const {
|
||||
accounts, isLoading, isSyncing, serverConfig, addAccount, deleteAccount,
|
||||
switchAccount, openSteamLogin, updateServerConfig, loginToServer,
|
||||
getCommunityAccounts, syncNow
|
||||
} = useAccounts();
|
||||
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
const [isAddDialogOpen, setIsAddDialogOpen] = useState(false);
|
||||
const [isSettingsOpen, setIsSettingsOpen] = useState(false);
|
||||
const [identifier, setIdentifier] = useState('');
|
||||
|
||||
const [addTab, setAddTab] = useState(0);
|
||||
const [communityAccounts, setCommunityAccounts] = useState<any[]>([]);
|
||||
const [isCommunityLoading, setIsCommunityLoading] = useState(false);
|
||||
const [serverUrl, setServerUrl] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
if (serverConfig?.url) {
|
||||
setServerUrl(serverConfig.url);
|
||||
}
|
||||
}, [serverConfig?.url]);
|
||||
|
||||
const loadCommunity = async () => {
|
||||
setIsCommunityLoading(true);
|
||||
try {
|
||||
const data = await getCommunityAccounts();
|
||||
setCommunityAccounts(Array.isArray(data) ? data : []);
|
||||
} catch (e) {
|
||||
} finally {
|
||||
setIsCommunityLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (isAddDialogOpen && addTab === 1) {
|
||||
loadCommunity();
|
||||
}
|
||||
}, [isAddDialogOpen, addTab]);
|
||||
|
||||
const handleAddAccount = async () => {
|
||||
if (!identifier) return;
|
||||
try {
|
||||
await addAccount({ identifier });
|
||||
setIsAddDialogOpen(false);
|
||||
setIdentifier('');
|
||||
} catch (e) {
|
||||
console.error("[Dashboard] Add failed:", e);
|
||||
}
|
||||
};
|
||||
|
||||
const handleAddFromCommunity = async (commAcc: any) => {
|
||||
try {
|
||||
await addAccount({ identifier: commAcc.steamId });
|
||||
setIsAddDialogOpen(false);
|
||||
} catch (e) { }
|
||||
};
|
||||
|
||||
const saveSettings = async () => {
|
||||
await updateServerConfig({ url: serverUrl });
|
||||
alert("Server URL updated!");
|
||||
};
|
||||
|
||||
const safeAccounts = Array.isArray(accounts) ? accounts : [];
|
||||
const filteredAccounts = safeAccounts.filter((acc) => {
|
||||
if (!acc) return false;
|
||||
const name = acc.personaName || 'Unknown';
|
||||
const id = acc.steamId || '';
|
||||
return name.toLowerCase().includes(searchTerm.toLowerCase()) || id.includes(searchTerm);
|
||||
});
|
||||
|
||||
return (
|
||||
<Box sx={{ minHeight: '100vh', display: 'flex', flexDirection: 'column', backgroundColor: 'background.default' }}>
|
||||
<NebulaBanner />
|
||||
|
||||
<AppBar position="sticky" sx={{ WebkitAppRegion: 'drag', background: 'background.default', boxShadow: 'none', borderBottom: '1px solid', borderColor: 'divider' } as any}>
|
||||
<Toolbar variant="dense">
|
||||
<SteamIcon sx={{ mr: 2, color: 'primary.main' }} />
|
||||
<Typography variant="h6" component="div" sx={{ flexGrow: 1, fontWeight: 'bold', fontSize: '1rem', letterSpacing: '1px' }}>
|
||||
ULTIMATE BAN TRACKER
|
||||
</Typography>
|
||||
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2, WebkitAppRegion: 'no-drag' } as any}>
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', mr: 1 }}>
|
||||
{isSyncing ? (
|
||||
<CircularProgress size={16} sx={{ color: 'primary.main', mr: 1 }} />
|
||||
) : (
|
||||
<IconButton size="small" onClick={() => syncNow()} disabled={!serverConfig?.enabled} sx={{ color: 'primary.main' }}>
|
||||
<SyncIcon sx={{ fontSize: 18 }} />
|
||||
</IconButton>
|
||||
)}
|
||||
</Box>
|
||||
|
||||
<TextField
|
||||
size="small"
|
||||
placeholder="Search accounts..."
|
||||
value={searchTerm}
|
||||
onChange={(e) => setSearchTerm(e.target.value)}
|
||||
sx={{
|
||||
backgroundColor: 'rgba(255, 255, 255, 0.05)',
|
||||
borderRadius: 1,
|
||||
width: 200,
|
||||
'& .MuiOutlinedInput-root': { '& fieldset': { border: 'none' }, height: 32 }
|
||||
}}
|
||||
InputProps={{
|
||||
startAdornment: (
|
||||
<InputAdornment position="start">
|
||||
<SearchIcon fontSize="small" sx={{ color: 'text.secondary' }} />
|
||||
</InputAdornment>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
|
||||
<Button
|
||||
variant="contained"
|
||||
color="primary"
|
||||
startIcon={<AddIcon />}
|
||||
onClick={() => setIsAddDialogOpen(true)}
|
||||
sx={{ height: 32 }}
|
||||
>
|
||||
Add
|
||||
</Button>
|
||||
|
||||
<IconButton color="inherit" onClick={() => setIsSettingsOpen(true)}>
|
||||
<SettingsIcon />
|
||||
</IconButton>
|
||||
</Box>
|
||||
</Toolbar>
|
||||
</AppBar>
|
||||
|
||||
<Container maxWidth="xl" sx={{ mt: 4, mb: 4, flexGrow: 1, overflowY: 'auto' }}>
|
||||
{isLoading ? (
|
||||
<Box sx={{ display: 'flex', justifyContent: 'center', mt: 10 }}><CircularProgress color="primary" /></Box>
|
||||
) : (
|
||||
<TableContainer component={Paper} sx={{ background: 'background.paper', backdropFilter: 'blur(10px)', borderRadius: 0, border: '1px solid', borderColor: 'divider' }}>
|
||||
<Table size="small">
|
||||
<TableHead>
|
||||
<TableRow sx={{ background: 'rgba(0,0,0,0.1)' }}>
|
||||
<TableCell sx={{ color: 'text.secondary', fontWeight: 'bold', width: 60 }}>AVATAR</TableCell>
|
||||
<TableCell sx={{ color: 'text.secondary', fontWeight: 'bold' }}>ACCOUNT</TableCell>
|
||||
<TableCell sx={{ color: 'text.secondary', fontWeight: 'bold' }}>BAN STATUS</TableCell>
|
||||
<TableCell sx={{ color: 'text.secondary', fontWeight: 'bold' }}>COOLDOWN</TableCell>
|
||||
<TableCell sx={{ color: 'text.secondary', fontWeight: 'bold', textAlign: 'right' }}>ACTIONS</TableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{filteredAccounts.map((account) => (
|
||||
<AccountRow
|
||||
key={account._id}
|
||||
account={account}
|
||||
onDelete={deleteAccount}
|
||||
onSwitch={switchAccount}
|
||||
onAuth={() => openSteamLogin(account.steamId)}
|
||||
/>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
)}
|
||||
|
||||
{!isLoading && filteredAccounts.length === 0 && (
|
||||
<Box sx={{ width: '100%', mt: 10, textAlign: 'center' }}>
|
||||
<Typography variant="h6" color="textSecondary">
|
||||
No accounts tracked. Click "Add Account" to get started!
|
||||
</Typography>
|
||||
</Box>
|
||||
)}
|
||||
</Container>
|
||||
|
||||
{/* Settings Dialog */}
|
||||
<Dialog open={isSettingsOpen} onClose={() => setIsSettingsOpen(false)} maxWidth="sm" fullWidth>
|
||||
<DialogTitle sx={{ backgroundColor: 'background.paper', color: 'text.primary' }}>Settings & Customization</DialogTitle>
|
||||
<DialogContent sx={{ backgroundColor: 'background.paper', pt: 2 }}>
|
||||
<Typography variant="subtitle2" gutterBottom sx={{ color: 'primary.main', mt: 1 }}>THEME SELECTION</Typography>
|
||||
<FormControl fullWidth size="small" sx={{ mb: 3 }}>
|
||||
<InputLabel sx={{ color: 'text.secondary' }}>Active Theme</InputLabel>
|
||||
<Select
|
||||
value={currentTheme || 'steam'}
|
||||
label="Active Theme"
|
||||
onChange={(e) => setTheme(e.target.value as ThemeType)}
|
||||
sx={{ bgcolor: 'rgba(0,0,0,0.1)', color: 'text.primary' }}
|
||||
>
|
||||
<MenuItem value="steam">Steam Classic</MenuItem>
|
||||
<MenuItem value="mocha">Catppuccin Mocha</MenuItem>
|
||||
<MenuItem value="latte">Catppuccin Latte</MenuItem>
|
||||
<MenuItem value="nord">Nord Arctic</MenuItem>
|
||||
<MenuItem value="tokyo">Tokyo Night</MenuItem>
|
||||
</Select>
|
||||
</FormControl>
|
||||
|
||||
<Divider sx={{ my: 2, borderColor: 'divider' }} />
|
||||
|
||||
<Typography variant="subtitle2" gutterBottom sx={{ color: 'primary.main' }}>BACKEND CONFIGURATION</Typography>
|
||||
<TextField
|
||||
fullWidth
|
||||
label="Server URL"
|
||||
value={serverUrl}
|
||||
onChange={(e) => setServerUrl(e.target.value)}
|
||||
placeholder="https://ultimate-ban-tracker.narl.io"
|
||||
margin="dense"
|
||||
sx={{ mb: 2 }}
|
||||
InputProps={{
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
<Button
|
||||
variant="contained"
|
||||
size="small"
|
||||
onClick={saveSettings}
|
||||
sx={{ height: 30 }}
|
||||
>
|
||||
Apply
|
||||
</Button>
|
||||
</InputAdornment>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
|
||||
<Divider sx={{ my: 2, borderColor: 'divider' }} />
|
||||
|
||||
<Typography variant="subtitle2" gutterBottom sx={{ color: 'primary.main' }}>COMMUNITY AUTHENTICATION</Typography>
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', p: 2, bgcolor: 'rgba(0,0,0,0.1)', borderRadius: 1 }}>
|
||||
<Box>
|
||||
<Typography variant="body2" sx={{ fontWeight: 'bold' }}>
|
||||
{serverConfig?.token ? "Connected to Server" : "Not Authenticated"}
|
||||
</Typography>
|
||||
<Typography variant="caption" color="textSecondary">
|
||||
{serverConfig?.token ? "Your accounts can now be shared with others." : "Login to share and sync with your community."}
|
||||
</Typography>
|
||||
</Box>
|
||||
<Box sx={{ display: 'flex', gap: 1 }}>
|
||||
{serverConfig?.token && (
|
||||
<Button
|
||||
variant="outlined"
|
||||
color="error"
|
||||
onClick={() => updateServerConfig({ token: undefined, enabled: false })}
|
||||
>
|
||||
Logout
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="outlined"
|
||||
color="primary"
|
||||
onClick={() => loginToServer()}
|
||||
disabled={!serverUrl}
|
||||
>
|
||||
{serverConfig?.token ? "Re-Login" : "Login with Steam"}
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Switch
|
||||
checked={serverConfig?.enabled || false}
|
||||
onChange={(e) => updateServerConfig({ enabled: e.target.checked })}
|
||||
disabled={!serverConfig?.token}
|
||||
/>
|
||||
}
|
||||
label="Enable Community Sync"
|
||||
sx={{ mt: 2 }}
|
||||
/>
|
||||
</DialogContent>
|
||||
<DialogActions sx={{ backgroundColor: 'background.paper', p: 2 }}>
|
||||
<Button onClick={() => setIsSettingsOpen(false)} color="inherit" variant="contained">Done</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
|
||||
{/* Add Account Dialog */}
|
||||
<Dialog open={isAddDialogOpen} onClose={() => setIsAddDialogOpen(false)} maxWidth="sm" fullWidth>
|
||||
<DialogTitle sx={{ backgroundColor: 'background.paper', color: 'text.primary', p: 0 }}>
|
||||
<Tabs value={addTab} onChange={(_, v) => setAddTab(v)} variant="fullWidth" textColor="inherit" indicatorColor="primary">
|
||||
<Tab label="Manual Add" icon={<AddIcon />} iconPosition="start" />
|
||||
<Tab label="From Community" icon={<PublicIcon />} iconPosition="start" disabled={!serverConfig?.token} />
|
||||
</Tabs>
|
||||
</DialogTitle>
|
||||
<DialogContent sx={{ backgroundColor: 'background.paper', pt: 2, minHeight: 300 }}>
|
||||
{addTab === 0 ? (
|
||||
<>
|
||||
<Typography variant="body2" color="textSecondary" sx={{ mb: 2 }}>
|
||||
Enter a SteamID64 or Profile URL. You will need to authenticate to enable full tracking and instant login features.
|
||||
</Typography>
|
||||
<TextField
|
||||
fullWidth
|
||||
autoFocus
|
||||
placeholder="SteamID64 or Profile URL"
|
||||
value={identifier}
|
||||
onChange={(e) => setIdentifier(e.target.value)}
|
||||
sx={{ '& .MuiOutlinedInput-root': { backgroundColor: 'rgba(0, 0, 0, 0.1)' } }}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<Box>
|
||||
{isCommunityLoading ? (
|
||||
<Box sx={{ display: 'flex', justifyContent: 'center', p: 4 }}><CircularProgress size={32} /></Box>
|
||||
) : (
|
||||
<List>
|
||||
{communityAccounts
|
||||
.filter(ca => !safeAccounts.find(a => a.steamId === ca.steamId))
|
||||
.map((ca) => (
|
||||
<ListItem key={ca.steamId} divider sx={{ borderColor: 'divider' }}>
|
||||
<Avatar src={ca.avatar} variant="square" sx={{ width: 32, height: 32, mr: 2 }} />
|
||||
<ListItemText
|
||||
primary={ca.personaName}
|
||||
secondary={ca.steamId}
|
||||
primaryTypographyProps={{ sx: { color: 'text.primary', fontWeight: 'bold' } }}
|
||||
/>
|
||||
<ListItemSecondaryAction>
|
||||
<Button size="small" variant="contained" onClick={() => handleAddFromCommunity(ca)}>Add</Button>
|
||||
</ListItemSecondaryAction>
|
||||
</ListItem>
|
||||
))}
|
||||
{communityAccounts.length === 0 && <Typography align="center" color="textSecondary" sx={{ p: 4 }}>No shared accounts found on server.</Typography>}
|
||||
</List>
|
||||
)}
|
||||
</Box>
|
||||
)}
|
||||
</DialogContent>
|
||||
<DialogActions sx={{ backgroundColor: 'background.paper', p: 2 }}>
|
||||
<Button onClick={() => setIsAddDialogOpen(false)} color="inherit">Cancel</Button>
|
||||
{addTab === 0 && <Button onClick={handleAddAccount} variant="contained" color="success" disabled={!identifier}>Add</Button>}
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
// --- Sub-Component: AccountRow ---
|
||||
|
||||
const AccountRow: React.FC<{
|
||||
account: Account,
|
||||
onDelete: (id: string) => void,
|
||||
onSwitch: (login: string) => void,
|
||||
onAuth: () => void
|
||||
}> = ({ account, onDelete, onSwitch, onAuth }) => {
|
||||
const { shareAccountWithUser, getServerUsers, serverConfig } = useAccounts();
|
||||
const [timeLeft, setTimeLeft] = useState<string | null>(null);
|
||||
const [isShareOpen, setIsShareOpen] = useState(false);
|
||||
const [targetUserId, setTargetUserId] = useState('');
|
||||
const [isSharing, setIsSharing] = useState(false);
|
||||
const [serverUsers, setServerUsers] = useState<any[]>([]);
|
||||
|
||||
const cooldownDate = account?.cooldownExpiresAt ? new Date(account.cooldownExpiresAt) : null;
|
||||
const isCooldownActive = cooldownDate && !isNaN(cooldownDate.getTime()) && cooldownDate.getTime() > Date.now();
|
||||
|
||||
useEffect(() => {
|
||||
if (!isCooldownActive || !cooldownDate) {
|
||||
setTimeLeft(null);
|
||||
return;
|
||||
}
|
||||
const targetTime = cooldownDate.getTime();
|
||||
const timer = setInterval(() => {
|
||||
const diff = targetTime - Date.now();
|
||||
if (diff <= 0) { setTimeLeft(null); clearInterval(timer); return; }
|
||||
const hours = Math.floor(diff / 3600000);
|
||||
const mins = Math.floor((diff % 3600000) / 60000);
|
||||
const secs = Math.floor((diff % 60000) / 1000);
|
||||
setTimeLeft(`${hours}h ${mins}m ${secs}s`);
|
||||
}, 1000);
|
||||
return () => clearInterval(timer);
|
||||
}, [account?.cooldownExpiresAt, isCooldownActive]);
|
||||
|
||||
const avatarSrc = account?.localAvatar
|
||||
? `steam-resource://${account.localAvatar}`
|
||||
: (account?.avatar || '');
|
||||
const [imgSrc, setImgSrc] = useState(avatarSrc);
|
||||
|
||||
useEffect(() => {
|
||||
setImgSrc(avatarSrc);
|
||||
}, [avatarSrc]);
|
||||
|
||||
const handleOpenShare = async () => {
|
||||
setIsShareOpen(true);
|
||||
try {
|
||||
const [users, selfInfo] = await Promise.all([
|
||||
getServerUsers(),
|
||||
(window as any).electronAPI.getServerUserInfo()
|
||||
]);
|
||||
const filtered = (Array.isArray(users) ? users : []).filter(u =>
|
||||
u.steamId !== selfInfo.steamId &&
|
||||
u.steamId !== account.steamId
|
||||
);
|
||||
setServerUsers(filtered);
|
||||
} catch (e) {}
|
||||
};
|
||||
|
||||
const handleShare = async () => {
|
||||
if (!targetUserId) return;
|
||||
setIsSharing(true);
|
||||
try {
|
||||
await shareAccountWithUser(account.steamId, targetUserId);
|
||||
alert(`Account shared successfully!`);
|
||||
setIsShareOpen(false);
|
||||
setTargetUserId('');
|
||||
} catch (e: any) {
|
||||
alert(e.message || "Failed to share account");
|
||||
} finally {
|
||||
setIsSharing(false);
|
||||
}
|
||||
};
|
||||
|
||||
const isBanned = account?.vacBanned || (account?.gameBans && account.gameBans > 0);
|
||||
const isShared = account?._id.startsWith('shared_');
|
||||
|
||||
return (
|
||||
<TableRow sx={{ '&:hover': { background: 'action.hover' }, borderBottom: '1px solid', borderColor: 'divider' }}>
|
||||
<TableCell>
|
||||
<Box sx={{ position: 'relative' }}>
|
||||
<Avatar src={imgSrc} variant="square" sx={{ width: 32, height: 32, border: '1px solid', borderColor: 'divider' }} />
|
||||
{isShared && (
|
||||
<Tooltip title="Community Shared Account">
|
||||
<PeopleIcon sx={{ position: 'absolute', bottom: -4, right: -4, fontSize: 14, color: 'primary.main', bgcolor: 'background.default', borderRadius: '50%', border: '1px solid', borderColor: 'divider', p: 0.2 }} />
|
||||
</Tooltip>
|
||||
)}
|
||||
</Box>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Typography variant="body2" sx={{ fontWeight: 'bold', color: isBanned ? 'error.main' : 'text.primary' }}>
|
||||
{account?.personaName || 'Unknown'}
|
||||
</Typography>
|
||||
<Typography variant="caption" sx={{ color: 'text.secondary', display: 'block' }}>{account?.steamId}</Typography>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{isBanned ? (
|
||||
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 0.5 }}>
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 0.5, color: 'error.main' }}>
|
||||
<GppBadIcon sx={{ fontSize: 16 }} />
|
||||
<Typography variant="caption" sx={{ fontWeight: 'bold', letterSpacing: '0.5px' }}>ACCOUNT BANNED</Typography>
|
||||
</Box>
|
||||
<Box sx={{ display: 'flex', gap: 0.5 }}>
|
||||
{account?.vacBanned && (
|
||||
<Chip label="VAC" size="small" sx={{ height: 16, fontSize: '0.6rem', bgcolor: 'error.main', color: 'white', fontWeight: 'bold', borderRadius: 0.5 }} />
|
||||
)}
|
||||
{account?.gameBans ? account.gameBans > 0 && (
|
||||
<Chip label={`${account.gameBans} GAME`} size="small" sx={{ height: 16, fontSize: '0.6rem', bgcolor: 'error.main', color: 'white', fontWeight: 'bold', borderRadius: 0.5 }} />
|
||||
) : null}
|
||||
</Box>
|
||||
</Box>
|
||||
) : (
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 0.5, color: 'success.main' }}>
|
||||
<ShieldIcon sx={{ fontSize: 16 }} />
|
||||
<Typography variant="caption" sx={{ fontWeight: 'bold', letterSpacing: '0.5px' }}>SECURE</Typography>
|
||||
</Box>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{account?.authError ? (
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', color: 'warning.main', gap: 0.5 }}>
|
||||
<LockResetIcon sx={{ fontSize: 16 }} />
|
||||
<Typography variant="body2" sx={{ fontWeight: 'bold' }}>Needs Re-auth</Typography>
|
||||
</Box>
|
||||
) : isCooldownActive ? (
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', color: 'primary.main', gap: 0.5 }}>
|
||||
<TimerIcon sx={{ fontSize: 16 }} />
|
||||
<Typography variant="body2" sx={{ fontWeight: 'bold' }}>{timeLeft}</Typography>
|
||||
</Box>
|
||||
) : (
|
||||
<Typography variant="caption" sx={{ color: 'text.secondary' }}>Available</Typography>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<Box sx={{ display: 'flex', justifyContent: 'flex-end', gap: 0.5 }}>
|
||||
{account?.steamLoginSecure ? (
|
||||
<Button
|
||||
variant="contained" size="small" onClick={() => onSwitch(account.loginName || '')}
|
||||
sx={{ height: 28, fontSize: '0.7rem', bgcolor: 'secondary.main', '&:hover': { opacity: 0.9 } }}
|
||||
>
|
||||
LOGIN
|
||||
</Button>
|
||||
) : (
|
||||
<Button variant="outlined" size="small" onClick={onAuth} sx={{ height: 28, fontSize: '0.7rem' }}>AUTH</Button>
|
||||
)}
|
||||
<IconButton size="small" onClick={handleOpenShare} disabled={!serverConfig?.token}><ShareIcon fontSize="inherit" sx={{ color: 'primary.main' }}/></IconButton>
|
||||
<IconButton size="small" sx={{ color: 'text.secondary' }} onClick={() => (window as any).electronAPI.openExternal(account?.profileUrl || '')}><OpenInNewIcon fontSize="inherit"/></IconButton>
|
||||
<IconButton size="small" sx={{ color: 'error.main' }} onClick={() => onDelete(account?._id || '')}><DeleteIcon fontSize="inherit"/></IconButton>
|
||||
</Box>
|
||||
|
||||
{/* Share Dialog */}
|
||||
<Dialog open={isShareOpen} onClose={() => setIsShareOpen(false)} maxWidth="xs" fullWidth>
|
||||
<DialogTitle sx={{ backgroundColor: 'background.paper', color: 'text.primary' }}>Share Account</DialogTitle>
|
||||
<DialogContent sx={{ backgroundColor: 'background.paper', pt: 2 }}>
|
||||
<Typography variant="body2" sx={{ mb: 2 }}>
|
||||
Select a community member to share this account with.
|
||||
</Typography>
|
||||
<FormControl fullWidth size="small" sx={{ mt: 1 }}>
|
||||
<InputLabel sx={{ color: 'text.secondary' }}>Select User</InputLabel>
|
||||
<Select
|
||||
value={targetUserId}
|
||||
label="Select User"
|
||||
onChange={(e) => setTargetUserId(e.target.value as string)}
|
||||
sx={{ bgcolor: 'rgba(0,0,0,0.1)', color: 'text.primary' }}
|
||||
>
|
||||
{serverUsers.map(user => (
|
||||
<MenuItem key={user.steamId} value={user.steamId}>
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
|
||||
<Avatar src={user.avatar} sx={{ width: 24, height: 24 }} />
|
||||
{user.personaName}
|
||||
</Box>
|
||||
</MenuItem>
|
||||
))}
|
||||
{serverUsers.length === 0 && <MenuItem disabled>No users found on server</MenuItem>}
|
||||
</Select>
|
||||
</FormControl>
|
||||
</DialogContent>
|
||||
<DialogActions sx={{ backgroundColor: 'background.paper', p: 2 }}>
|
||||
<Button onClick={() => setIsShareOpen(false)} color="inherit" disabled={isSharing}>Cancel</Button>
|
||||
<Button
|
||||
onClick={handleShare}
|
||||
variant="contained"
|
||||
startIcon={isSharing ? <CircularProgress size={16} color="inherit" /> : <GroupAddIcon />}
|
||||
disabled={!targetUserId || isSharing}
|
||||
>
|
||||
{isSharing ? "Sharing..." : "Grant Access"}
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
};
|
||||
|
||||
export default Dashboard;
|
||||
84
frontend/src/pages/LoginPage.tsx
Normal file
84
frontend/src/pages/LoginPage.tsx
Normal file
@@ -0,0 +1,84 @@
|
||||
import React from 'react';
|
||||
import { Box, Button, Typography, Container, Paper } from '@mui/material';
|
||||
import SteamIcon from '@mui/icons-material/SportsEsports';
|
||||
|
||||
const LoginPage: React.FC = () => {
|
||||
const handleSteamLogin = () => {
|
||||
const apiUrl = import.meta.env.VITE_API_URL || 'http://localhost:3001';
|
||||
window.location.href = `${apiUrl}/api/auth/steam`;
|
||||
};
|
||||
|
||||
return (
|
||||
<Box sx={{
|
||||
minHeight: '100vh',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
backgroundColor: 'background.default',
|
||||
position: 'relative',
|
||||
overflow: 'hidden',
|
||||
p: 2
|
||||
}}>
|
||||
{/* Background Glow */}
|
||||
<Box sx={{
|
||||
position: 'absolute',
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
height: '40vh',
|
||||
background: (theme) => `radial-gradient(circle at 50% 0%, ${theme.palette.primary.main}22 0%, transparent 70%)`,
|
||||
zIndex: 0
|
||||
}} />
|
||||
|
||||
<Container maxWidth="xs" sx={{ position: 'relative', zIndex: 1 }}>
|
||||
<Paper elevation={24} sx={{
|
||||
p: 5,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
alignItems: 'center',
|
||||
gap: 3,
|
||||
backgroundColor: 'background.paper',
|
||||
backdropFilter: 'blur(10px)',
|
||||
border: '1px solid',
|
||||
borderColor: 'divider',
|
||||
borderRadius: 2
|
||||
}}>
|
||||
<SteamIcon sx={{ fontSize: 64, color: 'primary.main' }} />
|
||||
|
||||
<Typography variant="h4" component="h1" align="center" sx={{ fontWeight: 'bold', letterSpacing: '1px', color: 'text.primary' }}>
|
||||
ULTIMATE BAN TRACKER
|
||||
</Typography>
|
||||
|
||||
<Typography variant="body1" align="center" sx={{ color: 'text.secondary' }}>
|
||||
Sign in with Steam to access your community dashboard and start tracking.
|
||||
</Typography>
|
||||
|
||||
<Button
|
||||
fullWidth
|
||||
variant="contained"
|
||||
size="large"
|
||||
startIcon={<SteamIcon />}
|
||||
onClick={handleSteamLogin}
|
||||
sx={{
|
||||
height: 56,
|
||||
fontSize: '1.1rem',
|
||||
fontWeight: 'bold',
|
||||
background: (theme) => `linear-gradient(to bottom, ${theme.palette.primary.main} 0%, ${theme.palette.primary.dark} 100%)`,
|
||||
'&:hover': {
|
||||
filter: 'brightness(1.1)'
|
||||
}
|
||||
}}
|
||||
>
|
||||
Sign in through STEAM
|
||||
</Button>
|
||||
|
||||
<Typography variant="caption" align="center" sx={{ color: 'text.secondary', opacity: 0.7 }}>
|
||||
We only use your Steam ID for identification. Your credentials remain private and secure.
|
||||
</Typography>
|
||||
</Paper>
|
||||
</Container>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
export default LoginPage;
|
||||
90
frontend/src/theme/SteamTheme.ts
Normal file
90
frontend/src/theme/SteamTheme.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
import { createTheme } from '@mui/material/styles';
|
||||
import type { ThemeOptions } from '@mui/material/styles';
|
||||
|
||||
export type ThemeType = 'steam' | 'mocha' | 'latte' | 'nord' | 'tokyo';
|
||||
|
||||
const commonSettings: ThemeOptions = {
|
||||
typography: {
|
||||
fontFamily: '"Motiva Sans", "Roboto", "Helvetica", "Arial", sans-serif',
|
||||
h6: { fontWeight: 700, letterSpacing: '0.5px' },
|
||||
button: { textTransform: 'none', fontWeight: 600 },
|
||||
},
|
||||
shape: { borderRadius: 4 },
|
||||
components: {
|
||||
MuiButton: {
|
||||
styleOverrides: {
|
||||
root: { borderRadius: 2, boxShadow: 'none', '&:hover': { boxShadow: 'none' } },
|
||||
},
|
||||
},
|
||||
MuiPaper: {
|
||||
styleOverrides: {
|
||||
root: { backgroundImage: 'none' },
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const themes: Record<ThemeType, ThemeOptions> = {
|
||||
steam: {
|
||||
...commonSettings,
|
||||
palette: {
|
||||
mode: 'dark',
|
||||
primary: { main: '#66c0f4', dark: '#1a9fff' },
|
||||
secondary: { main: '#4c6b22', dark: '#3d541b' },
|
||||
background: { default: '#171a21', paper: '#1b2838' },
|
||||
text: { primary: '#ffffff', secondary: '#8f98a0' },
|
||||
success: { main: '#a3cf06' },
|
||||
error: { main: '#ff4c4c' },
|
||||
},
|
||||
},
|
||||
mocha: {
|
||||
...commonSettings,
|
||||
palette: {
|
||||
mode: 'dark',
|
||||
primary: { main: '#89b4fa', dark: '#74c7ec' },
|
||||
secondary: { main: '#a6e3a1', dark: '#94e2d5' },
|
||||
background: { default: '#11111b', paper: '#1e1e2e' },
|
||||
text: { primary: '#cdd6f4', secondary: '#9399b2' },
|
||||
success: { main: '#a6e3a1' },
|
||||
error: { main: '#f38ba8' },
|
||||
},
|
||||
},
|
||||
latte: {
|
||||
...commonSettings,
|
||||
palette: {
|
||||
mode: 'light',
|
||||
primary: { main: '#1e66f5', dark: '#179299' },
|
||||
secondary: { main: '#40a02b', dark: '#40a02b' },
|
||||
background: { default: '#eff1f5', paper: '#e6e9ef' },
|
||||
text: { primary: '#4c4f69', secondary: '#6c6f85' },
|
||||
success: { main: '#40a02b' },
|
||||
error: { main: '#d20f39' },
|
||||
},
|
||||
},
|
||||
nord: {
|
||||
...commonSettings,
|
||||
palette: {
|
||||
mode: 'dark',
|
||||
primary: { main: '#88c0d0', dark: '#81a1c1' },
|
||||
secondary: { main: '#a3be8c', dark: '#8fbcbb' },
|
||||
background: { default: '#2e3440', paper: '#3b4252' },
|
||||
text: { primary: '#eceff4', secondary: '#d8dee9' },
|
||||
success: { main: '#a3be8c' },
|
||||
error: { main: '#bf616a' },
|
||||
},
|
||||
},
|
||||
tokyo: {
|
||||
...commonSettings,
|
||||
palette: {
|
||||
mode: 'dark',
|
||||
primary: { main: '#7aa2f7', dark: '#3d59a1' },
|
||||
secondary: { main: '#9ece6a', dark: '#73daca' },
|
||||
background: { default: '#1a1b26', paper: '#24283b' },
|
||||
text: { primary: '#c0caf5', secondary: '#9aa5ce' },
|
||||
success: { main: '#9ece6a' },
|
||||
error: { main: '#f7768e' },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const getTheme = (type: ThemeType) => createTheme(themes[type]);
|
||||
52
frontend/src/theme/ThemeContext.tsx
Normal file
52
frontend/src/theme/ThemeContext.tsx
Normal file
@@ -0,0 +1,52 @@
|
||||
import React, { createContext, useContext, useState, useEffect, useMemo } from 'react';
|
||||
import { ThemeProvider, CssBaseline } from '@mui/material';
|
||||
import { getTheme } from './SteamTheme';
|
||||
import type { ThemeType } from './SteamTheme';
|
||||
|
||||
interface ThemeContextType {
|
||||
currentTheme: ThemeType;
|
||||
setTheme: (theme: ThemeType) => void;
|
||||
}
|
||||
|
||||
const ThemeContext = createContext<ThemeContextType | undefined>(undefined);
|
||||
|
||||
export const AppThemeProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||
const [currentTheme, setCurrentTheme] = useState<ThemeType>('steam');
|
||||
|
||||
useEffect(() => {
|
||||
// Load theme from store on startup
|
||||
const loadTheme = async () => {
|
||||
const api = (window as any).electronAPI;
|
||||
if (api?.getServerConfig) {
|
||||
const config = await api.getServerConfig();
|
||||
if (config?.theme) setCurrentTheme(config.theme);
|
||||
}
|
||||
};
|
||||
loadTheme();
|
||||
}, []);
|
||||
|
||||
const setTheme = async (theme: ThemeType) => {
|
||||
setCurrentTheme(theme);
|
||||
const api = (window as any).electronAPI;
|
||||
if (api?.updateServerConfig) {
|
||||
await api.updateServerConfig({ theme });
|
||||
}
|
||||
};
|
||||
|
||||
const theme = useMemo(() => getTheme(currentTheme), [currentTheme]);
|
||||
|
||||
return (
|
||||
<ThemeContext.Provider value={{ currentTheme, setTheme }}>
|
||||
<ThemeProvider theme={theme}>
|
||||
<CssBaseline />
|
||||
{children}
|
||||
</ThemeProvider>
|
||||
</ThemeContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useAppTheme = () => {
|
||||
const context = useContext(ThemeContext);
|
||||
if (!context) throw new Error('useAppTheme must be used within AppThemeProvider');
|
||||
return context;
|
||||
};
|
||||
Reference in New Issue
Block a user