Skip to content

Commit

Permalink
Fix API pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
dpang314 committed Oct 5, 2023
1 parent 1bf3f3b commit 44bfef9
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
4 changes: 3 additions & 1 deletion backend/server/mongodb/actions/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ export async function adminGetUsers(
};
}

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
2 changes: 1 addition & 1 deletion mobile/components/Overlays/PaginatedOverlay.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, ReactElement, useEffect } from "react";
import React, { ReactElement } from "react";
import { StyleSheet, View, Text } from "react-native";
import { Ionicons } from "@expo/vector-icons";
import IconButton from "../IconButton";
Expand Down
5 changes: 1 addition & 4 deletions mobile/screens/Admin/AdminUserListScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ 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) => {
Expand All @@ -40,8 +39,7 @@ export default function AdminUserList(props: any) {

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

Expand Down Expand Up @@ -126,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
2 changes: 1 addition & 1 deletion mobile/screens/Analytics/AnalyticsUserList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function AnalyticsUserList(props: any) {
// setAllUsers([users]);
if (result) {
setAllUsers([[...result.users]]);
setTotalPages(result.totalCount / PAGE_SIZE + 1);
setTotalPages(Math.ceil(result.totalCount / PAGE_SIZE));
}
}
BackHandler.addEventListener("hardwareBackPress", function () {
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

0 comments on commit 44bfef9

Please sign in to comment.