Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add total number of pages #138

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion backend/server/mongodb/actions/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
}),
};

let query: any;

Check warning on line 105 in backend/server/mongodb/actions/User.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

if (!filter || filter === UserFilter.NONPROFIT_USERS) {
query = {
Expand Down Expand Up @@ -154,7 +154,9 @@
};
}

const users = await UserModel.find(query).limit(pageSize);
const users = await UserModel.find(query, null, { sort: { _id: 1 } }).limit(
pageSize
);
const totalCount = await UserModel.countDocuments(query);

return { users, totalCount };
Expand Down
6 changes: 5 additions & 1 deletion mobile/components/Overlays/PaginatedOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
pageBody: ReactElement;
footer?: ReactElement;
headerTitle: string;
navigationProp?: any;

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

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
currentPage: number;
totalPages: number;
errorMessage?: string;
paginationButtonFunction?: (direction: ButtonDirection) => void;
}
Expand All @@ -21,6 +22,7 @@
navigationProp,
headerTitle,
currentPage,
totalPages,
paginationButtonFunction,
errorMessage,
}: PaginatedOverlayProps) {
Expand Down Expand Up @@ -48,7 +50,9 @@
}
}}
></IconButton>
<Text style={styles.pageText}>{currentPage}</Text>
<Text style={styles.pageText}>
{currentPage} / {totalPages}
</Text>
<IconButton
icon={
<View style={styles.backgroundCircle}>
Expand Down
6 changes: 3 additions & 3 deletions mobile/screens/Admin/AdminUserListScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function AdminUserList(props: any) {
const [currentPage, setCurrentPage] = useState(0);
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 @@ -39,7 +39,7 @@ export default function AdminUserList(props: any) {

if (result) {
setAllUsers([[...result.users]]);
setTotalUserCount(result.totalCount);
setTotalPages(Math.ceil(result.totalCount / PAGE_SIZE));
}
}

Expand Down Expand Up @@ -100,6 +100,7 @@ export default function AdminUserList(props: any) {
: "Viewing Users"
}
currentPage={currentPage + 1}
totalPages={totalPages}
errorMessage={error}
pageBody={
<View style={styles.container}>
Expand All @@ -123,7 +124,6 @@ export default function AdminUserList(props: any) {
onEndEditing={loadUsers}
/>
</View>
<Text>Total Users: {totalUserCount}</Text>
{allUsers.length > 0 &&
allUsers[currentPage].map((user, index) => {
return (
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(Math.ceil(result.totalCount / PAGE_SIZE));
}
}
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
4 changes: 3 additions & 1 deletion mobile/screens/Onboarding/LandingScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export default function LandingScreen(props: any) {
</View>
) : null}
<View style={styles.quoteContainer}>
<Text style={styles.quoteText}>{`"Not all wounds are visible"`}</Text>
<Text
style={styles.quoteText}
>{`"Not all wounds are visible"`}</Text>
</View>
</View>
}
Expand Down
2 changes: 1 addition & 1 deletion mobile/screens/Training/AddTrainingLogScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function AddTrainingLogScreen(props: any) {
} else if (Number(totalHours) < 0) {
setError("Total hours cannot be negative!");
return;
} else if (Number(totalHours) > 24) {
} else if (Number(totalHours) > 24) {
setError("Total hours can't exceed 24.");
return;
} else if (skillKeysSelected.length === 0) {
Expand Down
Loading