Skip to content

Commit

Permalink
Revert "Add delay and debounce to loader on Swagger Viewer"
Browse files Browse the repository at this point in the history
This reverts commit 12a4dd9.
  • Loading branch information
mpabarca committed Sep 10, 2024
1 parent fa8def3 commit e3adc46
Showing 1 changed file with 3 additions and 29 deletions.
32 changes: 3 additions & 29 deletions src/features/docs/view/Swagger.tsx
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

0 comments on commit e3adc46

Please sign in to comment.