Skip to content

Commit

Permalink
pull to refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarman committed Aug 8, 2024
1 parent ab97771 commit c293669
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
24 changes: 23 additions & 1 deletion src/pages/Home/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { IonCol, IonContent, IonGrid, IonPage, IonRow } from '@ionic/react';
import {
IonCol,
IonContent,
IonGrid,
IonPage,
IonRefresher,
IonRefresherContent,
IonRow,
RefresherEventDetail,
} from '@ionic/react';
import { useQueryClient } from '@tanstack/react-query';

import './HomePage.scss';
import { QueryKey } from 'common/utils/constants';
import Header from 'common/components/Header/Header';
import UserSummaryCard from 'pages/Users/components/UserSummaryCard/UserSummaryCard';
import WelcomeBlock from './components/WelcomeBlock/WelcomeBlock';
Expand All @@ -11,11 +22,22 @@ import WelcomeBlock from './components/WelcomeBlock/WelcomeBlock';
* @returns JSX
*/
const HomePage = (): JSX.Element => {
const queryClient = useQueryClient();

const handleRefresh = async (event: CustomEvent<RefresherEventDetail>) => {
await queryClient.refetchQueries({ queryKey: [QueryKey.Users], exact: true });
event.detail.complete();
};

return (
<IonPage className="page-home" data-testid="page-home">
<Header title="Ionic Playground" />

<IonContent fullscreen>
<IonRefresher slot="fixed" onIonRefresh={handleRefresh}>
<IonRefresherContent></IonRefresherContent>
</IonRefresher>

<IonGrid fixed>
<IonRow>
<IonCol sizeXs="2" sizeMd="1">
Expand Down
20 changes: 19 additions & 1 deletion src/pages/Users/components/UserList/UserListPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { IonContent, IonPage } from '@ionic/react';
import {
IonContent,
IonPage,
IonRefresher,
IonRefresherContent,
RefresherEventDetail,
} from '@ionic/react';
import { useQueryClient } from '@tanstack/react-query';

import './UserListPage.scss';
import { QueryKey } from 'common/utils/constants';
import Header from 'common/components/Header/Header';
import Container from 'common/components/Content/Container';
import PageHeader from 'common/components/Content/PageHeader';
Expand All @@ -14,13 +22,23 @@ import ProgressProvider from 'common/providers/ProgressProvider';
*/
export const UserListPage = (): JSX.Element => {
const testid = 'page-user-list';
const queryClient = useQueryClient();

const handleRefresh = async (event: CustomEvent<RefresherEventDetail>) => {
await queryClient.refetchQueries({ queryKey: [QueryKey.Users], exact: true });
event.detail.complete();
};

return (
<IonPage className="page-user-list" data-testid={testid}>
<ProgressProvider>
<Header />

<IonContent>
<IonRefresher slot="fixed" onIonRefresh={handleRefresh}>
<IonRefresherContent></IonRefresherContent>
</IonRefresher>

<Container fixed>
<PageHeader title="Users" />
<UserList className="ion-hide-md-up" />
Expand Down

0 comments on commit c293669

Please sign in to comment.