Skip to content

Commit

Permalink
Fix query ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
Bestem0r committed Dec 25, 2024
1 parent df24a0f commit fe2d1cb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
8 changes: 3 additions & 5 deletions app/actions/CompanyActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const fetchAll = ({ fetchMore }: { fetchMore: boolean }) => {
});
};

export function fetchAllAdmin(semesterId: EntityId, fetchMore: boolean) {
export function fetchAllAdmin(query, next: boolean) {
return callAPI<AdminListCompany[]>({
types: Company.FETCH,
endpoint: `/bdb/`,
Expand All @@ -44,11 +44,9 @@ export function fetchAllAdmin(semesterId: EntityId, fetchMore: boolean) {
errorMessage: 'Henting av bedrifter feilet',
},
propagateError: true,
query: {
semester_id: semesterId,
},
query: query,
pagination: {
fetchNext: fetchMore,
fetchNext: next,
},
});
}
Expand Down
47 changes: 35 additions & 12 deletions app/routes/bdb/components/BdbPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ const BdbPage = () => {
[companySemesters, query.semester],
);

console.log(currentCompanySemester);
const { pagination } = useAppSelector(
selectPaginationNext({
endpoint: '/bdb/',
entity: EntityType.Companies,
query: {
semester_id: currentCompanySemester?.id,
...query,
semester_id: String(currentCompanySemester?.id),
},
}),
);
Expand All @@ -80,18 +80,32 @@ const BdbPage = () => {
async () => {
if (!companySemesters.length) {
const action = await dispatch(fetchSemesters());
const companySemesterEntities =
action.payload.entities.companySemesters;
const companySemesters = Object.values(companySemesterEntities).filter(
(companySemester) => companySemester !== undefined,
);
const companySemesters = Object.values(
action.payload.entities.companySemesters,
).filter((companySemester) => companySemester !== undefined);
const semester = resolveCurrentSemester(
query.semester,
companySemesters,
);
return dispatch(fetchAllAdmin(semester!.id, false));
return dispatch(
fetchAllAdmin(
{
...query,
semester_id: semester!.id,
},
false,
),
);
}
return dispatch(fetchAllAdmin(currentCompanySemester!.id, false));
return dispatch(
fetchAllAdmin(
{
...query,
semester_id: currentCompanySemester!.id,
},
false,
),
);
},
[query.semester, currentCompanySemester, companySemesters],
);
Expand Down Expand Up @@ -175,7 +189,7 @@ const BdbPage = () => {
<SelectInput
name="semester"
options={companySemesters
.sort((a, b) => (b.semester === 'autumn' ? 1 : -1))
.sort((_, b) => (b.semester === 'autumn' ? 1 : -1))
.sort((a, b) => b.year - a.year)
.map((semester) => ({
label: semesterToHumanReadable(
Expand Down Expand Up @@ -206,12 +220,21 @@ const BdbPage = () => {
<Table
className={styles.bdbTable}
columns={columns}
data={fetching ? [] : companies}
data={companies}
filters={query}
onChange={setQuery}
loading={fetching}
onLoad={() => {
dispatch(fetchAllAdmin(currentCompanySemester?.id, true));
currentCompanySemester?.id &&
dispatch(
fetchAllAdmin(
{
...query,
semester_id: currentCompanySemester.id,
},
true,
),
);
}}
hasMore={pagination.hasMore}
/>
Expand Down

0 comments on commit fe2d1cb

Please sign in to comment.