Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/polyblitz/backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ app.use("/api", apiRouter);

const defaultPort = 4590;
const port = process.env.BACKEND_PORT ?? defaultPort;

app.use("/Users", userRouter);
app.use("/Bet", betRouter);
app.use("/LeaderBoard", leaderBoardRouter);
Expand All @@ -58,7 +59,6 @@ async function startServer() {
console.log(`Backend listening on port ${port}`);
});
}

startServer().catch((error: unknown) => {
console.error("Backend failed to start:", error);
process.exitCode = 1;
Expand Down
2 changes: 2 additions & 0 deletions apps/polyblitz/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { PublicUser, Bet } from "@repo/polyblitz-types";
import { BetsPage } from "./pages/components/Bets";
import axios from "axios";
import { AddBet } from "./pages/AddBetPage";
import { Enter } from "./enter";

export const BackendURL = "http://localhost:4590";

Expand All @@ -27,6 +28,7 @@ const App: FC = () => {
<BetsPage user={user} bets={bets} />
<AddUser onSignUp={setUser} />
<Login onLogin={setUser} />
<Enter />
<AddBet />
{user && <p>welcome to polyblitz: {user.name}</p>}
</>
Expand Down
82 changes: 82 additions & 0 deletions apps/polyblitz/frontend/src/enter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { useState, useEffect } from "react";
import type { Bet } from "@repo/polyblitz-types";
import axios from "axios";

export function Enter() {
const [selectedOptions, setSelectedOptions] = useState<
Record<number, string>
>({});

const [bets, setBets] = useState<Bet[]>([]);

async function postBets(betId: number, option: string) {
try {
const response = await axios.post(
`http://localhost:4590/api/bets/${betId}/wagers`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the BackendURL in the App.tsx, also it's the wrong url, it's supposed to be https://localhost:4590/admin/bets/:id/resolve

{
userID: 2,
amountWagered: 10,
Comment on lines +17 to +18

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this, and no need for it to be in a json, please change this

option: option,
},
);

console.log(response.data);
} catch (error) {
console.error("Failed to place wager:", error);
}
}

async function getBets() {
try {
const response = await axios.get<Bet[]>("http://localhost:4590/Bet/bets");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here use the backendurl


setBets(response.data);
console.log(response.data);
} catch (error) {
console.error("Failed to get bets:", error);
}
}

useEffect(() => {
getBets();
}, []);

return (
<div>
<h1>Pending questions</h1>

{bets.map((bet) => (
<div key={bet.id}>
<h2>{bet.title}</h2>
<p>{bet.description}</p>

<button
onClick={() => {
setSelectedOptions({
...selectedOptions,
[bet.id]: "optionOne",
});

postBets(bet.id, "optionOne");
}}
>
{bet.optionOne.title}
</button>

<button
onClick={() => {
setSelectedOptions({
...selectedOptions,
[bet.id]: "optionTwo",
});

postBets(bet.id, "optionTwo");
}}
>
{bet.optionTwo.title}
</button>
</div>
))}
</div>
);
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"dependencies": {
"@hello-pangea/dnd": "^18.0.1",
"@radix-ui/react-slider": "^1.3.6",
"@repo/polyblitz-types": "0.0.0",
"@tailwindcss/vite": "^4.2.0",
"@tanstack/react-table": "^8.21.3",
"@vitejs/plugin-react": "^5.1.4",
Expand All @@ -50,7 +51,7 @@
"tailwindcss": "^4.2.0",
"tsx": "^4.21.0",
"usehooks-ts": "^3.1.1",
"@repo/polyblitz-types": "0.0.0"
"zod": "^4.6.7"
},
"devDependencies": {
"@dotenv-run/cli": "^1.3.6",
Expand Down
Loading