This repository has been archived by the owner on Jan 31, 2023. It is now read-only.
forked from electricitymaps/electricitymaps-contrib
-
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.
- Loading branch information
1 parent
3bc480a
commit a62aab7
Showing
12 changed files
with
204 additions
and
29 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,15 +1,23 @@ | ||
import LoadingOrError from 'components/LoadingOrError'; | ||
import LeftPanel from 'features/panels/LeftPanel'; | ||
import ErrorBoundary from 'features/error-boundary/ErrorBoundary'; | ||
import Header from 'features/header/Header'; | ||
import type { ReactElement } from 'react'; | ||
import { lazy, Suspense } from 'react'; | ||
|
||
const Map = lazy(async () => import('features/map/Map')); | ||
const LeftPanel = lazy(async () => import('features/panels/LeftPanel')); | ||
|
||
export default function App(): ReactElement { | ||
return ( | ||
<Suspense fallback={<LoadingOrError />}> | ||
<LeftPanel /> | ||
<Map /> | ||
<Suspense fallback={<div />}> | ||
<div className="h-full"> | ||
<Header /> | ||
<div className="flex h-screen"> | ||
<ErrorBoundary> | ||
<LeftPanel /> | ||
<Map /> | ||
</ErrorBoundary> | ||
</div> | ||
</div> | ||
</Suspense> | ||
); | ||
} |
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,57 @@ | ||
import { Component, ErrorInfo, ReactNode } from 'react'; | ||
|
||
interface Props { | ||
children?: ReactNode; | ||
} | ||
|
||
interface State { | ||
hasError: boolean; | ||
error: Error | undefined; | ||
} | ||
|
||
class ErrorBoundary extends Component<Props, State> { | ||
public state: State = { | ||
hasError: false, | ||
error: undefined, | ||
}; | ||
|
||
public static getDerivedStateFromError(error: Error): State { | ||
// Update state so the next render will show the fallback UI. | ||
return { hasError: true, error: error }; | ||
} | ||
|
||
public componentDidCatch(error: Error, errorInfo: ErrorInfo) { | ||
// TODO: Send this to Sentry | ||
console.error('Uncaught error:', error, errorInfo); | ||
} | ||
|
||
public render() { | ||
if (this.state.hasError) { | ||
const url = window.location.href; | ||
return ( | ||
<div className="flex w-full flex-col items-center justify-center"> | ||
<h1>Oh no, something went wrong...</h1> | ||
<p> | ||
Please let us know <a href="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/electricityMaps/electricitymaps-contrib">on Github</a> so we | ||
can fix this! | ||
</p> | ||
<pre className="rounded-lg bg-gray-300 p-2 text-xs"> | ||
Error message: {this.state.error?.message} | ||
<br /> | ||
Url: {url} | ||
</pre> | ||
<a | ||
href="/map" | ||
className="mt-4 cursor-pointer rounded-lg border border-gray-200 bg-gray-100 p-2 text-base text-black" | ||
> | ||
Back to map | ||
</a> | ||
</div> | ||
); | ||
} | ||
|
||
return this.props.children; | ||
} | ||
} | ||
|
||
export default 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import * as NavigationMenu from '@radix-ui/react-navigation-menu'; | ||
import { classnames } from 'tailwindcss-classnames'; | ||
|
||
interface MenuLinkProps { | ||
href: string; | ||
children: React.ReactNode; | ||
active?: boolean; | ||
} | ||
function MenuLink({ children, href, active }: MenuLinkProps): JSX.Element { | ||
return ( | ||
<div className="relative flex py-2 "> | ||
<NavigationMenu.Item asChild className="rounded-md transition-colors hover:bg-zinc-100"> | ||
<NavigationMenu.Link | ||
active={active} | ||
href={href} | ||
className={classnames('px-2 py-2 text-sm', active && 'font-bold')} | ||
> | ||
{children} | ||
{active && <div className="absolute left-0 bottom-0 h-[2px] w-full bg-green-500"></div>} | ||
</NavigationMenu.Link> | ||
</NavigationMenu.Item> | ||
</div> | ||
); | ||
} | ||
|
||
export default function Header(): JSX.Element { | ||
return ( | ||
<div className="flex items-center justify-between pl-4 pr-8 shadow-md"> | ||
<img src="/electricity-maps-logo.svg" alt="" className="w-100 h-10" /> | ||
|
||
<NavigationMenu.Root> | ||
<NavigationMenu.List className="flex space-x-2"> | ||
<MenuLink href="/" active> | ||
Live | ||
</MenuLink> | ||
<MenuLink href="https://electricitymaps.com/open-source/?utm_source=app.electricitymaps.com&utm_medium=referral"> | ||
We're hiring! | ||
</MenuLink> | ||
<MenuLink href="https://electricitymaps.com/open-source/?utm_source=app.electricitymaps.com&utm_medium=referral"> | ||
Open Source | ||
</MenuLink> | ||
<MenuLink href="https://electricitymaps.com/blog/?utm_source=app.electricitymaps.com&utm_medium=referral"> | ||
Blog | ||
</MenuLink> | ||
<MenuLink href="https://electricitymaps.com?utm_source=app.electricitymaps.com&utm_medium=referral"> | ||
Get our data | ||
</MenuLink> | ||
</NavigationMenu.List> | ||
</NavigationMenu.Root> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,9 @@ | |
src: url('/fonts/Inter-Bold.woff2') format('woff2'); | ||
} | ||
} | ||
|
||
html, | ||
body, | ||
#root { | ||
@apply h-full; | ||
} |
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,15 @@ | ||
// Send a greeting message to the console for curious people | ||
export function createConsoleGreeting() { | ||
console.info( | ||
`· · · | ||
· ϟ · %cWelcome to Electricity Maps!%c | ||
· · · | ||
🌱 %cReady to work on fixing climate change full-time? | ||
https://electricitymaps.com/jobs | ||
🐙 Got comments or want to contribute? | ||
https://github.com/electricityMaps/electricitymaps-contrib`, | ||
'color: green; font-weight: bold', | ||
'color: inherit', | ||
'color: #666; font-style: italic' | ||
); | ||
} |