components#Loading TypeScript Examples

The following examples show how to use components#Loading. 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: RootNavigator.tsx    From react-native-crypto-wallet-app with MIT License 6 votes vote down vote up
RootNavigator = () => {
  const { state, dispatch } = useContext(AppContext);
  const [user, setUser] = useState<FirebaseAuthTypes.User | null>(null);
  const { authLoading } = state;

  const checkUser = useCallback(
    (fbUser: FirebaseAuthTypes.User | null) => {
      setUser(fbUser);
      dispatch({
        type: AUTH_CHECKED,
      });
    },
    [dispatch],
  );

  useEffect(() => {
    const listener = auth().onAuthStateChanged(checkUser);
    return () => {
      listener();
    };
  }, [checkUser]);

  return authLoading ? (
    <Loading />
  ) : (
    <NavigationContainer>
      {user !== null ? <CCVPNavigator /> : <PreAuthNavigator />}
    </NavigationContainer>
  );
}
Example #2
Source File: index.test.tsx    From geist-ui with MIT License 6 votes vote down vote up
describe('Loading', () => {
  it('should render correctly', () => {
    const wrapper = mount(<Loading />)
    expect(wrapper.html()).toMatchSnapshot()
    expect(() => wrapper.unmount()).toMatchSnapshot()
  })

  it('should work with different types', () => {
    const wrapper = mount(
      <div>
        <Loading type="success" />
        <Loading type="secondary" />
        <Loading type="warning" />
        <Loading type="error" />
      </div>,
    )
    expect(wrapper.html()).toMatchSnapshot()
    expect(() => wrapper.unmount()).toMatchSnapshot()
  })

  it('should work with custom styles', () => {
    const wrapper = mount(
      <div>
        <Loading color="#fff" />
        <Loading unit="20%" />
        <Loading unit="10px" />
      </div>,
    )
    expect(wrapper.html()).toMatchSnapshot()
    expect(() => wrapper.unmount()).toMatchSnapshot()
  })

  it('should work with children', () => {
    const wrapper = mount(<Loading>test-children</Loading>)
    expect(wrapper.find('.loading').text()).toContain('test-children')
  })
})
Example #3
Source File: playground.tsx    From geist-ui with MIT License 5 votes vote down vote up
DynamicLive = dynamic(() => import('./dynamic-live'), {
  ssr: false,
  loading: () => (
    <div style={{ padding: '20pt 0' }}>
      <Loading />
    </div>
  ),
})
Example #4
Source File: Home.tsx    From iplocate with MIT License 4 votes vote down vote up
Home: React.FC = () => {
  const [currentIp, setCurrentIp] = useState<IP>();
  const [allIps, setAllIps] = usePersistentState<IP[]>("allIps", []);
  const [loading, setLoading] = useState(false);
  const [error, setError] = useState("");
  const [menuExpanded, setMenuExpanded] = useState(true);

  const onSearchIP = async (ip: string) => {
    setLoading(true);
    setError("");
    setAllIps((existing) => existing.filter((e) => e.traits.ipAddress !== ip));
    const params = new URLSearchParams({ ip });
    try {
      const ip = await request<IP>(`${endpoint}?${params}`);
      if (!(ip.location.latitude && ip.location.longitude)) {
        throw new Error("Unable to locate IP");
      }
      setCurrentIp(ip);
      setAllIps((allIps) => [ip, ...allIps]);
      setLoading(false);
    } catch (e) {
      setError(e.message);
      setLoading(false);
    }
  };

  const onRemoveIp = useCallback(
    (ip: IP) => {
      setAllIps((existing) =>
        existing.filter(
          (exist) => exist.traits.ipAddress !== ip.traits.ipAddress
        )
      );
    },
    [setAllIps]
  );

  const onToggleIpVisible = useCallback(
    (ip: IP) => {
      setAllIps((existing) =>
        existing.map((e) => ({
          ...e,
          hidden:
            e.traits.ipAddress === ip.traits.ipAddress ? !e.hidden : e.hidden,
        }))
      );
    },
    [setAllIps]
  );

  const onSetCurrentIP = useCallback(
    (ip: IP) => {
      if (window.matchMedia("(max-width: 450px)").matches) {
        setMenuExpanded(false);
      }
      setCurrentIp(ip);
    },
    [setCurrentIp]
  );

  return (
    <Wrapper>
      {loading && <Loading />}
      <CollapsableDialog
        title="IP Locate"
        collapsed={!!currentIp && allIps.length > 0}
        menuExpanded={menuExpanded}
        setMenuExpanded={setMenuExpanded}
      >
        {error && <ErrorMsg>{error}</ErrorMsg>}
        <IPForm onSubmit={(ip) => onSearchIP(ip)} />
        <IPMenu
          ips={allIps}
          onRemoveIp={onRemoveIp}
          onSetCurrentIp={onSetCurrentIP}
          onToggleIpVisible={onToggleIpVisible}
        />
      </CollapsableDialog>
      <Map
        selectedIP={currentIp}
        onSetSelectedIp={onSetCurrentIP}
        allIPs={allIps}
      />
    </Wrapper>
  );
}