Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update artifacts paths + mobile UI #23

Merged
merged 10 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"semi": false,
"singleQuote": true,
"jsxSingleQuote": true
}
208 changes: 87 additions & 121 deletions README.md

Large diffs are not rendered by default.

76 changes: 40 additions & 36 deletions app/EngineContext.tsx
Original file line number Diff line number Diff line change
@@ -1,50 +1,54 @@
// Initialize the engine and util imports in the SharedResourcesProvider component:
// Note: must import Uitls as a module instead of a component for engine to work (or else you will get 'self' is undefined wasm errors)
'use client'
import React, { createContext, useContext, useState, useEffect } from 'react';
type Utils = typeof import("./Utils")
type Engine = typeof import("@ezkljs/engine/web/ezkl")
import React, { createContext, useContext, useState, useEffect } from 'react'
type Utils = typeof import('./Utils')
type Engine = typeof import('@ezkljs/engine/web/ezkl')

interface SharedResources {
engine: Engine;
utils: Utils;
engine: Engine
utils: Utils
}

const SharedResourcesContext = createContext<SharedResources | null>(null);
const SharedResourcesContext = createContext<SharedResources | null>(null)
export const useSharedResources = (): SharedResources => {
const context = useContext(SharedResourcesContext);
if (!context) {
throw new Error('useSharedResources must be used within a SharedResourcesProvider');
}
return context;
};
const context = useContext(SharedResourcesContext)
if (!context) {
throw new Error(
'useSharedResources must be used within a SharedResourcesProvider',
)
}
return context
}

interface SharedResourcesProviderProps {
children: React.ReactNode;
children: React.ReactNode
}

export const SharedResourcesProvider: React.FC<SharedResourcesProviderProps> = ({ children }) => {
const [engine, setEngine] = useState<any>(null); // Replace 'any' with the actual type of 'engine'
const [utils, setUtils] = useState<any>(null); // Replace 'any' with the actual type of 'utils'
export const SharedResourcesProvider: React.FC<
SharedResourcesProviderProps
> = ({ children }) => {
const [engine, setEngine] = useState<any>(null) // Replace 'any' with the actual type of 'engine'
const [utils, setUtils] = useState<any>(null) // Replace 'any' with the actual type of 'utils'

useEffect(() => {
async function initializeResources() {
// Initialize the WASM module
const engine = await import("@ezkljs/engine/web/ezkl.js");
setEngine(engine)
await (engine as any).default()
// For human readable wasm debug errors call this function
engine.init_panic_hook()
// Initialize the utils module
const utils = await import("./Utils");
setUtils(utils)
}
initializeResources();
}, []);
useEffect(() => {
async function initializeResources() {
// Initialize the WASM module
const engine = await import('@ezkljs/engine/web/ezkl.js')
setEngine(engine)
await (engine as any).default(undefined, new WebAssembly.Memory({ initial: 20, maximum: 4096, shared: true }))
// For human readable wasm debug errors call this function
engine.init_panic_hook()
// Initialize the utils module
const utils = await import('./Utils')
setUtils(utils)
}
initializeResources()
}, [])

return (
<SharedResourcesContext.Provider value={{ engine, utils }}>
{children}
</SharedResourcesContext.Provider>
);
};
return (
<SharedResourcesContext.Provider value={{ engine, utils }}>
{children}
</SharedResourcesContext.Provider>
)
}
Loading