Skip to content

Commit

Permalink
A little cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnaab committed Sep 13, 2023
1 parent d0e02ce commit 68d8169
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 49 deletions.
3 changes: 1 addition & 2 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"@axe-core/playwright": "^4.7.3",
"@uswds/uswds": "^3.6.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"zustand": "^4.4.1"
"react-dom": "^18.2.0"
},
"devDependencies": {
"@playwright/test": "^1.37.1",
Expand Down
9 changes: 1 addition & 8 deletions apps/frontend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
import { Backend } from './state/context';
import { createAppRoot } from './views/main';

createAppRoot(document.getElementById('root') as HTMLElement, {
backend: new (class implements Backend {
helloWorld(echoValue: string) {
return `Hello, ${echoValue}!`;
}
})(),
});
createAppRoot(document.getElementById('root') as HTMLElement, {});
7 changes: 0 additions & 7 deletions apps/frontend/src/state/context.ts

This file was deleted.

18 changes: 0 additions & 18 deletions apps/frontend/src/state/store.ts

This file was deleted.

20 changes: 8 additions & 12 deletions apps/frontend/src/views/context.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { createContext, useContext, useState } from 'react';
import { useStore } from 'zustand';
import { createContext, useContext } from 'react';

import { Backend, Context } from '../state/context';
import { AppStore } from '../state/store';
export interface Backend {
helloWorld(echoValue: string): string;
}

export interface Context {
backend: Backend;
}

export const AppContext = createContext<Context>({
backend: {} as Backend,
Expand All @@ -21,11 +25,3 @@ export const AppContextProvider = ({
}) => {
return <AppContext.Provider value={context}>{children}</AppContext.Provider>;
};

export const useAppStore = <T,>(initStore: (ctx: Context) => AppStore<T>) => {
const ctx = useAppContext();
const [appStore, _] = useState<AppStore<T>>(() => {
return initStore(ctx);
});
return useStore(appStore);
};
3 changes: 1 addition & 2 deletions apps/frontend/src/views/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import '@uswds/uswds';
import React from 'react';
import ReactDOM from 'react-dom/client';

import { Context } from '../state/context';
import { App } from './app';
import './index.scss';
import { AppContextProvider } from './context';
import { AppContextProvider, Context } from './context';

export const createAppRoot = (rootElement: HTMLElement, context: Context) =>
ReactDOM.createRoot(rootElement).render(
Expand Down

0 comments on commit 68d8169

Please sign in to comment.