refactor: add react frontend

This commit is contained in:
2024-09-19 21:19:11 +02:00
parent fd17e4fe6b
commit 7ee3ead05b
46 changed files with 7119 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,42 @@
:root {
--background: #ffffff;
--foreground: #171717;
}
@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}
html,
body {
max-width: 100vw;
overflow-x: hidden;
}
body {
color: var(--foreground);
background: var(--background);
font-family: Arial, Helvetica, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
a {
color: inherit;
text-decoration: none;
}
@media (prefers-color-scheme: dark) {
html {
color-scheme: dark;
}
}

View File

@@ -0,0 +1,33 @@
import type { Metadata } from "next";
import localFont from "next/font/local";
import "./globals.css";
const geistSans = localFont({
src: "./fonts/GeistVF.woff",
variable: "--font-geist-sans",
weight: "100 900",
});
const geistMono = localFont({
src: "./fonts/GeistMonoVF.woff",
variable: "--font-geist-mono",
weight: "100 900",
});
export const metadata: Metadata = {
title: "SimC-Free",
description: "Generated by create next app",
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body className={`${geistSans.variable} ${geistMono.variable}`}>
{children}
</body>
</html>
);
}

View File

@@ -0,0 +1,184 @@
.page {
--gray-rgb: 0, 0, 0;
--gray-alpha-200: rgba(var(--gray-rgb), 0.08);
--gray-alpha-100: rgba(var(--gray-rgb), 0.05);
--button-primary-hover: #383838;
--button-secondary-hover: #f2f2f2;
display: grid;
grid-template-rows: 20px 1fr 20px;
align-items: center;
justify-items: center;
min-height: 100svh;
padding: 80px;
gap: 64px;
font-family: var(--font-geist-sans);
}
@media (prefers-color-scheme: dark) {
.page {
--gray-rgb: 255, 255, 255;
--gray-alpha-200: rgba(var(--gray-rgb), 0.145);
--gray-alpha-100: rgba(var(--gray-rgb), 0.06);
--button-primary-hover: #ccc;
--button-secondary-hover: #1a1a1a;
}
}
.main {
display: flex;
flex-direction: column;
gap: 32px;
grid-row-start: 2;
}
.main ol {
font-family: var(--font-geist-mono);
padding-left: 0;
margin: 0;
font-size: 14px;
line-height: 24px;
letter-spacing: -0.01em;
list-style-position: inside;
}
.main li:not(:last-of-type) {
margin-bottom: 8px;
}
.main code {
font-family: inherit;
background: var(--gray-alpha-100);
padding: 2px 4px;
border-radius: 4px;
font-weight: 600;
}
.ctas {
display: flex;
gap: 16px;
}
.ctas a,
.ctas button {
appearance: none;
border-radius: 128px;
height: 48px;
padding: 0 20px;
border: none;
border: 1px solid transparent;
transition:
background 0.2s,
color 0.2s,
border-color 0.2s;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-size: 16px;
line-height: 20px;
font-weight: 500;
}
.ctas .textarea {
width: 100%;
margin-bottom: 40px;
}
a.primary {
background: var(--foreground);
color: var(--background);
gap: 8px;
}
button.primary {
background: var(--foreground);
color: var(--background);
gap: 8px;
}
a.secondary {
border-color: var(--gray-alpha-200);
min-width: 180px;
}
.footer {
grid-row-start: 3;
display: flex;
gap: 24px;
}
.footer a {
display: flex;
align-items: center;
gap: 8px;
}
.footer img {
flex-shrink: 0;
}
/* Enable hover only on non-touch devices */
@media (hover: hover) and (pointer: fine) {
a.primary:hover {
background: var(--button-primary-hover);
border-color: transparent;
}
a.secondary:hover {
background: var(--button-secondary-hover);
border-color: transparent;
}
.footer a:hover {
text-decoration: underline;
text-underline-offset: 4px;
}
}
@media (max-width: 600px) {
.page {
padding: 32px;
padding-bottom: 80px;
}
.main {
align-items: center;
}
.main ol {
text-align: center;
}
.ctas {
flex-direction: column;
}
.ctas a {
font-size: 14px;
height: 40px;
padding: 0 16px;
}
a.secondary {
min-width: auto;
}
.footer {
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
}
.logo {
margin: auto;
}
/* @media (prefers-color-scheme: dark) {
.logo {
filter: invert();
}
} */

78
frontend/src/app/page.tsx Normal file
View File

@@ -0,0 +1,78 @@
import Image from "next/image";
import styles from "./page.module.css";
import { SimCurrentGear } from "./ui/forms/simCurrentGear";
export default function Home() {
return (
<div className={styles.page}>
<main className={styles.main}>
<img
className={styles.logo}
src={`/img/warcraft-icon-22.png`}
alt="Sim-Free Logo"
width={150}
height={150}
// priority
/>
<ol>
<li>
Copy/paste the text from the SimulationCraft addon. {}
<a
className={styles.primary}
target="_blank"
href="https://github.com/simulationcraft/simc-addon"
>
How to install and use the SimC addon
</a>
</li>
<li>Select pieces of gear and Sim-Free will sim them</li>
</ol>
<SimCurrentGear />
</main>
<footer className={styles.footer}>
<a
href="https://github.com/alexohneander/sim_free/issues/new"
target="_blank"
rel="noopener noreferrer"
>
<Image
aria-hidden
src="https://nextjs.org/icons/file.svg"
alt="File icon"
width={16}
height={16}
/>
Issues
</a>
<a
href="https://github.com/alexohneander/sim_free/"
target="_blank"
rel="noopener noreferrer"
>
<Image
aria-hidden
src="https://nextjs.org/icons/window.svg"
alt="Window icon"
width={16}
height={16}
/>
Project
</a>
<a
href="https://alexohneander.de"
target="_blank"
rel="noopener noreferrer"
>
<Image
aria-hidden
src="https://nextjs.org/icons/globe.svg"
alt="Globe icon"
width={16}
height={16}
/>
Go to alexohneander.de
</a>
</footer>
</div>
);
}

View File

@@ -0,0 +1,76 @@
"use client";
import { useState } from "react";
import styles from "../../page.module.css";
export function SimCurrentGear() {
const [isFetched, setIsFetched] = useState(false);
const [fetchedData, setFetchedData] = useState("");
async function fetchSimResult(formData: FormData) {
try {
const response = await fetch("http://127.0.0.1:8000/sim/current_gear", {
method: "POST",
headers: {
"Access-Control-Allow-Origin": "*",
},
body: formData,
});
if (!response.ok) {
throw new Error(`Error! status: ${response.status}`);
} else {
setIsFetched(true);
setFetchedData(await response.text());
}
} catch (err) {
if (err instanceof Error) {
// ✅ TypeScript knows err is Error
console.log(err.message);
} else {
console.log("Unexpected error", err);
}
}
}
return (
<div>
<iframe
id="renderframe"
style={{
display: `${isFetched ? "block" : "none"}`,
width: "100%",
height: "100vh",
marginBottom: "50px",
}}
srcDoc={`${fetchedData}`}
/>
<form action={fetchSimResult}>
<div className={styles.ctas}>
<textarea
className={styles.textarea}
rows={10}
id="simcprofile"
name="simcprofile"
style={{
display: `${isFetched ? "none" : "block"}`,
}}
/>
</div>
<div className={styles.ctas}>
<button className={styles.primary} type="submit">
Run Sim
</button>
<a
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
className={styles.secondary}
>
Read our docs
</a>
</div>
</form>
</div>
);
}