Skip to content

Commit

Permalink
refactor: conditionally load gsi script.
Browse files Browse the repository at this point in the history
  • Loading branch information
morganney committed Feb 5, 2024
1 parent 75adceb commit eec1cfb
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/ui/src/components/signIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@ import type { RiderFavoriteItem } from '@busmap/common/types/favorites'

const SignIn: FC = () => {
const ref = useRef<HTMLDivElement>(null)
const { dispatch } = useGlobals()
const { dispatch, page } = useGlobals()
const [riderFavorites, setRiderFavorites] = useState<RiderFavoriteItem[]>()
const [loading, setLoading] = useState(false)
const [gsiLoaded, setGsiLoaded] = useState(false)
const storageDispatch = useStorageDispatch()

useEffect(() => {
const script = document.createElement('script')
if (page === 'signin' && !gsiLoaded) {
const script = document.createElement('script')

script.src = 'https://accounts.google.com/gsi/client'
script.async = true
script.addEventListener('load', () => {
setGsiLoaded(true)
})
document.head.appendChild(script)
}, [])
script.src = 'https://accounts.google.com/gsi/client'
script.async = true
script.addEventListener('load', () => {
setGsiLoaded(true)
})
document.head.appendChild(script)
}
}, [page, gsiLoaded])

useEffect(() => {
if (gsiLoaded && window.google && ref.current) {
Expand Down

0 comments on commit eec1cfb

Please sign in to comment.