mirror of
https://github.com/SomboChea/ui
synced 2024-11-24 15:04:27 +07:00
fix: removed tsignore for AppContext (#188)
This commit is contained in:
parent
fdbdb6303b
commit
d2c1130efd
@ -14,21 +14,30 @@ import '../utils/styles/global';
|
|||||||
import 'normalize.css';
|
import 'normalize.css';
|
||||||
import Footer from '../components/Footer';
|
import Footer from '../components/Footer';
|
||||||
import { FormError } from '../components/Login/Login';
|
import { FormError } from '../components/Login/Login';
|
||||||
|
import { PackageInterface } from '../components/Package/Package';
|
||||||
|
|
||||||
export const AppContext = React.createContext<{}>({});
|
interface AppContextData {
|
||||||
export const AppContextProvider = AppContext.Provider;
|
|
||||||
export const AppContextConsumer = AppContext.Consumer;
|
|
||||||
|
|
||||||
export interface AppStateInterface {
|
|
||||||
error?: FormError;
|
|
||||||
logoUrl: string;
|
logoUrl: string;
|
||||||
|
scope: string;
|
||||||
|
isUserLoggedIn: boolean;
|
||||||
|
packages: PackageInterface[];
|
||||||
user: {
|
user: {
|
||||||
username?: string;
|
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;
|
showLoginModal: boolean;
|
||||||
isUserLoggedIn: boolean;
|
|
||||||
packages: any[];
|
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
}
|
}
|
||||||
export default class App extends Component<{}, AppStateInterface> {
|
export default class App extends Component<{}, AppStateInterface> {
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import PackageList from '../../components/PackageList';
|
import PackageList from '../../components/PackageList';
|
||||||
|
import { PackageInterface } from '../../components/Package/Package';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
isUserLoggedIn: boolean;
|
isUserLoggedIn: boolean;
|
||||||
packages: [];
|
packages: PackageInterface[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const Home: React.FC<Props> = ({ packages }) => (
|
const Home: React.FC<Props> = ({ packages }) => (
|
||||||
|
@ -4,7 +4,7 @@ import React, { Component, ReactElement } from 'react';
|
|||||||
import { Router, Route, Switch } from 'react-router-dom';
|
import { Router, Route, Switch } from 'react-router-dom';
|
||||||
import { createBrowserHistory } from 'history';
|
import { createBrowserHistory } from 'history';
|
||||||
|
|
||||||
import { AppContextConsumer, AppStateInterface } from './App/App';
|
import { AppContextConsumer } from './App/App';
|
||||||
import Header from './components/Header';
|
import Header from './components/Header';
|
||||||
|
|
||||||
const history = createBrowserHistory({
|
const history = createBrowserHistory({
|
||||||
@ -44,7 +44,7 @@ class RouterApp extends Component<RouterAppProps> {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<AppContextConsumer>
|
<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} />;
|
return <Header logo={logoUrl} onLogout={onLogout} onToggleLoginModal={onToggleLoginModal} scope={scope} username={user && user.username} />;
|
||||||
}}
|
}}
|
||||||
</AppContextConsumer>
|
</AppContextConsumer>
|
||||||
@ -54,8 +54,7 @@ class RouterApp extends Component<RouterAppProps> {
|
|||||||
public renderHomePage = (): ReactElement<HTMLDivElement> => {
|
public renderHomePage = (): ReactElement<HTMLDivElement> => {
|
||||||
return (
|
return (
|
||||||
<AppContextConsumer>
|
<AppContextConsumer>
|
||||||
{function renderConsumerVersionPage({ isUserLoggedIn, packages }: Partial<AppStateInterface>) {
|
{function renderConsumerVersionPage({ isUserLoggedIn, packages }) {
|
||||||
// @ts-ignore
|
|
||||||
return <HomePage isUserLoggedIn={isUserLoggedIn} packages={packages} />;
|
return <HomePage isUserLoggedIn={isUserLoggedIn} packages={packages} />;
|
||||||
}}
|
}}
|
||||||
</AppContextConsumer>
|
</AppContextConsumer>
|
||||||
@ -65,7 +64,7 @@ class RouterApp extends Component<RouterAppProps> {
|
|||||||
public renderVersionPage = (routerProps): ReactElement<HTMLDivElement> => {
|
public renderVersionPage = (routerProps): ReactElement<HTMLDivElement> => {
|
||||||
return (
|
return (
|
||||||
<AppContextConsumer>
|
<AppContextConsumer>
|
||||||
{function renderConsumerVersionPage({ isUserLoggedIn }: Partial<AppStateInterface>) {
|
{function renderConsumerVersionPage({ isUserLoggedIn }) {
|
||||||
return <VersionPackage {...routerProps} isUserLoggedIn={isUserLoggedIn} />;
|
return <VersionPackage {...routerProps} isUserLoggedIn={isUserLoggedIn} />;
|
||||||
}}
|
}}
|
||||||
</AppContextConsumer>
|
</AppContextConsumer>
|
||||||
|
Loading…
Reference in New Issue
Block a user