forked from owid/owid-grapher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgdocsHooks.ts
34 lines (28 loc) · 1018 Bytes
/
gdocsHooks.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { useEffect, useState } from "react"
import { OwidGdoc, checkIsGdocPost } from "@ourworldindata/utils"
import { checkHasChanges, checkIsLightningUpdate } from "./gdocsDeploy.js"
export const useGdocsChanged = (
prevGdoc: OwidGdoc | undefined,
nextGdoc: OwidGdoc | undefined
) => {
const [hasChanges, setHasChanges] = useState(false)
useEffect(() => {
if (!prevGdoc || !nextGdoc) return
setHasChanges(checkHasChanges(prevGdoc, nextGdoc))
}, [prevGdoc, nextGdoc])
return hasChanges
}
export const useLightningUpdate = (
prevGdoc: OwidGdoc | undefined,
nextGdoc: OwidGdoc | undefined,
hasChanges: boolean
) => {
const [isLightningDeploy, setLightningUpdate] = useState(false)
useEffect(() => {
if (!checkIsGdocPost(prevGdoc) || !checkIsGdocPost(nextGdoc)) return
setLightningUpdate(
checkIsLightningUpdate(prevGdoc, nextGdoc, hasChanges)
)
}, [prevGdoc, nextGdoc, hasChanges])
return isLightningDeploy
}