Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
thatguyinabeanie committed Nov 8, 2024
1 parent bdcdcf4 commit b99ebd0
Show file tree
Hide file tree
Showing 27 changed files with 519 additions and 180 deletions.
Empty file removed apps/nextjs/env.ts
Empty file.
13 changes: 12 additions & 1 deletion apps/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@
"@clerk/backend": "^1.15.1",
"@clerk/clerk-react": "^5.13.1",
"@clerk/nextjs": "^6.0.2",
"@iconify/react": "^5.0.2",
"@pkmn/sets": "^5.1.2",
"@pkmn/types": "^4.0.0",
"@rails/actioncable": "^7.2.200",
"@t3-oss/env-nextjs": "catalog:",
"@tanstack/react-query": "catalog:",
"@tanstack/react-table": "catalog:",
"@trpc/client": "catalog:",
"@trpc/react-query": "catalog:",
"@trpc/server": "catalog:",
Expand All @@ -45,22 +50,28 @@
"geist": "^1.3.1",
"jose": "^5.9.6",
"js-cookie": "^3.0.5",
"next": "^14.2.15",
"next": "catalog:",
"next-themes": "catalog:",
"openapi-fetch": "^0.13.0",
"openapi-typescript-helpers": "^0.0.15",
"react": "catalog:react18",
"react-dom": "catalog:react18",
"server-only": "^0.0.1",
"superjson": "2.2.1",
"tailwind-merge": "^2.5.4",
"tailwind-variants": "^0.2.1",
"tailwindcss-animate": "^1.0.7",
"tweetnacl": "^1.0.3",
"zod": "catalog:"
},
"devDependencies": {
"@battle-stadium/eslint-config": "workspace:*",
"@battle-stadium/prettier-config": "workspace:*",
"@battle-stadium/tailwind-config": "workspace:*",
"@battle-stadium/tsconfig": "workspace:*",
"@types/js-cookie": "^3.0.6",
"@types/node": "^20.16.11",
"@types/rails__actioncable": "^6.1.11",
"@types/react": "catalog:react18",
"@types/react-dom": "catalog:react18",
"dotenv-cli": "^7.4.2",
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/(info)/about/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Metadata } from "next";
import type {Metadata} from "next";

