components#FullPageSpinner JavaScript Examples

The following examples show how to use components#FullPageSpinner. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: useAuth.js    From git-insights with MIT License 5 votes vote down vote up
function AuthProvider(props) {
  const [firstAttemptFinished, setFirstAttemptFinished] = useState(false)
  const {
    data = { user: null },
    error,
    isRejected,
    isPending,
    isSettled,
    reload,
  } = useAsync({
    promiseFn: bootstrapAppData,
  });

  useLayoutEffect(() => {
    if (isSettled) {
      setFirstAttemptFinished(true)
    }
  }, [isSettled])

  if (!firstAttemptFinished) {
    if (isPending) {
      return <FullPageSpinner />
    }
    if (isRejected) {
      return (
        <div css={{color: 'red'}}>
          <p>Uh oh... There's a problem. Try refreshing the app.</p>
          <pre>{error.message}</pre>
        </div>
      )
    }
  }

  // const login = form => authClient.login(form).then(reload)
  // const register = form => authClient.register(form).then(reload)

  const login = () => undefined;
  const register = () => undefined;
  const logout = () => authClient.logout().then(reload);

  return (
    <AuthContext.Provider value={{data, login, logout, register}} {...props} />
  )
}