Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
various changes, up-to-date with esp8266-react mainline
Browse files Browse the repository at this point in the history
  • Loading branch information
proddybot committed Feb 1, 2021
1 parent 3d621f9 commit 30b67f2
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion interface/src/ap/APSettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type APSettingsFormProps = RestFormProps<APSettings>;

class APSettingsForm extends React.Component<APSettingsFormProps> {

componentWillMount() {
componentDidMount() {
ValidatorForm.addValidationRule('isIP', isIP);
}

Expand Down
4 changes: 2 additions & 2 deletions interface/src/authentication/AuthenticatedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Redirect, Route, RouteProps, RouteComponentProps } from "react-router-d
import { withSnackbar, WithSnackbarProps } from 'notistack';

import * as Authentication from './Authentication';
import { withAuthenticationContext, AuthenticationContextProps, AuthenticatedContext } from './AuthenticationContext';
import { withAuthenticationContext, AuthenticationContextProps, AuthenticatedContext, AuthenticatedContextValue } from './AuthenticationContext';

type ChildComponent = React.ComponentType<RouteComponentProps<any>> | React.ComponentType<any>;

Expand All @@ -21,7 +21,7 @@ export class AuthenticatedRoute extends React.Component<AuthenticatedRouteProps>
const renderComponent: RenderComponent = (props) => {
if (authenticationContext.me) {
return (
<AuthenticatedContext.Provider value={authenticationContext as AuthenticatedContext}>
<AuthenticatedContext.Provider value={authenticationContext as AuthenticatedContextValue}>
<Component {...props} />
</AuthenticatedContext.Provider>
);
Expand Down
12 changes: 6 additions & 6 deletions interface/src/authentication/AuthenticationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ export interface Me {
version: string; // proddy added
}

export interface AuthenticationContext {
export interface AuthenticationContextValue {
refresh: () => void;
signIn: (accessToken: string) => void;
signOut: () => void;
me?: Me;
}

const AuthenticationContextDefaultValue = {} as AuthenticationContext
const AuthenticationContextDefaultValue = {} as AuthenticationContextValue
export const AuthenticationContext = React.createContext(
AuthenticationContextDefaultValue
);

export interface AuthenticationContextProps {
authenticationContext: AuthenticationContext;
authenticationContext: AuthenticationContextValue;
}

export function withAuthenticationContext<T extends AuthenticationContextProps>(Component: React.ComponentType<T>) {
Expand All @@ -34,17 +34,17 @@ export function withAuthenticationContext<T extends AuthenticationContextProps>(
};
}

export interface AuthenticatedContext extends AuthenticationContext {
export interface AuthenticatedContextValue extends AuthenticationContextValue {
me: Me;
}

const AuthenticatedContextDefaultValue = {} as AuthenticatedContext
const AuthenticatedContextDefaultValue = {} as AuthenticatedContextValue
export const AuthenticatedContext = React.createContext(
AuthenticatedContextDefaultValue
);

export interface AuthenticatedContextProps {
authenticatedContext: AuthenticatedContext;
authenticatedContext: AuthenticatedContextValue;
}

export function withAuthenticatedContext<T extends AuthenticatedContextProps>(Component: React.ComponentType<T>) {
Expand Down
4 changes: 2 additions & 2 deletions interface/src/authentication/AuthenticationWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import jwtDecode from 'jwt-decode';
import history from '../history'
import { VERIFY_AUTHORIZATION_ENDPOINT } from '../api';
import { ACCESS_TOKEN, authorizedFetch, getStorage } from './Authentication';
import { AuthenticationContext, Me } from './AuthenticationContext';
import { AuthenticationContext, AuthenticationContextValue, Me } from './AuthenticationContext';
import FullScreenLoading from '../components/FullScreenLoading';
import { withFeatures, WithFeaturesProps } from '../features/FeaturesContext';

export const decodeMeJWT = (accessToken: string): Me => jwtDecode(accessToken) as Me;

interface AuthenticationWrapperState {
context: AuthenticationContext;
context: AuthenticationContextValue;
initialized: boolean;
}

Expand Down
4 changes: 2 additions & 2 deletions interface/src/features/FeaturesContext.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';
import { Features } from './types';

export interface FeaturesContext {
export interface FeaturesContextValue {
features: Features;
}

const FeaturesContextDefaultValue = {} as FeaturesContext
const FeaturesContextDefaultValue = {} as FeaturesContextValue
export const FeaturesContext = React.createContext(
FeaturesContextDefaultValue
);
Expand Down
4 changes: 3 additions & 1 deletion interface/src/validators/optional.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export default (validator: (value: any) => boolean) => (value: any) => !value || validator(value);
const OPTIONAL = (validator: (value: any) => boolean) => (value: any) => !value || validator(value);

export default OPTIONAL;
6 changes: 4 additions & 2 deletions interface/src/validators/or.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export default (validator1: (value: any) => boolean, validator2: (value: any) => boolean) => {
const OR = (validator1: (value: any) => boolean, validator2: (value: any) => boolean) => {
return (value: any) => validator1(value) || validator2(value);
}
};

export default OR;
4 changes: 2 additions & 2 deletions interface/src/wifi/WiFiConnection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import { MenuAppBar } from '../components';
import WiFiStatusController from './WiFiStatusController';
import WiFiSettingsController from './WiFiSettingsController';
import WiFiNetworkScanner from './WiFiNetworkScanner';
import { WiFiConnectionContext } from './WiFiConnectionContext';
import { WiFiConnectionContext, WiFiConnectionContextValue } from './WiFiConnectionContext';
import { WiFiNetwork } from './types';

type WiFiConnectionProps = AuthenticatedContextProps & RouteComponentProps;

class WiFiConnection extends Component<WiFiConnectionProps, WiFiConnectionContext> {
class WiFiConnection extends Component<WiFiConnectionProps, WiFiConnectionContextValue> {

constructor(props: WiFiConnectionProps) {
super(props);
Expand Down
4 changes: 2 additions & 2 deletions interface/src/wifi/WiFiConnectionContext.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react';
import { WiFiNetwork } from './types';

export interface WiFiConnectionContext {
export interface WiFiConnectionContextValue {
selectedNetwork?: WiFiNetwork;
selectNetwork: (network: WiFiNetwork) => void;
deselectNetwork: () => void;
}

const WiFiConnectionContextDefaultValue = {} as WiFiConnectionContext
const WiFiConnectionContextDefaultValue = {} as WiFiConnectionContextValue
export const WiFiConnectionContext = React.createContext(
WiFiConnectionContextDefaultValue
);
6 changes: 3 additions & 3 deletions interface/src/wifi/WiFiSettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import SaveIcon from '@material-ui/icons/Save';
import { RestFormProps, PasswordValidator, BlockFormControlLabel, FormActions, FormButton } from '../components';
import { isIP, isHostname, optional } from '../validators';

import { WiFiConnectionContext } from './WiFiConnectionContext';
import { WiFiConnectionContext, WiFiConnectionContextValue } from './WiFiConnectionContext';
import { isNetworkOpen, networkSecurityMode } from './WiFiSecurityModes';
import { WiFiSettings } from './types';

Expand All @@ -24,7 +24,7 @@ class WiFiSettingsForm extends React.Component<WiFiStatusFormProps> {
static contextType = WiFiConnectionContext;
context!: React.ContextType<typeof WiFiConnectionContext>;

constructor(props: WiFiStatusFormProps, context: WiFiConnectionContext) {
constructor(props: WiFiStatusFormProps, context: WiFiConnectionContextValue) {
super(props);

const { selectedNetwork } = context;
Expand All @@ -39,7 +39,7 @@ class WiFiSettingsForm extends React.Component<WiFiStatusFormProps> {
}
}

componentWillMount() {
componentDidMount() {
ValidatorForm.addValidationRule('isIP', isIP);
ValidatorForm.addValidationRule('isHostname', isHostname);
ValidatorForm.addValidationRule('isOptionalIP', optional(isIP));
Expand Down
3 changes: 2 additions & 1 deletion interface/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
"jsx": "react",
"noFallthroughCasesInSwitch": true
},
"include": [
"src"
Expand Down

0 comments on commit 30b67f2

Please sign in to comment.