Skip to content

Commit 7f1feb4

Browse files
committed
upload to same tab, but it's still hangling and demos for some reason does not play
1 parent 8eb7386 commit 7f1feb4

File tree

4 files changed

+60
-32
lines changed

4 files changed

+60
-32
lines changed

web/src/App.jsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1+
import { useState } from 'react'
12
import { LocationProvider, Router, Route, lazy } from 'preact-iso';
23
import { Home } from './Index/Home'
34
import { PlayerApp } from './Player/PlayerApp'
5+
import { DemoContext } from './context'
46

57
export function App() {
6-
return <LocationProvider>
7-
<Router>
8-
{/* Both of these are equivalent */}
9-
<Home path="/" />
10-
<Route path="/player" component={PlayerApp} />
11-
{/* <NotFound default /> */}
12-
</Router>
13-
</LocationProvider>
8+
const [demoData, setDemoData] = useState(null);
9+
return (
10+
<DemoContext.Provider value={{demoData, setDemoData}}>
11+
<LocationProvider>
12+
<Router>
13+
{/* Both of these are equivalent */}
14+
<Home path="/" />
15+
<Route path="/player" component={PlayerApp} />
16+
{/* <NotFound default /> */}
17+
</Router>
18+
</LocationProvider>
19+
</DemoContext.Provider>
20+
)
1421
}

web/src/Index/Uploader/Uploader.jsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import './Uploader.css';
22
import { FileUpload } from 'primereact/fileupload';
33
import { ProgressBar } from 'primereact/progressbar';
4+
import { useLocation } from 'preact-iso';
5+
import { useContext } from 'react';
6+
import { DemoContext } from '../../context'
47

58
const Uploader = (props) => {
9+
const demoData = useContext(DemoContext);
610
// const [serverHost] = useState(window.location.host.includes("localhost") ? "http://localhost:8080" : "")
711
// const [uploadProgress, setUploadProgress] = useState([])
812
// const onUpload = function (event) {
@@ -12,26 +16,28 @@ const Uploader = (props) => {
1216
// const onProgress = (event, filename) => {
1317
// console.log("progress", filename, event)
1418
// }
19+
const { route } = useLocation();
1520

1621
const uploadHandler = function ({ files }) {
1722
const [file] = files;
1823
console.log(file)
1924
console.log("am I even here?")
2025

2126
const reader = new FileReader();
22-
27+
2328
console.log("and here?")
2429
reader.onload = function (e) {
2530
console.log("loadedede");
2631
const arrayBuffer = e.target.result;
2732
const byteArray = new Uint8Array(arrayBuffer);
28-
29-
const uuid = crypto.randomUUID()
30-
window.open("/player?platform=upload&uuid=" + uuid, '_blank').focus();
31-
const channel = new BroadcastChannel(uuid);
32-
setTimeout(() => {
33-
channel.postMessage(byteArray);
34-
}, 1000)
33+
demoData.setDemoData(byteArray)
34+
route("/player?blabol")
35+
// const uuid = crypto.randomUUID()
36+
// window.open("/player?platform=upload&uuid=" + uuid, '_blank').focus();
37+
// const channel = new BroadcastChannel(uuid);
38+
// setTimeout(() => {
39+
// channel.postMessage(byteArray);
40+
// }, 1000)
3541
};
3642
reader.readAsArrayBuffer(file);
3743
}

web/src/Player/PlayerApp.jsx

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState } from "react";
1+
import { useEffect, useState, useContext } from "react";
22
import './PlayerApp.css';
33
import ErrorBoundary from "./Error.jsx";
44
import MessageBus from "./MessageBus.js";
@@ -7,26 +7,26 @@ import Map2d from "./map/Map2d.jsx";
77
import InfoPanel from "./panel/InfoPanel.jsx";
88
import '../libs/wasm_exec.js';
99
import './protos/Message_pb.js'
10+
import DemoContext from "../context.js"
1011

1112
export function PlayerApp() {
13+
const demoData = useContext(DemoContext);
14+
1215
const [messageBus] = useState(new MessageBus())
1316
const [player] = useState(new Player(messageBus))
1417
const [serverHost] = useState(window.location.host.includes("localhost") ? "http://localhost:8080" : "");
1518
const [isWasmLoaded, setIsWasmLoaded] = useState(false)
1619

1720
useEffect(() => {
18-
console.log("run run run")
21+
console.log("run run run", demoData)
1922

2023
if (!isWasmLoaded) {
2124
loadWasm();
2225
return
2326
}
2427

25-
const urlParams = new URLSearchParams(window.location.search);
26-
const channel = new BroadcastChannel(urlParams.get("uuid"));
27-
channel.onmessage = (event) => {
28-
console.log("received", event, isWasmLoaded)
29-
window.testt(event.data, function (data) {
28+
if (demoData.demoData) {
29+
window.testt(demoData.demoData, async function (data) {
3030
if (data instanceof Uint8Array) {
3131
const msg = proto.Message.deserializeBinary(data).toObject()
3232
messageBus.emit(msg)
@@ -35,7 +35,25 @@ export function PlayerApp() {
3535
messageBus.emit(JSON.parse(data))
3636
}
3737
})
38-
};
38+
demoData.setDemoData(null)
39+
}
40+
41+
// const urlParams = new URLSearchParams(window.location.search);
42+
// const channel = new BroadcastChannel(urlParams.get("uuid"));
43+
// channel.onmessage = async (event) => {
44+
// console.log("received", event, isWasmLoaded)
45+
// await window.testt(event.data, function (data) {
46+
// if (data instanceof Uint8Array) {
47+
// const msg = proto.Message.deserializeBinary(data).toObject()
48+
// setMessage("123")
49+
// console.log("huha?")
50+
// messageBus.emit(msg)
51+
// } else {
52+
// console.log("[message] text data received from server, this is weird. We're using protobufs ?!?!?", data);
53+
// messageBus.emit(JSON.parse(data))
54+
// }
55+
// })
56+
// };
3957
messageBus.listen([13], function (msg) {
4058
alert(msg.message)
4159
// window.testt(byteArray)
@@ -65,11 +83,3 @@ export function PlayerApp() {
6583
</div>
6684
</ErrorBoundary>);
6785
}
68-
69-
async function parseDemo(event, messageBus) {
70-
await parse(event, messageBus)
71-
}
72-
73-
async function parse(event, messageBus) {
74-
75-
}

web/src/context.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { createContext } from 'react';
2+
3+
export const DemoContext = createContext("some context here?");
4+
5+
export default DemoContext;

0 commit comments

Comments
 (0)