6d25a499b2
BREAKING CHANGE: Replaced all direct useNavigate() usage with HandleNavigate hook
## Summary
- Complete frontend navigation refactoring
- Centralized route management with routes.js
- Converted 18+ components to use HandleNavigate
- Enhanced navigation with 20+ type-safe functions
## New Files
- src/utils/routes.js - Central route constants and helpers
- Documentations/FRONTEND_CODING_GUIDELINES.md - Frontend best practices (300+ lines)
- Documentations/NAVIGATION_REFACTORING_REPORT.md - Detailed refactoring report (400+ lines)
## Modified Components (18+)
### Pages
- Home.jsx, LoginForm.jsx, RegisterForm.jsx
- ResetPassword.jsx, VerifyEmailPage.jsx
- DeckCreator.jsx, Card_display.jsx
- Lobby.jsx, GameTest.jsx, ChooseDeck.jsx, PlayerSetup.jsx
- Landingpage.jsx
### Components
- Userdetails.jsx, DeckInfoPopUp.jsx
- PlayMenu.jsx, LandingPage.jsx, DeckManager.jsx
### Hooks
- useRequireAuth.jsx
### Core
- App.jsx - Route constants integration
- HandleNavigate.jsx - Enhanced with 20+ navigation functions
## Key Improvements
Type-safe navigation (goDeckDetails(id) vs navigate('/deck/'+id))
Automatic scroll management
Centralized state passing
Single source of truth for routes
Backwards compatibility aliases
Zero compile errors
Production ready
## Validation
- useNavigate: Only in HandleNavigate.jsx
- navigate() calls: 0 direct usage
- Compile errors: 0
- Documentation: Complete
98 lines
3.2 KiB
React
98 lines
3.2 KiB
React
// src/pages/Home/Home.jsx
|
|
// Régi PlayMenu-s oldal, "Home" néven
|
|
|
|
import { useEffect, useState } from "react"
|
|
import useRequireAuth from "../../hooks/useRequireAuth"
|
|
import HandleNavigate from "../../utils/HandleNavigate/HandleNavigate"
|
|
import Navbar from "../../components/Navbar/Navbar"
|
|
import Footer from "../../components/Footer/Footer.jsx"
|
|
import Background from "../../assets/backgrounds/Background.jsx"
|
|
import PlayMenu from "../../components/Landingpage/PlayMenu.jsx"
|
|
import { joinGame } from "../../api/gameApi.js"
|
|
|
|
export default function Home() {
|
|
const { goLogin, goLobby, goChooseDeck } = HandleNavigate()
|
|
// a hook inicializálja a user-t a localStorage-ból és visszaadja a state-et + settert
|
|
const [user, setUser] = useRequireAuth({ redirect: false }) // no redirect on unauthenticated visitors
|
|
const [isJoining, setIsJoining] = useState(false)
|
|
|
|
// Join game handler - csatlakozás játékhoz kóddal
|
|
const handleJoinGame = async (code) => {
|
|
if (!user) {
|
|
alert('Kérlek először jelentkezz be!')
|
|
goLogin()
|
|
return
|
|
}
|
|
|
|
console.log('=== JOIN GAME DEBUG ===')
|
|
console.log('Current user:', user)
|
|
console.log('Game code:', code)
|
|
console.log('LocalStorage username:', localStorage.getItem('username'))
|
|
console.log('LocalStorage authLevel:', localStorage.getItem('authLevel'))
|
|
console.log('======================')
|
|
|
|
setIsJoining(true)
|
|
try {
|
|
const joinData = {
|
|
gameCode: code.toUpperCase(),
|
|
playerName: user || 'Player',
|
|
}
|
|
|
|
console.log('Sending join request with:', joinData)
|
|
const response = await joinGame(joinData)
|
|
console.log('Joined game:', response)
|
|
|
|
// Backend returns game object directly
|
|
if (response.gameToken) {
|
|
localStorage.setItem('gameToken', response.gameToken)
|
|
}
|
|
|
|
goLobby({ gameCode: code.toUpperCase() })
|
|
} catch (err) {
|
|
const errorMsg = err.response?.data?.error || err.response?.data?.message || 'Nem sikerült csatlakozni a játékhoz'
|
|
alert(errorMsg)
|
|
console.error('Join game error:', err)
|
|
console.error('Error details:', err.response?.data)
|
|
} finally {
|
|
setIsJoining(false)
|
|
}
|
|
}
|
|
|
|
// Create game handler - új játék létrehozása
|
|
const handleCreateGame = () => {
|
|
if (!user) {
|
|
alert('Kérlek először jelentkezz be!')
|
|
goLogin()
|
|
return
|
|
}
|
|
|
|
// Navigate to choose deck page to start game creation flow
|
|
goChooseDeck()
|
|
}
|
|
|
|
const userObj = { name: user }
|
|
|
|
// ha szükséges a user módosítása máshol: setUser("újnév") automatikusan menti localStorage-be
|
|
|
|
return (
|
|
<div className="w-full min-h-screen flex flex-col relative overflow-x-hidden">
|
|
<div className="fixed inset-0 -z-10 pointer-events-none">
|
|
<Background />
|
|
</div>
|
|
<div className="fixed top-0 left-0 right-0 z-30">
|
|
<Navbar />
|
|
</div>
|
|
<main className="flex-1 min-h-[calc(100vh-64px)] flex mt-[64px] flex-col items-center justify-center px-2 sm:px-4">
|
|
<PlayMenu
|
|
onJoinGame={handleJoinGame}
|
|
onCreateGame={handleCreateGame}
|
|
user={userObj}
|
|
setUser={setUser}
|
|
/>
|
|
{/* Ide jöhetnek további szekciók, ha szeretnél még tartalmat */}
|
|
</main>
|
|
<Footer />
|
|
</div>
|
|
)
|
|
}
|