From aa7e28e799ce19f04c6c33782ea8d25ef4c3bb98 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Fri, 17 Jan 2025 15:30:04 +0100 Subject: feat(Server): Add frontend starter --- server/frontend/src/App.module.css | 0 server/frontend/src/App.tsx | 11 +++++ server/frontend/src/Test.tsx | 23 +++++++++ server/frontend/src/api-schema.d.ts | 98 +++++++++++++++++++++++++++++++++++++ server/frontend/src/api.ts | 6 +++ server/frontend/src/index.css | 13 +++++ server/frontend/src/index.tsx | 21 ++++++++ 7 files changed, 172 insertions(+) create mode 100644 server/frontend/src/App.module.css create mode 100644 server/frontend/src/App.tsx create mode 100644 server/frontend/src/Test.tsx create mode 100644 server/frontend/src/api-schema.d.ts create mode 100644 server/frontend/src/api.ts create mode 100644 server/frontend/src/index.css create mode 100644 server/frontend/src/index.tsx (limited to 'server/frontend/src') diff --git a/server/frontend/src/App.module.css b/server/frontend/src/App.module.css new file mode 100644 index 0000000..e69de29 diff --git a/server/frontend/src/App.tsx b/server/frontend/src/App.tsx new file mode 100644 index 0000000..6773d90 --- /dev/null +++ b/server/frontend/src/App.tsx @@ -0,0 +1,11 @@ +import type {Component} from "solid-js"; +import {A} from "@solidjs/router"; + +const App: Component = () => { + return <> + Hello World + Test Page + ; +}; + +export default App; diff --git a/server/frontend/src/Test.tsx b/server/frontend/src/Test.tsx new file mode 100644 index 0000000..6eee2d6 --- /dev/null +++ b/server/frontend/src/Test.tsx @@ -0,0 +1,23 @@ +import {A, createAsync} from "@solidjs/router"; +import {client} from "./api.js"; +import {For, Suspense} from "solid-js"; + +export default function Test() { + let items = createAsync(() => client.GET("/item", { + params: { + query: { + itemId: ['HYPERION', 'BAT_WAND'] + } + } + })) + return <> + Test page Back to main +
+ +

Here are all Items:

+ + { ([id, name]) =>
  • {id}: {name}
  • } +
    +
    + +} \ No newline at end of file diff --git a/server/frontend/src/api-schema.d.ts b/server/frontend/src/api-schema.d.ts new file mode 100644 index 0000000..920cd4b --- /dev/null +++ b/server/frontend/src/api-schema.d.ts @@ -0,0 +1,98 @@ +/** + * This file was auto-generated by openapi-typescript. + * Do not make direct changes to the file. + */ + +export interface paths { + "/profiles": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** List all profiles and players known to ledger */ + get: operations["listProfiles"]; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; + "/item": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** Get item names for item ids */ + get: operations["getItemNames"]; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; +} +export type webhooks = Record; +export interface components { + schemas: never; + responses: never; + parameters: never; + requestBodies: never; + headers: never; + pathItems: never; +} +export type $defs = Record; +export interface operations { + listProfiles: { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + requestBody?: never; + responses: { + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + playerId: string; + profileId: string; + }[]; + }; + }; + }; + }; + getItemNames: { + parameters: { + query?: { + itemId?: string[]; + }; + header?: never; + path?: never; + cookie?: never; + }; + requestBody?: never; + responses: { + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + [key: string]: string; + }; + }; + }; + }; + }; +} diff --git a/server/frontend/src/api.ts b/server/frontend/src/api.ts new file mode 100644 index 0000000..00273ec --- /dev/null +++ b/server/frontend/src/api.ts @@ -0,0 +1,6 @@ +import createClient from "openapi-fetch"; +import type {paths} from "./api-schema.js"; + +const apiRoot = import.meta.env.DEV ? "//localhost:8080/api" : "/api"; + +export const client = createClient({baseUrl: apiRoot}); \ No newline at end of file diff --git a/server/frontend/src/index.css b/server/frontend/src/index.css new file mode 100644 index 0000000..4a1df4d --- /dev/null +++ b/server/frontend/src/index.css @@ -0,0 +1,13 @@ +body { + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", + "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", + sans-serif; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +code { + font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", + monospace; +} diff --git a/server/frontend/src/index.tsx b/server/frontend/src/index.tsx new file mode 100644 index 0000000..023872c --- /dev/null +++ b/server/frontend/src/index.tsx @@ -0,0 +1,21 @@ +/* @refresh reload */ +import {render} from "solid-js/web"; + +import "./index.css"; +import type {RouteDefinition} from "@solidjs/router"; +import {Router} from "@solidjs/router"; +import {lazy} from "solid-js"; + +const root = document.getElementById("root"); + +if (!(root instanceof HTMLElement)) { + throw new Error( + "Root element not found. Did you forget to add it to your index.html? Or maybe the id attribute got misspelled?" + ); +} +const routes: Array = [ + {path: '/', component: lazy(() => import("./App.tsx"))}, + {path: "/test/", component: lazy(() => import("./Test.tsx"))} +] + +render(() => {routes}, root!); -- cgit