-
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.
Revert "Add delay and debounce to loader on Swagger Viewer"
This reverts commit 12a4dd9.
- Loading branch information
Showing
1 changed file
with
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,18 @@ | ||
import { useState, useEffect, useRef } from "react" | ||
import { useState } from "react" | ||
import SwaggerUI from "swagger-ui-react" | ||
import "swagger-ui-react/swagger-ui.css" | ||
import { Box } from "@mui/material" | ||
import LoadingWrapper from "./LoadingWrapper" | ||
|
||
const Swagger = ({ url }: { url: string }) => { | ||
const [isLoading, setLoading] = useState(true) | ||
const debounceTimeout = useRef<NodeJS.Timeout | null>(null) | ||
|
||
const handleComplete = () => { | ||
// Clear any existing debounce timeout | ||
if (debounceTimeout.current) { | ||
clearTimeout(debounceTimeout.current) | ||
} | ||
// Set a debounce delay to wait before updating the loading state | ||
debounceTimeout.current = setTimeout(() => { | ||
setLoading(false) | ||
}, 1200) | ||
} | ||
// Cleanup timeout on unmount | ||
useEffect(() => { | ||
return () => { | ||
if (debounceTimeout.current) { | ||
clearTimeout(debounceTimeout.current) | ||
} | ||
} | ||
}, []) | ||
|
||
return ( | ||
<LoadingWrapper showLoadingIndicator={isLoading}> | ||
<Box sx={{ paddingBottom: 1 }}> | ||
<SwaggerUI | ||
url={url} | ||
onComplete={handleComplete} | ||
deepLinking | ||
persistAuthorization | ||
/> | ||
<SwaggerUI url={url} onComplete={() => setLoading(false)} deepLinking persistAuthorization /> | ||
</Box> | ||
</LoadingWrapper> | ||
) | ||
} | ||
|
||
export default Swagger | ||
export default Swagger |