fix: removed tsignore for AppContext (#188)

This commit is contained in:
Thomas Klein 2019-10-12 19:59:47 +02:00 committed by Juan Picado @jotadeveloper
parent fdbdb6303b
commit d2c1130efd
3 changed files with 24 additions and 15 deletions

View File

@ -14,21 +14,30 @@ import '../utils/styles/global';
import 'normalize.css';
import Footer from '../components/Footer';
import { FormError } from '../components/Login/Login';
import { PackageInterface } from '../components/Package/Package';
export const AppContext = React.createContext<{}>({});
export const AppContextProvider = AppContext.Provider;
export const AppContextConsumer = AppContext.Consumer;
export interface AppStateInterface {
error?: FormError;
interface AppContextData {
logoUrl: string;
scope: string;
isUserLoggedIn: boolean;
packages: PackageInterface[];
user: {
username?: string;
};
scope: string;
}
export const AppContext = React.createContext<AppContextData>({
logoUrl: window.VERDACCIO_LOGO,
user: {},
scope: window.VERDACCIO_SCOPE || '',
isUserLoggedIn: false,
packages: [],
});
const AppContextProvider = AppContext.Provider;
export const AppContextConsumer = AppContext.Consumer;
export interface AppStateInterface extends AppContextData {
error?: FormError;
showLoginModal: boolean;
isUserLoggedIn: boolean;
packages: any[];
isLoading: boolean;
}
export default class App extends Component<{}, AppStateInterface> {

View File

@ -1,10 +1,11 @@
import React from 'react';
import PackageList from '../../components/PackageList';
import { PackageInterface } from '../../components/Package/Package';
interface Props {
isUserLoggedIn: boolean;
packages: [];
packages: PackageInterface[];
}
const Home: React.FC<Props> = ({ packages }) => (

View File

@ -4,7 +4,7 @@ import React, { Component, ReactElement } from 'react';
import { Router, Route, Switch } from 'react-router-dom';
import { createBrowserHistory } from 'history';
import { AppContextConsumer, AppStateInterface } from './App/App';
import { AppContextConsumer } from './App/App';
import Header from './components/Header';
const history = createBrowserHistory({
@ -44,7 +44,7 @@ class RouterApp extends Component<RouterAppProps> {
return (
<AppContextConsumer>
{function renderConsumerVersionPage({ logoUrl, scope = '', user }: Partial<AppStateInterface>) {
{function renderConsumerVersionPage({ logoUrl, scope = '', user }) {
return <Header logo={logoUrl} onLogout={onLogout} onToggleLoginModal={onToggleLoginModal} scope={scope} username={user && user.username} />;
}}
</AppContextConsumer>
@ -54,8 +54,7 @@ class RouterApp extends Component<RouterAppProps> {
public renderHomePage = (): ReactElement<HTMLDivElement> => {
return (
<AppContextConsumer>
{function renderConsumerVersionPage({ isUserLoggedIn, packages }: Partial<AppStateInterface>) {
// @ts-ignore
{function renderConsumerVersionPage({ isUserLoggedIn, packages }) {
return <HomePage isUserLoggedIn={isUserLoggedIn} packages={packages} />;
}}
</AppContextConsumer>
@ -65,7 +64,7 @@ class RouterApp extends Component<RouterAppProps> {
public renderVersionPage = (routerProps): ReactElement<HTMLDivElement> => {
return (
<AppContextConsumer>
{function renderConsumerVersionPage({ isUserLoggedIn }: Partial<AppStateInterface>) {
{function renderConsumerVersionPage({ isUserLoggedIn }) {
return <VersionPackage {...routerProps} isUserLoggedIn={isUserLoggedIn} />;
}}
</AppContextConsumer>