Added SSR

This commit is contained in:
Sebastian Seedorf
2022-08-17 11:52:56 +02:00
parent fe7e6d8ae2
commit 9660f0cf34
16 changed files with 1869 additions and 1834 deletions

View File

@@ -8,8 +8,10 @@ import {useGroups} from "../contexts/GroupProvider";
import {Preferences} from "./Preferences/Preferences";
import {download, streamToArrayBuffer} from "../../src/download";
import Link from "next/link";
import {useRouter} from "next/router";
export const Home: FC = () => {
const router = useRouter()
const {factories} = useFactories()
const {
groups,
@@ -42,13 +44,17 @@ export const Home: FC = () => {
download('factorio-microservices.bin', store());
}}>Store</button>
<button onClick={async () => {
await fetch( '/api/submit', {
const res = await fetch( '/api/submit', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({groups, ignored: ignoredFactories, base: baseFactories})
})
if (res.ok) {
const { uuid } = await res.json()
if (uuid) await router.push({query: {...router.query, id: uuid}})
}
}}>Upload</button>
<input type={"file"} multiple={false} ref={inputRef} onChange={async evt => {
const stream = evt.currentTarget.files?.[0].stream() as globalThis.ReadableStream<Uint8Array>|undefined
@@ -58,7 +64,7 @@ export const Home: FC = () => {
if (inputRef.current) inputRef.current.value = null as unknown as string
}
}}/>
<Link href={'/visualize'}>Visualize</Link>
<Link href={{pathname: '/visualize', query: router.query}}>Visualize</Link>
<Preferences />
<fieldset>
<legend>Missing export factories</legend>