export const metadata: Metadata = {
title: "About Us",
Expand Down
4 changes: 2 additions & 2 deletions apps/nextjs/src/app/analytics/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { type Metadata } from "next";
import type { Metadata } from "next";

export const metadata: Metadata = {
title: "Analytics",
};

export default async function Analytics() {
export default function Analytics () {
return (
<div>
<h1>Analytics</h1>
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/dashboard/@admin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function Admin() {
endpoint="imageUploader"
onClientUploadComplete={(res) => {
// Do something with the response
console.log("Files: ", res); // eslint-disable-line no-console
console.log("Files: ", res);
// alert("Upload Completed");
}}
onUploadError={(error: Error) => {
Expand Down
6 changes: 3 additions & 3 deletions apps/nextjs/src/app/dashboard/@settings/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use client";

import { Tabs, TabsContent, TabsList, TabsTrigger } from "~/components/ui/tabs";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@battle-stadium/ui/tabs";

export default function Settings() {
export default function Settings () {
return (
<div className="border-small w-full max-w-2xl flex-col rounded-3xl border-neutral-400 border-opacity-15 p-10 backdrop-blur">
<Tabs>
Expand All @@ -22,7 +22,7 @@ export default function Settings() {
Make changes to your account here.
</TabsContent>
<TabsContent value="appearance">
{"Make changes to the site's appearance here."}
{ "Make changes to the site's appearance here." }
</TabsContent>
</Tabs>
</div>
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/dashboard/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type DashboardLayoutProps } from "~/types";
import type {DashboardLayoutProps} from "~/types";
import { getAccountMe } from "~/app/server-actions/accounts/actions";

export default async function DashboardLayout({
Expand Down
4 changes: 2 additions & 2 deletions apps/nextjs/src/app/server-actions/accounts/actions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use server";

import { BattleStadiumApiClient, defaultConfig } from "~/lib/api";
import { type paths } from "~/lib/api/openapi-v1";
import type {paths} from "~/lib/api/openapi-v1";
import { auth } from "@clerk/nextjs/server";
import { type FetchOptions } from "openapi-fetch";
import type {FetchOptions} from "openapi-fetch";

export async function getAccounts(
options?: FetchOptions<paths["/accounts"]["get"]>,
Expand Down
12 changes: 6 additions & 6 deletions apps/nextjs/src/app/server-actions/organizations/actions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use server";

import { BattleStadiumApiClient, defaultConfig } from "~/lib/api";
import { type paths } from "~/lib/api/openapi-v1";
import { type FetchOptions } from "openapi-fetch";
import type {paths} from "~/lib/api/openapi-v1";
import type {FetchOptions} from "openapi-fetch";

export async function getOrganizations(
options?: FetchOptions<paths["/organizations"]["get"]>,
Expand All @@ -12,8 +12,8 @@ export async function getOrganizations(
...options,
params: {
query: {
page: options?.params?.query?.page ?? 0,
per_page: options?.params?.query?.per_page ?? 20,
page: options?.params.query.page ?? 0,
per_page: options?.params.query.per_page ?? 20,
},
},
};
Expand All @@ -23,8 +23,8 @@ export async function getOrganizations(
await BattleStadiumApiClient(skipClerkAuth)

Check failure on line 23 in apps/nextjs/src/app/server-actions/organizations/actions.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected `await` of a non-Promise (non-"Thenable") value
).GET("/organizations", organizationsOptions);
const allOrgs = resp.data?.data;
const partnerOrgs = (allOrgs ?? [])?.filter((org) => org.partner);
const nonPartnerOrgs = (allOrgs ?? [])?.filter((org) => !org.partner);
const partnerOrgs = (allOrgs ?? []).filter((org) => org.partner);
const nonPartnerOrgs = (allOrgs ?? []).filter((org) => !org.partner);

return {
partners: partnerOrgs,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use server";

import { BattleStadiumApiClient, defaultConfig } from "~/lib/api";
import { type paths } from "~/lib/api/openapi-v1";
import { type FetchOptions } from "openapi-fetch";
import type {paths} from "~/lib/api/openapi-v1";
import type {FetchOptions} from "openapi-fetch";

export async function getOrganizationTournaments(
slug: string,
Expand Down
13 changes: 5 additions & 8 deletions apps/nextjs/src/app/server-actions/pokemon/actions.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
"use server";

import { BattleStadiumApiClient, defaultConfig } from "~/lib/api";
import { type paths } from "~/lib/api/openapi-v1";
import {
type ValidatedPokemon,
type PokePasteMetadata,
} from "~/lib/pokemon/common";
import { type FetchOptions } from "openapi-fetch";
import type {paths} from "~/lib/api/openapi-v1";
import type {ValidatedPokemon, PokePasteMetadata} from "~/lib/pokemon/common";
import type {FetchOptions} from "openapi-fetch";

type PostPokemonTeamBody = {
interface PostPokemonTeamBody {
pokepaste_id?: string;
profile_id: number | null;
name: string;
Expand All @@ -29,7 +26,7 @@ type PostPokemonTeamBody = {
move4: string | null;
pokemon_team_id?: number;
}[];
};
}

export async function getPokemonTeams(
options?: FetchOptions<paths["/pokemon_teams"]["get"]>,
Expand Down
4 changes: 2 additions & 2 deletions apps/nextjs/src/app/server-actions/profiles/actions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use server";

import { BattleStadiumApiClient, defaultConfig } from "~/lib/api";
import { type paths } from "~/lib/api/openapi-v1";
import type {paths} from "~/lib/api/openapi-v1";
import { revalidateTag } from "next/cache";
import { type FetchOptions } from "openapi-fetch";
import type {FetchOptions} from "openapi-fetch";

export async function getProfiles(
options?: FetchOptions<paths["/profiles"]["get"]>,
Expand Down
4 changes: 2 additions & 2 deletions apps/nextjs/src/app/server-actions/tournaments/actions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use server";

import { BattleStadiumApiClient, defaultConfig } from "~/lib/api";
import { type paths } from "~/lib/api/openapi-v1";
import { type FetchOptions } from "openapi-fetch";
import type {paths} from "~/lib/api/openapi-v1";
import type {FetchOptions} from "openapi-fetch";

export async function getTournament(
tournament_id: number,
Expand Down
5 changes: 5 additions & 0 deletions apps/nextjs/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ export const env = createEnv({
* This way you can ensure the app isn't built with invalid env vars.
*/
server: {
COOKIE_DOMAIN: z.string(),
PROD_API_BASE_URL: z.string().url(),
LOCAL_DEV_BACKEND_HOST: z.string().optional().default("localhost"),
LOCAL_DEV_BACKEND_PORT: z.string().optional().default("10000"),
POSTGRES_URL: z.string().url(),
WEBSOCKET_URL: z.string().optional(),
},

/**
Expand Down
13 changes: 7 additions & 6 deletions apps/nextjs/src/lib/api/client.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
import createFetchClient, { type Middleware } from "openapi-fetch";
import createFetchClient from "openapi-fetch";
import type { Middleware } from "openapi-fetch";
import { env } from "~/env.ts";
import { getVercelOidcToken } from "@vercel/functions/oidc";
import { auth } from "@clerk/nextjs/server";
import { type paths } from "~/lib/api/openapi-v1";
import type { paths } from "~/lib/api/openapi-v1";

export const DEFAULT_CACHE_TIMEOUT = 300;

export function defaultConfig(tag: string, revalidate?: number) {
export function defaultConfig (tag: string, revalidate?: number) {
return {
next: { tags: [tag], revalidate: revalidate ?? DEFAULT_CACHE_TIMEOUT },
};
}

export function getBaseUrl() {
export function getBaseUrl () {
if ([env.NODE_ENV, env.VERCEL_ENV].includes("production")) {
return `${env.PROD_API_BASE_URL}`;
}

return `http://${env.LOCAL_DEV_BACKEND_HOST}:${env.LOCAL_DEV_BACKEND_PORT}`;
}

export async function BattleStadiumApiClient(skipClerkAuth = false) {
export function BattleStadiumApiClient (skipClerkAuth = false) {
const baseUrl = `${getBaseUrl()}/api/v1`;
const fetchClient = createFetchClient<paths>({ baseUrl });
const authMiddleware: Middleware = {
async onRequest({ request }) {
async onRequest ({ request }) {
if (env.NODE_ENV !== "development") {
request.headers.set(
"X-Vercel-OIDC-Token",
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/src/lib/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type components } from "~/lib/api/openapi-v1";
import type {components} from "~/lib/api/openapi-v1";
export * from "~/lib/api/client";

export type Schemas = components["schemas"];
Expand Down
9 changes: 3 additions & 6 deletions apps/nextjs/src/lib/discord/verify-incoming-request.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import {
type APIChatInputApplicationCommandInteraction,
type APIPingInteraction,
} from "discord-api-types/v10";
import type {APIChatInputApplicationCommandInteraction, APIPingInteraction} from "discord-api-types/v10";
import nacl from "tweetnacl";

type VerifyWithNaclArgs = {
interface VerifyWithNaclArgs {
appPublicKey: string;
rawBody: string;
signature: string;
timestamp: string;
};
}

const verifyWithNacl = ({
appPublicKey,
Expand Down
4 changes: 2 additions & 2 deletions apps/nextjs/src/lib/pokemon/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type PokemonSet, type StatsTable } from "@pkmn/types";
import type {PokemonSet, StatsTable} from "@pkmn/types";

export interface OptionalStatsPokemonSet
extends Omit<PokemonSet, "evs" | "ivs"> {
Expand Down Expand Up @@ -57,7 +57,7 @@ export function cleanImageUrl(url: string): string {
url = "/" + url;
}

if (url?.startsWith("/img/pokemon/0-0.png")) {
if (url.startsWith("/img/pokemon/0-0.png")) {
return "";
}

Expand Down
24 changes: 10 additions & 14 deletions apps/nextjs/src/lib/pokemon/parse-pokepaste-html.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import {
type ParsedTeam,
type PokePasteMetadata,
type ParsedPokemon,
cleanImageUrl,
parseStats,
parseStats
} from "./common";
import type { ParsedTeam, PokePasteMetadata, ParsedPokemon } from "./common";

export function parsePokePasteHTML(html: string, url: string): ParsedTeam {
export function parsePokePasteHTML (html: string, url: string): ParsedTeam {
if (typeof window === "undefined")
return { metadata: { title: "", author: "", format: "" }, pokemon: [] };

Expand Down Expand Up @@ -73,11 +71,9 @@ export function parsePokePasteHTML(html: string, url: string): ParsedTeam {
} else if (line.startsWith("Tera Type:")) {
currentPokemon.teraType = line.split(":")[1]?.trim() ?? "";
} else if (line.startsWith("EVs:")) {
currentPokemon.evs =
parseStats(line.split(":")[1]?.trim() ?? "") ?? currentPokemon.evs;
currentPokemon.evs = parseStats(line.split(":")[1]?.trim() ?? "");
} else if (line.startsWith("IVs:")) {
currentPokemon.ivs =
parseStats(line.split(":")[1]?.trim() ?? "") ?? currentPokemon.ivs;
currentPokemon.ivs = parseStats(line.split(":")[1]?.trim() ?? "");
} else if (line.includes("Nature")) {
currentPokemon.nature = line.split(" ")[0] ?? "";
} else if (line.startsWith("-")) {
Expand All @@ -101,29 +97,29 @@ export function parsePokePasteHTML(html: string, url: string): ParsedTeam {
return { metadata, pokemon };
}

function parseNameSpeciesItem(line: string): {
function parseNameSpeciesItem (line: string): {
name: string;
species: string;
item: string;
gender?: string;
remainingDetails: string;
} {
console.log("Parsing line:", line); // eslint-disable-line no-console
console.log("Parsing line:", line);

const [nameSpecies, itemAndRest] = line.split("@").map((s) => s.trim());

let nameSpeciesLet = nameSpecies;

if (!nameSpeciesLet) {
console.warn("Unable to parse Pokemon name/species from line:", line); // eslint-disable-line no-console
console.warn("Unable to parse Pokemon name/species from line:", line);

return { name: "", species: "Unknown", item: "", remainingDetails: "" };
}

// Handle gender separately
let gender: string | undefined;

if (nameSpeciesLet.endsWith(" (M)") ?? nameSpeciesLet.endsWith(" (F)")) {
if (nameSpeciesLet.endsWith(" (M)") || nameSpeciesLet.endsWith(" (F)")) {
gender = nameSpeciesLet.slice(-2, -1);
nameSpeciesLet = nameSpeciesLet.slice(0, -4);
}
Expand Down Expand Up @@ -155,7 +151,7 @@ function parseNameSpeciesItem(line: string): {
remainingDetails,
};

console.log("Parsed result:", obj); // eslint-disable-line no-console
console.log("Parsed result:", obj);

return obj;
}
7 changes: 4 additions & 3 deletions apps/nextjs/src/lib/pokemon/parse-showdown-format.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {
convertToParsedPokemon,
type ParsedPokemon,
type ParsedTeam,
convertToParsedPokemon


} from "./common";
import type {ParsedPokemon, ParsedTeam} from "./common";
import { Sets } from "@pkmn/sets";

export function parseShowdownFormat(input: string): ParsedTeam {
Expand Down
7 changes: 1 addition & 6 deletions apps/nextjs/src/lib/pokemon/use-pokemon-team.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
"use client";
import { useState, useCallback } from "react";

import {
type ParsedPokemon,
type ParsedTeam,
type PokePasteMetadata,
type ValidatedPokemon,
} from "./common";
import type {ParsedPokemon, ParsedTeam, PokePasteMetadata, ValidatedPokemon} from "./common";
import { parseShowdownFormat } from "./parse-showdown-format";
import { parsePokePasteHTML } from "./parse-pokepaste-html";

Expand Down
Loading

0 comments on commit b99ebd0

Please sign in to comment.