parent
220ea84e22
commit
756973e412
@ -8,10 +8,11 @@ import Webpage from "@/app/_components/webpage";
|
|||||||
// TODO: MAKE MAPFIX & SUBMISSIONS USE THE SAME COMPONENTS :angry: (currently too lazy)
|
// TODO: MAKE MAPFIX & SUBMISSIONS USE THE SAME COMPONENTS :angry: (currently too lazy)
|
||||||
|
|
||||||
import "./(styles)/page.scss";
|
import "./(styles)/page.scss";
|
||||||
|
import { ListSortConstants } from "../ts/Sort";
|
||||||
|
|
||||||
export default function MapfixInfoPage() {
|
export default function MapfixInfoPage() {
|
||||||
const [mapfixes, setMapfixes] = useState<MapfixInfo[]>([])
|
const [mapfixes, setMapfixes] = useState<MapfixInfo[]>([])
|
||||||
const [currentPage, setCurrentPage] = useState(0);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const cardsPerPage = 24; // built to fit on a 1920x1080 monitor
|
const cardsPerPage = 24; // built to fit on a 1920x1080 monitor
|
||||||
|
|
||||||
const totalPages = Math.ceil(mapfixes.length / cardsPerPage);
|
const totalPages = Math.ceil(mapfixes.length / cardsPerPage);
|
||||||
@ -22,20 +23,20 @@ export default function MapfixInfoPage() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const nextPage = () => {
|
const nextPage = () => {
|
||||||
if (currentPage < totalPages - 1) {
|
if (currentPage < totalPages) {
|
||||||
setCurrentPage(currentPage + 1);
|
setCurrentPage(currentPage + 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const prevPage = () => {
|
const prevPage = () => {
|
||||||
if (currentPage > 0) {
|
if (currentPage > 1) {
|
||||||
setCurrentPage(currentPage - 1);
|
setCurrentPage(currentPage - 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchMapfixes() {
|
async function fetchMapfixes() {
|
||||||
const res = await fetch('/api/mapfixes?Page=1&Limit=100')
|
const res = await fetch(`/api/mapfixes?Page=${currentPage}&Limit=${cardsPerPage}&Sort=${ListSortConstants.ListSortDateDescending}`)
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
setMapfixes(await res.json())
|
setMapfixes(await res.json())
|
||||||
}
|
}
|
||||||
@ -44,7 +45,7 @@ export default function MapfixInfoPage() {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
fetchMapfixes()
|
fetchMapfixes()
|
||||||
}, 50);
|
}, 50);
|
||||||
}, [])
|
}, [currentPage])
|
||||||
|
|
||||||
if (!mapfixes) {
|
if (!mapfixes) {
|
||||||
return <Webpage>
|
return <Webpage>
|
||||||
|
@ -6,10 +6,11 @@ import { SubmissionCard } from "../_components/mapCard";
|
|||||||
import Webpage from "@/app/_components/webpage";
|
import Webpage from "@/app/_components/webpage";
|
||||||
|
|
||||||
import "./(styles)/page.scss";
|
import "./(styles)/page.scss";
|
||||||
|
import { ListSortConstants } from "../ts/Sort";
|
||||||
|
|
||||||
export default function SubmissionInfoPage() {
|
export default function SubmissionInfoPage() {
|
||||||
const [submissions, setSubmissions] = useState<SubmissionInfo[]>([])
|
const [submissions, setSubmissions] = useState<SubmissionInfo[]>([])
|
||||||
const [currentPage, setCurrentPage] = useState(0);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const cardsPerPage = 24; // built to fit on a 1920x1080 monitor
|
const cardsPerPage = 24; // built to fit on a 1920x1080 monitor
|
||||||
|
|
||||||
const totalPages = Math.ceil(submissions.length / cardsPerPage);
|
const totalPages = Math.ceil(submissions.length / cardsPerPage);
|
||||||
@ -20,20 +21,20 @@ export default function SubmissionInfoPage() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const nextPage = () => {
|
const nextPage = () => {
|
||||||
if (currentPage < totalPages - 1) {
|
if (currentPage < totalPages) {
|
||||||
setCurrentPage(currentPage + 1);
|
setCurrentPage(currentPage + 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const prevPage = () => {
|
const prevPage = () => {
|
||||||
if (currentPage > 0) {
|
if (currentPage > 1) {
|
||||||
setCurrentPage(currentPage - 1);
|
setCurrentPage(currentPage - 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchSubmissions() {
|
async function fetchSubmissions() {
|
||||||
const res = await fetch('/api/submissions?Page=1&Limit=100')
|
const res = await fetch(`/api/submissions?Page=${currentPage}&Limit=${cardsPerPage}&Sort=${ListSortConstants.ListSortDateDescending}`)
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
setSubmissions(await res.json())
|
setSubmissions(await res.json())
|
||||||
}
|
}
|
||||||
@ -42,7 +43,7 @@ export default function SubmissionInfoPage() {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
fetchSubmissions()
|
fetchSubmissions()
|
||||||
}, 50);
|
}, 50);
|
||||||
}, [])
|
}, [currentPage])
|
||||||
|
|
||||||
if (!submissions) {
|
if (!submissions) {
|
||||||
return <Webpage>
|
return <Webpage>
|
||||||
|
15
web/src/app/ts/Sort.ts
Normal file
15
web/src/app/ts/Sort.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
type ListSort = number;
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
const ListSortConstants = {
|
||||||
|
ListSortDisabled: 0,
|
||||||
|
ListSortDisplayNameAscending: 1,
|
||||||
|
ListSortDisplayNameDescending: 2,
|
||||||
|
ListSortDateAscending: 3,
|
||||||
|
ListSortDateDescending: 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
export {
|
||||||
|
type ListSort,
|
||||||
|
ListSortConstants,
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user