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

Add types in index.tsx #177

Merged
merged 4 commits into from
Oct 13, 2022
Merged
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
19 changes: 13 additions & 6 deletions web/frontend/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,25 @@ class FlashMessage {
return this.level;
}
}

const flashM = new FlashMessage('', 1);
const defaultFlashState = {
getMessages: function (): FlashMessage[] {
return [flashM];
},
addMessage: function (msg: string, level: FlashLevel): void {},
hideMessage: function (index: string): void {},
};
// the flash context handles flash messages across the app
export const FlashContext = createContext<FlashState>(undefined);
export const FlashContext = createContext<FlashState>(defaultFlashState);

// the proxy state provides the proxy address across all the app
export interface ProxyState {
getProxy(): string;
setProxy(p: string);
setProxy(p: string): void;
}

export class ProxyHolder implements ProxyState {
proxy: string;
proxy!: string;

getProxy(): string {
return this.proxy;
Expand Down Expand Up @@ -145,7 +152,7 @@ const Failed: FC = ({ children }) => (
// and displays flash messages.
const AppContainer = () => {
const [content, setContent] = useState<ReactElement>(<Loading />);
const [auth, setAuth] = useState<AuthState>(undefined);
const [auth, setAuth] = useState<AuthState>(defaultAuth);

const [flashes, setFlashes] = useState<FlashMessage[]>([]);

Expand Down Expand Up @@ -226,7 +233,7 @@ const AppContainer = () => {
await setDefaultProxy();

setContent(<App />);
} catch (e) {
} catch (e: any) {
setContent(<Failed>{e.toString()}</Failed>);
console.log('error:', e);
}
Expand Down