-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: error boundary, pull in leaflet. (#5)
- Loading branch information
Showing
16 changed files
with
166 additions
and
62 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
|
@@ -23,13 +23,16 @@ | |
], | ||
"author": "Morgan Ney <[email protected]>", | ||
"devDependencies": { | ||
"@types/geojson": "^7946.0.10", | ||
"@types/leaflet": "^1.9.4", | ||
"@types/react": "^18.2.20", | ||
"@types/react-dom": "^18.2.7", | ||
"@vitejs/plugin-react": "^4.0.4", | ||
"vite": "^4.4.9" | ||
}, | ||
"dependencies": { | ||
"@busmap/components": "^1.0.0-alpha.0", | ||
"leaflet": "^1.9.4", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"react-query": "^3.39.3", | ||
|
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,41 @@ | ||
import { Component } from 'react' | ||
|
||
import type { ReactNode } from 'react' | ||
|
||
interface ErrorBoundaryProps { | ||
children: ReactNode | ||
} | ||
interface State { | ||
hasError: boolean | ||
error?: Error | ||
} | ||
|
||
class ErrorBoundary extends Component<ErrorBoundaryProps, State> { | ||
constructor(props: ErrorBoundaryProps) { | ||
super(props) | ||
|
||
this.state = { | ||
hasError: false | ||
} | ||
} | ||
static getDerivedStateFromError(error: Error) { | ||
return { | ||
hasError: true, | ||
error | ||
} | ||
} | ||
|
||
render() { | ||
if (this.state.hasError) { | ||
return ( | ||
<div> | ||
<p>Oops!: {this.state.error?.message}</p> | ||
</div> | ||
) | ||
} | ||
|
||
return this.props.children | ||
} | ||
} | ||
|
||
export { ErrorBoundary } |
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 |
---|---|---|
@@ -1,13 +1,37 @@ | ||
import styled from 'styled-components' | ||
import { Clear } from '@busmap/components/icons/clear' | ||
|
||
const Content = styled.p` | ||
font-weight: 700; | ||
` | ||
export const Home = () => { | ||
return ( | ||
<Content> | ||
This is Home page content. <Clear /> | ||
</Content> | ||
) | ||
import { useQuery } from 'react-query' | ||
import { createPortal } from 'react-dom' | ||
|
||
import { Agencies } from './components/agencies.js' | ||
|
||
import type { ReactNode, FC } from 'react' | ||
|
||
export interface HomeProps { | ||
children?: ReactNode | ||
} | ||
export const Home: FC<HomeProps> = () => { | ||
const { data, error } = useQuery('agencies', async () => { | ||
const resp = await fetch('/restbus/agencies') | ||
const json = await resp.json() | ||
|
||
return json | ||
}) | ||
|
||
if (error) { | ||
if (error instanceof Error) { | ||
return <p>An unexpected error occured: {error.message}</p> | ||
} | ||
} | ||
|
||
if (data) { | ||
return ( | ||
<> | ||
{createPortal( | ||
<Agencies agencies={data} />, | ||
document.querySelector('body > aside') as HTMLElement | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
return <>Loading...</> | ||
} |
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,35 +1,29 @@ | ||
import { useQuery } from 'react-query' | ||
import { createPortal } from 'react-dom' | ||
|
||
import { Agencies } from './components/agencies.js' | ||
import L from 'leaflet' | ||
import { useEffect } from 'react' | ||
|
||
import type { FC, ReactNode } from 'react' | ||
|
||
export const Layout: FC<{ children: ReactNode }> = ({ children }) => { | ||
const { data, error } = useQuery('agencies', async () => { | ||
const resp = await fetch('/restbus/agencies') | ||
const json = await resp.json() | ||
export interface LayoutProps { | ||
children: ReactNode | ||
} | ||
export const Layout: FC<LayoutProps> = ({ children }) => { | ||
useEffect(() => { | ||
const main = document.querySelector('main') as HTMLElement | ||
const map = L.map(main, { | ||
center: [32.79578, -95.45166], | ||
zoom: 13 | ||
}) | ||
|
||
return json | ||
}) | ||
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', { | ||
maxZoom: 19, | ||
attribution: | ||
'© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>' | ||
}).addTo(map) | ||
|
||
if (error) { | ||
if (error instanceof Error) { | ||
return <p>An unexpected error occured: {error.message}</p> | ||
return () => { | ||
map.remove() | ||
} | ||
} | ||
|
||
if (data) { | ||
return ( | ||
<> | ||
{createPortal( | ||
<Agencies agencies={data} />, | ||
document.querySelector('body > aside') as HTMLElement | ||
)} | ||
{children} | ||
</> | ||
) | ||
} | ||
}, []) | ||
|
||
return <>Loading...</> | ||
return children | ||
} |
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