Skip to content
This repository was archived by the owner on Jan 16, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion src/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface AppStateInterface {
scope: string;
showLoginModal: boolean;
isUserLoggedIn: boolean;
packages: any[];
packages: [];
isLoading: boolean;
}
export default class App extends Component<{}, AppStateInterface> {
Expand Down Expand Up @@ -85,6 +85,7 @@ export default class App extends Component<{}, AppStateInterface> {
public loadOnHandler = async () => {
try {
const packages = await API.request<any[]>('packages', 'GET');
// @ts-ignore: FIX THIS TYPE: Type 'any[]' is not assignable to type '[]'
this.setState({
packages,
isLoading: false,
Expand Down
20 changes: 20 additions & 0 deletions src/App/AppContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createContext } from 'react';

import { FormError } from '../components/Login/Login';

export interface AppProps {
error?: FormError;
logoUrl: string;
user: {
username?: string;
};
scope: string;
showLoginModal: boolean;
isUserLoggedIn: boolean;
packages: [];
isLoading: boolean;
}

export const AppContext = createContext<Partial<AppProps>>({});
export const AppContextProvider = AppContext.Provider;
export const AppContextConsumer = AppContext.Consumer;
53 changes: 53 additions & 0 deletions src/App/AppRoute.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React, { lazy, useContext, Suspense } from 'react';
import { Route, Switch } from 'react-router-dom';

import { Route as Routes } from '../routers';
import Loading from '../components/Loading';

import { AppContext } from './AppContext';

const NotFound = lazy(() => import('../components/NotFound'));
const VersionContextProvider = lazy(() => import('../pages/Version/VersionContextProvider'));
const VersionPage = lazy(() => import('../pages/Version'));
const HomePage = lazy(() => import('../pages/home'));

/* eslint react/jsx-max-depth: 0 */
const AppRoute: React.FC = () => {
const appContext = useContext(AppContext);
const { isUserLoggedIn, packages } = appContext;

return (
<Suspense fallback={<Loading />}>
<Switch>
<Route exact={true} path={Routes.ROOT}>
<HomePage isUserLoggedIn={!!isUserLoggedIn} packages={packages || []} />
</Route>
<Route exact={true} path={Routes.PACKAGE}>
<VersionContextProvider>
<VersionPage />
</VersionContextProvider>
</Route>
<Route exact={true} path={Routes.PACKAGE_VERSION}>
<VersionContextProvider>
<VersionPage />
</VersionContextProvider>
</Route>
<Route exact={true} path={Routes.SCOPE_PACKAGE_VERSION}>
<VersionContextProvider>
<VersionPage />
</VersionContextProvider>
</Route>
<Route exact={true} path={Routes.SCOPE_PACKAGE}>
<VersionContextProvider>
<VersionPage />
</VersionContextProvider>
</Route>
<Route>
<NotFound />
</Route>
</Switch>
</Suspense>
);
};

export default AppRoute;
76 changes: 0 additions & 76 deletions src/router.tsx

This file was deleted.

7 changes: 7 additions & 0 deletions src/routers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export enum Route {
ROOT = '/',
SCOPE_PACKAGE = '/-/web/detail/@:scope/:package',
SCOPE_PACKAGE_VERSION = '/-/web/detail/@:scope/:package/v/:version',
PACKAGE = '/-/web/detail/:package',
PACKAGE_VERSION = '/-/web/detail/:package/v/:version',
}
4 changes: 0 additions & 4 deletions src/utils/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ export function formatDateDistance(lastUpdate): string {
return distanceInWordsToNow(new Date(lastUpdate));
}

export function buildScopePackage(scope: string, packageName: string): string {
return `@${scope}/${packageName}`;
}

/**
* For <LastSync /> component
* @param {array} uplinks
Expand Down