Skip to content

Commit

Permalink
add total pages
Browse files Browse the repository at this point in the history
  • Loading branch information
bphoebew committed Oct 4, 2023
1 parent a037946 commit 1bf3f3b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
8 changes: 6 additions & 2 deletions mobile/components/Overlays/PaginatedOverlay.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactElement } from "react";
import React, { useState, ReactElement, useEffect } from "react";

Check warning on line 1 in mobile/components/Overlays/PaginatedOverlay.tsx

View workflow job for this annotation

GitHub Actions / lint

'useState' is defined but never used

Check warning on line 1 in mobile/components/Overlays/PaginatedOverlay.tsx

View workflow job for this annotation

GitHub Actions / lint

'useEffect' is defined but never used
import { StyleSheet, View, Text } from "react-native";
import { Ionicons } from "@expo/vector-icons";
import IconButton from "../IconButton";
Expand All @@ -13,6 +13,7 @@ interface PaginatedOverlayProps {
headerTitle: string;
navigationProp?: any;
currentPage: number;
totalPages: number;
errorMessage?: string;
paginationButtonFunction?: (direction: ButtonDirection) => void;
}
Expand All @@ -21,6 +22,7 @@ export default function PaginatedOverlay({
navigationProp,
headerTitle,
currentPage,
totalPages,
paginationButtonFunction,
errorMessage,
}: PaginatedOverlayProps) {
Expand Down Expand Up @@ -48,7 +50,9 @@ export default function PaginatedOverlay({
}
}}
></IconButton>
<Text style={styles.pageText}>{currentPage}</Text>
<Text style={styles.pageText}>
{currentPage} / {totalPages}
</Text>
<IconButton
icon={
<View style={styles.backgroundCircle}>
Expand Down
3 changes: 3 additions & 0 deletions mobile/screens/Admin/AdminUserListScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function AdminUserList(props: any) {
const [error, setError] = useState("");
const [searchText, setSearchText] = useState("");
const [totalUserCount, setTotalUserCount] = useState<number>(0);
const [totalPages, setTotalPages] = useState<number>(0);

const removeUserFromList = (errorMessage: string, userId: Types.ObjectId) => {
if (errorMessage) {
Expand All @@ -40,6 +41,7 @@ export default function AdminUserList(props: any) {
if (result) {
setAllUsers([[...result.users]]);
setTotalUserCount(result.totalCount);
setTotalPages(result.totalCount / PAGE_SIZE + 1);
}
}

Expand Down Expand Up @@ -100,6 +102,7 @@ export default function AdminUserList(props: any) {
: "Viewing Users"
}
currentPage={currentPage + 1}
totalPages={totalPages}
errorMessage={error}
pageBody={
<View style={styles.container}>
Expand Down
11 changes: 9 additions & 2 deletions mobile/screens/Analytics/AnalyticsUserList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@ export default function AnalyticsUserList(props: any) {
const [allUsers, setAllUsers] = useState<User[][]>([]);
const [currentPage, setCurrentPage] = useState(0);
const [error, setError] = useState("");
const [totalPages, setTotalPages] = useState<number>(0);

const filter = completed
? UserFilter.WITH_800_HOURS_USERS
: UserFilter.WITHOUT_800_HOURS_USERS;

useEffect(() => {
async function loadUsers() {
const users = await ErrorWrapper({
const result = await ErrorWrapper({
functionToExecute: adminGetUsers,
errorHandler: setError,
parameters: [PAGE_SIZE, undefined, filter, ""],
});
setAllUsers([users]);
// setAllUsers([users]);
if (result) {
setAllUsers([[...result.users]]);
setTotalPages(result.totalCount / PAGE_SIZE + 1);
}
}
BackHandler.addEventListener("hardwareBackPress", function () {
props.navigation.navigate(Screens.ADMIN_DASHBOARD_SCREEN);
Expand Down Expand Up @@ -70,6 +76,7 @@ export default function AnalyticsUserList(props: any) {
: "Users Who Did Not Complete Training"
}
currentPage={currentPage + 1}
totalPages={totalPages}
errorMessage={error}
pageBody={
<View style={styles.container}>
Expand Down

0 comments on commit 1bf3f3b

Please sign in to comment.