Skip to content

Commit 7eb58b0

Browse files
committed
fixed firebase problem and added match making
1 parent c3afa76 commit 7eb58b0

File tree

17 files changed

+2235
-24
lines changed

17 files changed

+2235
-24
lines changed

src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import { Route, Routes } from "react-router-dom";
22
import Home from "./components/Home";
33
import MultiplayerRoom from "./components/MultiplayerRoom";
44
import { SinglePlayerRoom } from "./singleplayer";
5+
import { MultiplayerRoom as MatchmakingRoom } from "./multiplayer/matchmaking";
56

67
function App() {
78
return (
89
<Routes>
910
<Route path="/" element={<Home />} />
1011
<Route path="/room/:roomId" element={<MultiplayerRoom />} />
1112
<Route path="/room" element={<SinglePlayerRoom />} />
13+
<Route path="/multiplayer/:roomId" element={<MatchmakingRoom />} />
1214
</Routes>
1315
);
1416
}

src/components/Home.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ import OnlineLobbyDialog from "./OnlineLobby";
77
import { useGameStore } from "../store/gameStore";
88
import { handleOnlinePlay } from "../services/gameService";
99
import SinglePlayerRoomConfigDialog from "../singleplayer/components/SinglePlayerRoomConfigDialog";
10+
import { MatchmakingLobby } from "../multiplayer/matchmaking";
11+
import { Dialog } from "./ui";
1012
import { useState } from "react";
13+
import { loginWithGoogle } from "../services/firebase";
1114

1215
export default function Home() {
1316
const navigate = useNavigate();
1417
const { user } = useAuth();
1518

1619
const [isDialogOpen, setIsDialogOpen] = useState(false);
20+
const [isQuickMatchOpen, setIsQuickMatchOpen] = useState(false);
1721

1822
const { isOnlineDialogOpen, isOnboarded, setIsOnlineDialogOpen } =
1923
useGameStore();
@@ -26,6 +30,18 @@ export default function Home() {
2630
handleOnlinePlay(user);
2731
};
2832

33+
const handleQuickMatchClick = async () => {
34+
if (!user) {
35+
const { user: newUser } = await loginWithGoogle();
36+
if (newUser) {
37+
setIsQuickMatchOpen(true);
38+
} else {
39+
// Login failed
40+
}
41+
}
42+
setIsQuickMatchOpen(true);
43+
};
44+
2945
const handleConfirm = () => {
3046
setIsDialogOpen(false);
3147
navigate("/room");
@@ -84,7 +100,10 @@ export default function Home() {
84100
<Button variant="blue" onClick={handlePlayClick}>
85101
Play
86102
</Button>
87-
<Button onClick={handleOnlinePlayClick}>Online</Button>
103+
<Button variant="green" onClick={handleQuickMatchClick}>
104+
Quick Match
105+
</Button>
106+
<Button onClick={handleOnlinePlayClick}>Online Rooms</Button>
88107
</div>
89108

90109
<SinglePlayerRoomConfigDialog
@@ -98,6 +117,14 @@ export default function Home() {
98117
isOpen={isOnlineDialogOpen}
99118
onClose={() => setIsOnlineDialogOpen(false)}
100119
/>
120+
121+
<Dialog
122+
isOpen={isQuickMatchOpen}
123+
onClose={() => setIsQuickMatchOpen(false)}
124+
title="Quick Match"
125+
>
126+
<MatchmakingLobby onClose={() => setIsQuickMatchOpen(false)} />
127+
</Dialog>
101128
</div>
102129
);
103130
}

src/lib/firebase.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { getFirestore } from "firebase/firestore";
33
import { getAuth } from "firebase/auth";
44

55
const firebaseConfig = {
6-
apiKey: import.meta.env.VITE_FIREBASE_API_KEY,
7-
authDomain: import.meta.env.VITE_FIREBASE_AUTH_DOMAIN,
8-
projectId: import.meta.env.VITE_FIREBASE_PROJECT_ID,
9-
storageBucket: import.meta.env.VITE_FIREBASE_STORAGE_BUCKET,
10-
messagingSenderId: import.meta.env.VITE_FIREBASE_MESSAGING_SENDER_ID,
11-
appId: import.meta.env.VITE_FIREBASE_APP_ID,
6+
apiKey: "AIzaSyCFfB-OFucl6TY67X0BTMhGGEYSJu4NKXE",
7+
authDomain: "handwar-pz.firebaseapp.com",
8+
projectId: "handwar-pz",
9+
storageBucket: "handwar-pz.firebasestorage.app",
10+
messagingSenderId: "829667112715",
11+
appId: "1:829667112715:web:b276faa05ee963e99d140e",
1212
};
1313

1414
const app = initializeApp(firebaseConfig);

0 commit comments

Comments
 (0)