Skip to content

Commit

Permalink
switch to codesandbox examples
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloSzx committed Apr 7, 2021
1 parent 739e1e3 commit c25bb2e
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 68 deletions.
5 changes: 5 additions & 0 deletions .changeset/gold-kings-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@gqless/react': patch
---

[usePaginatedQuery] pause cache changes while merge
4 changes: 4 additions & 0 deletions internal/website/fix-typedoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ async function main() {
);
})
);

spawnSync('node', ['./node_modules/pretty-quick/bin/pretty-quick.js'], {
stdio: 'ignore',
});
}

main().catch((err) => {
Expand Down
2 changes: 1 addition & 1 deletion internal/website/src/components/Examples/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const App = ({ children }: { children?: AppChildren }) => {
return (
<Flex flexDirection="column">
<Topbar />
<Flex flex="1" overflow="hidden" h="calc(100vh - 80px)" m="2px">
<Flex flex="1" m="2px">
<Sidebar display={{ base: 'none', md: 'flex' }} />

<Box
Expand Down
81 changes: 81 additions & 0 deletions internal/website/src/components/Examples/Embed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React, { useEffect, useState } from 'react';
import { useWindowSize } from 'react-use';

import { Box, Spinner, Stack } from '@chakra-ui/react';

const EmbedSpinner = ({ frameHeight }: { frameHeight: number }) => {
const [hideSpinner, setHideSpinner] = useState(false);

useEffect(() => {
let isMounted = true;
const timeout = setTimeout(() => {
if (isMounted) setHideSpinner(true);
}, 5000);
return () => {
isMounted = false;
clearTimeout(timeout);
};
}, []);

if (hideSpinner) return null;

return (
<Box
pos="absolute"
width="100%"
height={frameHeight}
minHeight={frameHeight}
>
<Spinner
size="xl"
thickness="3px"
position="absolute"
left="50%"
top="50%"
zIndex={-1}
emptyColor="gray.200"
color="blue.500"
speed="0.8s"
/>
</Box>
);
};

export interface EmbedProps {
file: string;
initialPath: string;
}

export function CodeSandboxEmbed({ file, initialPath }: EmbedProps) {
const { height } = useWindowSize(0, 400);

if (!file.startsWith('/')) file = '/' + file;

const src = `https://codesandbox.io/embed/prod-framework-b3m2q?fontsize=14&hidenavigation=1&module=${encodeURIComponent(
file
)}&theme=dark&initialpath=${encodeURIComponent(initialPath)}`;

const frameHeight = height - 150;

return (
<Stack height="100%" width="100%">
<EmbedSpinner frameHeight={frameHeight} />

<Box
as="iframe"
width="100%"
height={frameHeight}
minHeight={frameHeight}
src={src}
onMouseOver={() => {
document.body.style.overflowY = 'hidden';
document.body.style.overflowX = 'hidden';
}}
onMouseOut={() => {
document.body.style.overflowY = 'auto';
document.body.style.overflowX = 'auto';
}}
/>
</Stack>
);
}
58 changes: 0 additions & 58 deletions internal/website/src/components/Examples/StackblitzEmbed.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions internal/website/src/pages/examples/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export default function Page() {
<Heading as="h2">Online Editor and Visualization</Heading>
<Text>
These examples are made using{' '}
<Link to="http://stackblitz.io/">
<b>StackBlitz</b>
<Link to="https://codesandbox.io/">
<b>CodeSandbox</b>
</Link>
, which allows you to modify the examples and play with gqless{' '}
<b>without installing anything</b>.
Expand Down
10 changes: 5 additions & 5 deletions internal/website/src/pages/examples/suspense/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import { useLocation } from '@docusaurus/router';

import { ExamplesPage } from '../../../components/Examples/App';
import {
StackBlitzEmbed,
StackBlitzProps,
} from '../../../components/Examples/StackblitzEmbed';
CodeSandboxEmbed,
EmbedProps,
} from '../../../components/Examples/Embed';

export default function Page() {
const { hash } = useLocation();

const { file, initialPath } = useMemo<StackBlitzProps>(() => {
const { file, initialPath } = useMemo<EmbedProps>(() => {
switch (hash) {
case '#headers': {
return {
Expand Down Expand Up @@ -77,7 +77,7 @@ export default function Page() {
</ListItem>
</UnorderedList>
</Stack>
<StackBlitzEmbed file={file} initialPath={initialPath} />
<CodeSandboxEmbed file={file} initialPath={initialPath} />
</ExamplesPage>
);
}
4 changes: 2 additions & 2 deletions internal/website/src/pages/examples/suspense/query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Heading, Text } from '@chakra-ui/react';
import Link from '@docusaurus/Link';

import { ExamplesPage } from '../../../components/Examples/App';
import { StackBlitzEmbed } from '../../../components/Examples/StackblitzEmbed';
import { CodeSandboxEmbed } from '../../../components/Examples/Embed';

export default function Page() {
return (
Expand All @@ -15,7 +15,7 @@ export default function Page() {
<Link to="/react/query#usequery">useQuery</Link> and{' '}
<Link to="/react/query#graphql-hoc">graphql HOC</Link>.
</Text>
<StackBlitzEmbed file="src/components/Hello.tsx" initialPath="/" />
<CodeSandboxEmbed file="src/components/Hello.tsx" initialPath="/" />
</ExamplesPage>
);
}

1 comment on commit c25bb2e

@vercel
Copy link

@vercel vercel bot commented on c25bb2e Apr 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.