Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-laplante committed May 11, 2024
1 parent 335bd83 commit 470e0f0
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 14 deletions.
22 changes: 21 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@
"@types/react-dom": "^18.2.25",
"ace-builds": "^1.33.1",
"classnames": "^2.5.1",
"immer": "^10.1.1",
"pyodide": "^0.25.1",
"react": "^18.2.0",
"react-ace": "^11.0.1",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.13"
"react-error-boundary": "^4.0.13",
"use-immer": "^0.9.0"
}
}
59 changes: 50 additions & 9 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, {useEffect, useState} from "react";


import {createTheme, MantineColorsTuple, MantineProvider} from '@mantine/core';
import {AppShell, Burger, createTheme, MantineColorsTuple, MantineProvider} from '@mantine/core';
import FetchWithProgress from "./FetchWithProgress";
import AceEditor from "react-ace";
import "ace-builds/src-noconflict/mode-jsx";
import {usePyodide} from "../usePyodide";
import {useDisclosure} from "@mantine/hooks";
import {useImmer} from "use-immer";

const myColor: MantineColorsTuple = [
'#e4f8ff',
Expand All @@ -29,15 +31,21 @@ const theme = createTheme({
const Inner: React.FC = () => {
const [data, setData] = useState<ArrayBuffer | null>(null);

const pyodide = usePyodide();
const {pyodide, status: pyodideStatus } = usePyodide();

const [ran, setRan] = useState<boolean>(false);

const [output, setOutput] = useImmer<string[]>([]);

useEffect(() => {
const go = async () => {
if (data && !ran) {
setRan(true);

pyodide.setStdout({
batched: (msg) => setOutput(o => { o.push(msg); })
})

console.warn("LOADING SQLITE");
await pyodide.loadPackage("sqlite3");
console.warn("LOADED!");
Expand Down Expand Up @@ -187,20 +195,53 @@ print(sys.meta_path)

return <>
<FetchWithProgress url={"assets/bitbake-2.8.0.zip"} data={data} setData={setData}/>
<p>pyodide: {pyodideStatus}</p>
<ul>
{output.map(e => <li>{e}</li>)}
</ul>
</>;
}

export const App: React.FC = () => {
const [opened, { toggle }] = useDisclosure();

return (
<MantineProvider theme={theme}>
<AceEditor
mode="java"
theme="github"
name="UNIQUE_ID_OF_DIV"
editorProps={{$blockScrolling: true}}
/>
<Inner/>

<AppShell
header={{ height: 60 }}
navbar={{
width: 300,
breakpoint: 'sm',
collapsed: { mobile: !opened },
}}
padding="md"
>
<AppShell.Header>
<Burger
opened={opened}
onClick={toggle}
hiddenFrom="sm"
size="sm"
/>
<div>Logo</div>
</AppShell.Header>

<AppShell.Navbar p="md">Navbar</AppShell.Navbar>

<AppShell.Main>


<AceEditor
mode="java"
theme="github"
name="UNIQUE_ID_OF_DIV"
editorProps={{$blockScrolling: true}}
/>
<Inner/>
</AppShell.Main>
</AppShell>

</MantineProvider>
);
};
13 changes: 10 additions & 3 deletions src/usePyodide.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import React, { useEffect, useState } from 'react';
import {useEffect, useState} from 'react';

import pyodide from "pyodide";

export const usePyodide = () => {
const [pyodide, setPyodide] = useState(null);
const [pyodide, setPyodide] = useState<pyodide>(null);
const [status, setStatus] = useState<string>('idle');

useEffect(() => {
let isActive = true;

const loadPyodide = async () => {
if (!window.pyodide) {
setStatus("importing");
const { loadPyodide: loadPyodideModule } = await import("https://cdn.jsdelivr.net/pyodide/v0.25.1/full/pyodide.mjs");
setStatus("loading");
window.pyodide = await loadPyodideModule();
setStatus("done");
}
if (isActive) {
setPyodide(window.pyodide);
Expand All @@ -19,9 +25,10 @@ export const usePyodide = () => {
loadPyodide();

return () => {
setStatus("inactive");
isActive = false;
};
}, []);

return pyodide;
return { pyodide, status } as const;
};

0 comments on commit 470e0f0

Please sign in to comment.