From 400d772cc391d979747510776fa8acfb5a1d00cb Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Sat, 5 Jul 2025 21:42:22 -0700 Subject: implement generic score viewer and import deduplication --- frontend/src/pages/Import.tsx | 200 +++++++++++++++++++++--------------------- 1 file changed, 98 insertions(+), 102 deletions(-) (limited to 'frontend/src/pages/Import.tsx') diff --git a/frontend/src/pages/Import.tsx b/frontend/src/pages/Import.tsx index efd1d03..fe2501f 100644 --- a/frontend/src/pages/Import.tsx +++ b/frontend/src/pages/Import.tsx @@ -1,40 +1,42 @@ -import { useState, useEffect } from 'react'; -import { Link, useNavigate } from 'react-router'; -import { useAuth } from '../contexts/AuthContext'; -import JsonUploadModal from '../components/modals/JsonUploadModal'; -import EamusementModal from '../components/modals/EamusementModal'; -import type { SupportedGame } from '../types/game'; -import { uploadScore } from '../utils/scoreUpload'; - - +import { useState, useEffect } from "react"; +import { useNavigate } from "react-router"; +import { useAuth } from "../contexts/AuthContext"; +import JsonUploadModal from "../components/modals/JsonUploadModal"; +import EamusementModal from "../components/modals/EamusementModal"; +import SessionExpiredPopup from "../components/SessionExpiredPopup"; +import type { SupportedGame } from "../types/game"; +import { uploadScore } from "../utils/scoreUpload"; +import { NavBar } from "../components/NavBar"; const Import = () => { const { user, isLoading, logout } = useAuth(); const navigate = useNavigate(); - const [selectedGame, setSelectedGame] = useState(''); + const [selectedGame, setSelectedGame] = useState(""); const [isJsonModalOpen, setIsJsonModalOpen] = useState(false); const [isEamusementModalOpen, setIsEamusementModalOpen] = useState(false); const [supportedGames, setSupportedGames] = useState([]); const [gamesLoading, setGamesLoading] = useState(true); const [uploadStatus, setUploadStatus] = useState<{ - type: 'success' | 'error' | null; + type: "success" | "error" | null; message: string; - }>({ type: null, message: '' }); + }>({ type: null, message: "" }); useEffect(() => { const fetchSupportedGames = async () => { try { - const response = await fetch(import.meta.env.VITE_API_URL+'/supportedGames'); + const response = await fetch( + import.meta.env.VITE_API_URL + "/supportedGames", + ); if (!response.ok) { - throw new Error('Failed to fetch supported games'); + throw new Error("Failed to fetch supported games"); } const data = await response.json(); setSupportedGames(data); } catch (error) { - console.error('Failed to fetch supported games:', error); + console.error("Failed to fetch supported games:", error); setUploadStatus({ - type: 'error', - message: 'Failed to load supported games. Please refresh the page.' + type: "error", + message: "Failed to load supported games. Please refresh the page.", }); } finally { setGamesLoading(false); @@ -47,10 +49,10 @@ const Import = () => { const handleLogout = async () => { try { await logout(); - navigate('/'); + navigate("/"); } catch (error) { - console.error('Logout failed:', error); - alert('Network error during logout. Please try again.'); + console.error("Logout failed:", error); + alert("Network error during logout. Please try again."); } }; @@ -58,30 +60,33 @@ const Import = () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const handleJsonUpload = async (data: any) => { try { - console.log('Uploading data for game:', selectedGame, data); + console.log("Uploading data for game:", selectedGame, data); const result = await uploadScore({ meta: { game: data.meta.game, service: data.meta.service, - playtype: data.meta.playtype + playtype: data.meta.playtype, }, - scores: data.scores + scores: data.scores, }); setUploadStatus({ - type: 'success', - message: `Successfully imported ${result.scoreCount} score(s) for ${supportedGames.find(g => g.internalName === data.meta.game)?.formattedName || data.meta.game}` + type: "success", + message: `Successfully imported ${result.scoreCount} score(s) for ${supportedGames.find((g) => g.internalName === data.meta.game)?.formattedName || data.meta.game}`, }); setTimeout(() => { - setUploadStatus({ type: null, message: '' }); + setUploadStatus({ type: null, message: "" }); }, 5000); } catch (error) { - console.error('Upload failed:', error); + console.error("Upload failed:", error); setUploadStatus({ - type: 'error', - message: error instanceof Error ? error.message : 'Failed to import data. Please try again.' + type: "error", + message: + error instanceof Error + ? error.message + : "Failed to import data. Please try again.", }); } }; @@ -89,8 +94,18 @@ const Import = () => { const JsonUploadCard = () => (
- - + +

Batch-Manual Upload

@@ -111,11 +126,23 @@ const Import = () => { {/* e-amusement Card */}
- - + +
-

e-amusement Play History

+

+ e-amusement Play History +

Import via scraping your playdata from KONAMI e-amusement

@@ -131,12 +158,12 @@ const Import = () => { const renderImportOptions = () => { switch (selectedGame) { - case 'dancerush': + case "dancerush": return ( <> {/* JSON Upload Card */} - + ); @@ -157,83 +184,40 @@ const Import = () => { } if (!user) { - return ( -
-
-
-

Session Expired

-

Please sign in to import your data.

-
- - Sign In - - - Back to Home - -
-
-
-
- ); + return ; } return (
{/* Navigation */} - + {/* Main Content */}
{/* Header */}

Import Data

-

Import your game scores and progress from various sources

+

+ Import your game scores and progress from various sources +

{/* Status Message */} {uploadStatus.type && ( -
-

+

+

{uploadStatus.message}

@@ -262,7 +246,11 @@ const Import = () => { > {supportedGames.map((game) => ( - ))} @@ -273,7 +261,9 @@ const Import = () => { {/* Import Options */} {selectedGame && (
-

Import Options

+

+ Import Options +

{renderImportOptions()} @@ -288,14 +278,20 @@ const Import = () => { isOpen={isJsonModalOpen} onClose={() => setIsJsonModalOpen(false)} onUpload={handleJsonUpload} - game={supportedGames.find(g => g.internalName === selectedGame)?.formattedName || ''} + game={ + supportedGames.find((g) => g.internalName === selectedGame) + ?.formattedName || "" + } /> {/* Eamusement Modal */} setIsEamusementModalOpen(false)} - game={supportedGames.find(g => g.internalName === selectedGame) || undefined} + game={ + supportedGames.find((g) => g.internalName === selectedGame) || + undefined + } />
); -- cgit v1.2.3