|
@@ -2,7 +2,7 @@ import { API_BASE } from "../config";
|
|
|
|
|
|
export const getStatus = async () => {
|
|
|
try {
|
|
|
- const res = await fetch(API_BASE + "/");
|
|
|
+ const res = await fetch(API_BASE);
|
|
|
if (!res.ok) {
|
|
|
throw Error(res.statusText);
|
|
|
}
|
|
@@ -13,7 +13,7 @@ export const getStatus = async () => {
|
|
|
}
|
|
|
|
|
|
export const createGame = async (name, timer) => {
|
|
|
- const res = await fetch(API_BASE + "/game", {
|
|
|
+ const res = await fetch(`${API_BASE}/game`, {
|
|
|
method: "PUT",
|
|
|
headers: {
|
|
|
"Authorization": `Name ${name}`,
|
|
@@ -29,7 +29,7 @@ export const createGame = async (name, timer) => {
|
|
|
}
|
|
|
|
|
|
export const gameInfo = async (gameId) => {
|
|
|
- const res = await fetch(API_BASE + `/game/${gameId}`);
|
|
|
+ const res = await fetch(`${API_BASE}/game/${gameId}`);
|
|
|
if (!res.ok) {
|
|
|
throw Error(res.statusText);
|
|
|
}
|
|
@@ -37,7 +37,7 @@ export const gameInfo = async (gameId) => {
|
|
|
}
|
|
|
|
|
|
export const joinGame = async (gameId, name) => {
|
|
|
- const res = await fetch(API_BASE + `/game/${gameId}/join`, {
|
|
|
+ const res = await fetch(`${API_BASE}/game/${gameId}/join`, {
|
|
|
method: "POST",
|
|
|
headers: {
|
|
|
"Authorization": `Name ${name}`
|
|
@@ -49,7 +49,7 @@ export const joinGame = async (gameId, name) => {
|
|
|
}
|
|
|
|
|
|
export const getGuesses = async (gameId, name) => {
|
|
|
- const res = await fetch(API_BASE + `/game/${gameId}/guesses`, {
|
|
|
+ const res = await fetch(`${API_BASE}/game/${gameId}/guesses`, {
|
|
|
headers: {
|
|
|
"Authorization": `Name ${name}`
|
|
|
},
|
|
@@ -59,3 +59,19 @@ export const getGuesses = async (gameId, name) => {
|
|
|
}
|
|
|
return await res.json();
|
|
|
}
|
|
|
+
|
|
|
+export const sendGuess = async (gameId, name, round, lat, lng) => {
|
|
|
+ const res = await fetch(`${API_BASE}/game/${gameId}/guesses/${round}`, {
|
|
|
+ method: "POST",
|
|
|
+ headers: {
|
|
|
+ "Authorization": `Name ${name}`,
|
|
|
+ "Content-Type": "application/json",
|
|
|
+ },
|
|
|
+ body: JSON.stringify({ lat, lng }),
|
|
|
+ });
|
|
|
+ if (!res.ok) {
|
|
|
+ throw Error(res.statusText);
|
|
|
+ }
|
|
|
+ const { score } = await res.json();
|
|
|
+ return score;
|
|
|
+}
|