rename "get" util functions to "fetch"
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import GameAuthWrapper from "@/components/game/GameAuthWrapper";
|
import GameAuthWrapper from "@/components/game/GameAuthWrapper";
|
||||||
import { getActiveGame } from "@/lib/game";
|
import { fetchActiveGame } from "@/lib/game";
|
||||||
import { notFound } from "next/navigation";
|
import { notFound } from "next/navigation";
|
||||||
|
|
||||||
export async function generateMetadata({ params }: { params: { code: string } }) {
|
export async function generateMetadata({ params }: { params: { code: string } }) {
|
||||||
const game = await getActiveGame(params.code);
|
const game = await fetchActiveGame(params.code);
|
||||||
if (!game) {
|
if (!game) {
|
||||||
return {
|
return {
|
||||||
description: "Game not found",
|
description: "Game not found",
|
||||||
@@ -35,7 +35,7 @@ export async function generateMetadata({ params }: { params: { code: string } })
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default async function Game({ params }: { params: { code: string } }) {
|
export default async function Game({ params }: { params: { code: string } }) {
|
||||||
const game = await getActiveGame(params.code);
|
const game = await fetchActiveGame(params.code);
|
||||||
if (!game) {
|
if (!game) {
|
||||||
notFound();
|
notFound();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import ArchivedGame from "@/components/archive/ArchivedGame";
|
import ArchivedGame from "@/components/archive/ArchivedGame";
|
||||||
import { getArchivedGame } from "@/lib/game";
|
import { fetchArchivedGame } from "@/lib/game";
|
||||||
import type { Game } from "@chessu/types";
|
import type { Game } from "@chessu/types";
|
||||||
import { notFound } from "next/navigation";
|
import { notFound } from "next/navigation";
|
||||||
|
|
||||||
export async function generateMetadata({ params }: { params: { id: number } }) {
|
export async function generateMetadata({ params }: { params: { id: number } }) {
|
||||||
const game = (await getArchivedGame({ id: params.id })) as Game | undefined;
|
const game = (await fetchArchivedGame({ id: params.id })) as Game | undefined;
|
||||||
if (!game) {
|
if (!game) {
|
||||||
return {
|
return {
|
||||||
description: "Game not found",
|
description: "Game not found",
|
||||||
@@ -36,7 +36,7 @@ export async function generateMetadata({ params }: { params: { id: number } }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default async function Archive({ params }: { params: { id: number } }) {
|
export default async function Archive({ params }: { params: { id: number } }) {
|
||||||
const game = (await getArchivedGame({ id: params.id })) as Game | undefined;
|
const game = (await fetchArchivedGame({ id: params.id })) as Game | undefined;
|
||||||
if (!game) {
|
if (!game) {
|
||||||
notFound();
|
notFound();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import type { FormEvent } from "react";
|
import type { FormEvent } from "react";
|
||||||
import { useState, useContext } from "react";
|
import { useState, useContext } from "react";
|
||||||
import { SessionContext } from "@/context/session";
|
import { SessionContext } from "@/context/session";
|
||||||
import { getActiveGame } from "@/lib/game";
|
import { fetchActiveGame } from "@/lib/game";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
export default function JoinGame() {
|
export default function JoinGame() {
|
||||||
@@ -31,7 +31,7 @@ export default function JoinGame() {
|
|||||||
code = new URL(code).pathname.split("/")[1];
|
code = new URL(code).pathname.split("/")[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
const game = await getActiveGame(code);
|
const game = await fetchActiveGame(code);
|
||||||
|
|
||||||
if (game && game.code) {
|
if (game && game.code) {
|
||||||
router.push(`/${game.code}`);
|
router.push(`/${game.code}`);
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { getPublicGames } from "@/lib/game";
|
import { fetchPublicGames } from "@/lib/game";
|
||||||
import JoinButton from "./JoinButton";
|
import JoinButton from "./JoinButton";
|
||||||
import RefreshButton from "./RefreshButton";
|
import RefreshButton from "./RefreshButton";
|
||||||
|
|
||||||
export default async function PublicGames() {
|
export default async function PublicGames() {
|
||||||
const games = await getPublicGames();
|
const games = await fetchPublicGames();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-center">
|
<div className="flex flex-col items-center">
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export const createGame = async (side: string, unlisted: boolean) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getActiveGame = async (code: string) => {
|
export const fetchActiveGame = async (code: string) => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/v1/games/${code}`, { cache: "no-store" });
|
const res = await fetch(`${API_URL}/v1/games/${code}`, { cache: "no-store" });
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ export const getActiveGame = async (code: string) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getPublicGames = async () => {
|
export const fetchPublicGames = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/v1/games`, { cache: "no-store" });
|
const res = await fetch(`${API_URL}/v1/games`, { cache: "no-store" });
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ export const getPublicGames = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getArchivedGame = async ({ id, userid }: { id?: number; userid?: number }) => {
|
export const fetchArchivedGame = async ({ id, userid }: { id?: number; userid?: number }) => {
|
||||||
let url = `${API_URL}/v1/games?`;
|
let url = `${API_URL}/v1/games?`;
|
||||||
if (id) {
|
if (id) {
|
||||||
url += `id=${id}`;
|
url += `id=${id}`;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { API_URL } from "@/config";
|
import { API_URL } from "@/config";
|
||||||
import type { User, Game } from "@chessu/types";
|
import type { User, Game } from "@chessu/types";
|
||||||
|
|
||||||
export const getProfileData = async (name: string) => {
|
export const fetchProfileData = async (name: string) => {
|
||||||
try {
|
try {
|
||||||
// TODO: handle caching more efficiently?
|
// TODO: handle caching more efficiently?
|
||||||
const res = await fetch(`${API_URL}/v1/users/${name}`, {
|
const res = await fetch(`${API_URL}/v1/users/${name}`, {
|
||||||
|
|||||||
Reference in New Issue
Block a user