add repeat for gosuslugi
This commit is contained in:
1 parent
ac3bbb825d
commit
320768b6db
1 file changed
+27
-3
@@ -2,17 +2,41 @@ import { useEffect } from "react"
|
|||||||
import { getCode } from "./lib"
|
import { getCode } from "./lib"
|
||||||
import InnerHTML from "dangerously-set-html-content"
|
import InnerHTML from "dangerously-set-html-content"
|
||||||
|
|
||||||
|
async function sleep(ms: number) {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
setTimeout(resolve, ms)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function repeat(delay: number, times: number, fn: () => void): Promise<void> {
|
||||||
|
try {
|
||||||
|
fn()
|
||||||
|
} catch (error) {
|
||||||
|
if (times === 0) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
|
||||||
|
await sleep(delay)
|
||||||
|
return repeat(delay, times - 1, fn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export type GosuslugiProps = {}
|
export type GosuslugiProps = {}
|
||||||
|
|
||||||
export const Gosuslugi: React.FC<GosuslugiProps> = () => {
|
export const Gosuslugi: React.FC<GosuslugiProps> = () => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const id = setTimeout(() => {
|
let mount = true
|
||||||
|
repeat(1000, 50, () => {
|
||||||
|
if (!mount) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// This call taken from getCode <script>Widget("https://pos.gosuslugi.ru/form", 312519)</script>
|
// This call taken from getCode <script>Widget("https://pos.gosuslugi.ru/form", 312519)</script>
|
||||||
(window as any).Widget("https://pos.gosuslugi.ru/form", 312519)
|
(window as any).Widget("https://pos.gosuslugi.ru/form", 312519)
|
||||||
}, 100)
|
})
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
clearTimeout(id)
|
mount = false
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user