-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update react router to data router (#182)
* Turn Layout into pathless Route * Migrate to router provider * Define data routes for data router * Lift layout route * Add top level error boundary * Lift redirect root route * Lift all the remaining routes * Reorganize configPromise * Turn layout into root route * Rename Layout and PulpMenu
- Loading branch information
Showing
8 changed files
with
113 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { isRouteErrorResponse, useRouteError } from 'react-router'; | ||
|
||
export const ErrorBoundary = () => { | ||
const error = useRouteError(); | ||
|
||
if (isRouteErrorResponse(error)) { | ||
return ( | ||
<> | ||
<h1> | ||
{error.status} {error.statusText} | ||
</h1> | ||
<p>{error.data.toString()}</p> | ||
</> | ||
); | ||
} else if (error instanceof Error) { | ||
return ( | ||
<div> | ||
<h1>Error</h1> | ||
<p>{error.message}</p> | ||
<p>The stack trace is:</p> | ||
<pre>{error.stack}</pre> | ||
</div> | ||
); | ||
console.error(error); | ||
return <div>Something went horribly wrong!</div>; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Outlet, useNavigation } from 'react-router'; | ||
import { AppContextProvider } from 'src/app-context'; | ||
import { LoadingSpinner, UIVersion } from 'src/components'; | ||
import { Layout } from 'src/layout'; | ||
import { UserContextProvider } from 'src/user-context'; | ||
|
||
export default function Root() { | ||
const navigation = useNavigation(); | ||
const isNavigating = Boolean(navigation.location); | ||
|
||
return ( | ||
<UserContextProvider> | ||
<AppContextProvider> | ||
<Layout> | ||
{isNavigating && <LoadingSpinner />} | ||
<Outlet /> | ||
</Layout> | ||
<UIVersion /> | ||
</AppContextProvider> | ||
</UserContextProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import defaults from '../pulp-ui-config.json'; | ||
|
||
export const configPromise = fetch('/pulp-ui-config.json').then((data) => | ||
data.status > 0 && data.status < 300 | ||
? data.json() | ||
: Promise.reject(`${data.status}: ${data.statusText}`), | ||
); | ||
export const configPromise = fetch('/pulp-ui-config.json') | ||
.then((data) => | ||
data.status > 0 && data.status < 300 | ||
? data.json() | ||
: Promise.reject(`${data.status}: ${data.statusText}`), | ||
) | ||
.then((data) => (config = data)); | ||
|
||
export let config = null; | ||
|
||
export const configFallback = () => (config = defaults); | ||
|
||
configPromise.then((data) => (config = data)); |