-
Notifications
You must be signed in to change notification settings - Fork 2
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 #83 from shapehq/feature/stoplight
Embeds Redoc viewer in iframe
- Loading branch information
Showing
19 changed files
with
234 additions
and
89 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import DocumentationViewer from "@/features/docs/view/DocumentationViewer" | ||
|
||
type SearchParams = { visualizer: string, url: string } | ||
|
||
export default async function Page({ | ||
searchParams | ||
}: { | ||
searchParams: SearchParams | ||
}) { | ||
return ( | ||
<DocumentationViewer | ||
visualizer={parseInt(searchParams.visualizer)} | ||
url={searchParams.url} | ||
/> | ||
) | ||
} |
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,19 @@ | ||
import { useState, useEffect } from "react" | ||
import LoadingIndicator from "./LoadingIndicator" | ||
|
||
const DelayedLoadingIndicator = ({ | ||
delay | ||
}: { | ||
delay?: number | ||
}) => { | ||
const [isVisible, setVisible] = useState(false) | ||
useEffect(() => { | ||
const timer = setTimeout(() => { | ||
setVisible(true) | ||
}, delay || 1000) | ||
return () => clearTimeout(timer) | ||
}, [delay, setVisible]) | ||
return <>{isVisible && <LoadingIndicator/>}</> | ||
} | ||
|
||
export default DelayedLoadingIndicator |
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,42 @@ | ||
import { useState, useEffect } from "react" | ||
import { Box, Typography } from "@mui/material" | ||
import { useTheme } from "@mui/material/styles" | ||
|
||
const LoadingIndicator = () => { | ||
const theme = useTheme() | ||
const [count, setCount] = useState(0) | ||
useEffect(() => { | ||
const timer = setInterval(() => { | ||
if (count == 3) { | ||
setCount(0) | ||
} else { | ||
setCount(count + 1) | ||
} | ||
}, 200) | ||
return () => clearTimeout(timer) | ||
}, [count, setCount]) | ||
return ( | ||
<Box style={{ | ||
display: "flex", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
height: "100%", | ||
width: "100%", | ||
background: theme.palette.background.default | ||
}}> | ||
{Array.from(Array(3).keys()).map((e) => { | ||
return ( | ||
<Typography | ||
key={count} | ||
variant="h3" | ||
sx={{ opacity: e + 1 == count ? 0.5 : 0.2 }} | ||
> | ||
• | ||
</Typography> | ||
) | ||
})} | ||
</Box> | ||
) | ||
} | ||
|
||
export default LoadingIndicator |
20 changes: 13 additions & 7 deletions
20
...rojects/view/docs/DocumentationViewer.tsx → ...eatures/docs/view/DocumentationViewer.tsx
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,32 @@ | ||
import { ReactNode } from "react" | ||
import { Box } from "@mui/material" | ||
import LoadingIndicator from "@/common/loading/LoadingIndicator" | ||
|
||
const LoadingWrapper = ({ | ||
showLoadingIndicator, | ||
children | ||
}: { | ||
showLoadingIndicator: boolean, | ||
children: ReactNode | ||
}) => { | ||
return ( | ||
<Box sx={{ width: "100%", height: "100%", position: "relative", overflow: "scroll" }}> | ||
{showLoadingIndicator && | ||
<Box sx={{ width: "100%", height: "100%", position: "absolute" }}> | ||
<LoadingIndicator/> | ||
</Box> | ||
} | ||
<Box sx={{ | ||
width: "100%", | ||
height: "100%", | ||
position: "absolute", | ||
background: "white", | ||
opacity: showLoadingIndicator ? 0 : 1 | ||
}}> | ||
{children} | ||
</Box> | ||
</Box> | ||
) | ||
} | ||
|
||
export default LoadingWrapper |
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,18 @@ | ||
import { useState } from "react" | ||
import { RedocStandalone } from "redoc" | ||
import LoadingWrapper from "./LoadingWrapper" | ||
|
||
const Redocly = ({ url }: { url: string }) => { | ||
const [isLoading, setLoading] = useState(true) | ||
return ( | ||
<LoadingWrapper showLoadingIndicator={isLoading}> | ||
<RedocStandalone | ||
specUrl={url} | ||
options={{ hideLoading: true }} | ||
onLoaded={() => setLoading(false)} | ||
/> | ||
</LoadingWrapper> | ||
) | ||
} | ||
|
||
export default Redocly |
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 @@ | ||
import { useState } from "react" | ||
import SwaggerUI from "swagger-ui-react" | ||
import "swagger-ui-react/swagger-ui.css" | ||
import LoadingWrapper from "./LoadingWrapper" | ||
|
||
const Swagger = ({ url }: { url: string }) => { | ||
const [isLoading, setLoading] = useState(true) | ||
return ( | ||
<LoadingWrapper showLoadingIndicator={isLoading}> | ||
<SwaggerUI url={url} onComplete={() => setLoading(false)} /> | ||
</LoadingWrapper> | ||
) | ||
} | ||
|
||
export default Swagger |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import DocumentationViewer from "@/features/docs/view/DocumentationViewer" | ||
import DocumentationIframe from "./DocumentationIframe" | ||
import DocumentationVisualizer from "@/features/settings/domain/DocumentationVisualizer" | ||
import useDocumentationVisualizer from "@/features/settings/data/useDocumentationVisualizer" | ||
|
||
const Documentation = ({ url }: { url: string }) => { | ||
const [visualizer] = useDocumentationVisualizer() | ||
switch (visualizer) { | ||
case DocumentationVisualizer.REDOCLY: | ||
return <DocumentationIframe visualizer={visualizer} url={url} /> | ||
case DocumentationVisualizer.SWAGGER: | ||
return <DocumentationViewer visualizer={visualizer} url={url} /> | ||
} | ||
} | ||
|
||
export default Documentation |
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,28 @@ | ||
import { Box } from "@mui/material" | ||
import DelayedLoadingIndicator from "@/common/loading/DelayedLoadingIndicator" | ||
import DocumentationVisualizer from "@/features/settings/domain/DocumentationVisualizer" | ||
|
||
const DocumentationIframe = ({ | ||
visualizer, | ||
url | ||
}: { | ||
visualizer: DocumentationVisualizer, | ||
url: string | ||
}) => { | ||
const searchParams = new URLSearchParams() | ||
searchParams.append("visualizer", visualizer.toString()) | ||
searchParams.append("url", url) | ||
return ( | ||
<Box sx={{ width: "100%", height: "100%", position: "relative" }}> | ||
<Box sx={{ width: "100%", height: "100%", position: "absolute" }}> | ||
<DelayedLoadingIndicator/> | ||
</Box> | ||
<iframe | ||
src={`/documentation-viewer?${searchParams.toString()}`} | ||
style={{ width: "100%", height: "100%", position: "absolute" }} | ||
/> | ||
</Box> | ||
) | ||
} | ||
|
||
export default DocumentationIframe |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
10 changes: 5 additions & 5 deletions
10
src/features/projects/view/MobileToolbar.tsx → ...s/projects/view/toolbar/MobileToolbar.tsx
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
File renamed without changes.
10 changes: 5 additions & 5 deletions
10
...res/projects/view/TrailingToolbarItem.tsx → ...ects/view/toolbar/TrailingToolbarItem.tsx
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
File renamed without changes.
40 changes: 19 additions & 21 deletions
40
src/features/settings/view/DocumentationVisualizationPicker.tsx
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