generated from storybookjs/addon-kit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #303 from chromaui/ghengeveld/251-ui-no-network-issue
Poll for API connection and show notification when it fails
- Loading branch information
Showing
7 changed files
with
153 additions
and
8 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
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,20 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import { NoNetwork } from "./NoNetwork"; | ||
|
||
const meta = { | ||
component: NoNetwork, | ||
args: { | ||
aborted: false, | ||
}, | ||
} satisfies Meta<typeof NoNetwork>; | ||
|
||
export default meta; | ||
|
||
export const Default = {} satisfies StoryObj<typeof meta>; | ||
|
||
export const Aborted = { | ||
args: { | ||
aborted: true, | ||
}, | ||
} satisfies StoryObj<typeof meta>; |
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,61 @@ | ||
import { SyncIcon } from "@storybook/icons"; | ||
import { useChannel } from "@storybook/manager-api"; | ||
import { styled } from "@storybook/theming"; | ||
import React, { useEffect, useState } from "react"; | ||
|
||
import { Button } from "../../components/Button"; | ||
import { Container } from "../../components/Container"; | ||
import { Link } from "../../components/design-system"; | ||
import { rotate360 } from "../../components/design-system/shared/animation"; | ||
import { Heading } from "../../components/Heading"; | ||
import { Screen } from "../../components/Screen"; | ||
import { Stack } from "../../components/Stack"; | ||
import { Text } from "../../components/Text"; | ||
import { RETRY_CONNECTION } from "../../constants"; | ||
|
||
const SpinIcon = styled(SyncIcon)({ | ||
animation: `${rotate360} 1s linear infinite`, | ||
}); | ||
|
||
export const NoNetwork = ({ aborted }: { aborted: boolean }) => { | ||
const [retried, setRetried] = useState(false); | ||
const emit = useChannel({}); | ||
|
||
const retry = () => { | ||
setRetried(true); | ||
emit(RETRY_CONNECTION); | ||
}; | ||
|
||
useEffect(() => { | ||
setRetried(false); | ||
}, [aborted]); | ||
|
||
return ( | ||
<Screen footer={null}> | ||
<Container> | ||
<Stack> | ||
<div> | ||
<Heading>Can't connect to Chromatic</Heading> | ||
<Text center muted> | ||
Double check your internet connection and firewall settings. | ||
</Text> | ||
</div> | ||
{aborted ? ( | ||
<Button size="medium" variant="solid" onClick={retry} disabled={retried}> | ||
<SyncIcon /> | ||
Retry | ||
</Button> | ||
) : ( | ||
<Button size="medium" variant="ghost" onClick={retry} disabled={retried}> | ||
<SpinIcon /> | ||
Connecting... | ||
</Button> | ||
)} | ||
<Link href="https://status.chromatic.com" target="_blank" rel="noreferrer" withArrow> | ||
Chromatic API status | ||
</Link> | ||
</Stack> | ||
</Container> | ||
</Screen> | ||
); | ||
}; |
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