Skip to content

Commit

Permalink
Implement filtering company interests by event
Browse files Browse the repository at this point in the history
  • Loading branch information
Arash Farzaneh Taleghani committed Mar 15, 2023
1 parent 62cf9c2 commit 3780ce0
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 117 deletions.
22 changes: 17 additions & 5 deletions app/reducers/companyInterest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,29 @@ export const selectCompanyInterestList = createSelector(
(state) => state.companyInterest.byId,
(state) => state.companyInterest.items,
(state, props) => props,
(companyInterestById, companyInterestIds, semesterId) => {
(state, props, selectedEventOption) => selectedEventOption,
(companyInterestById, companyInterestIds, semesterId, eventValue) => {
const companyInterests = companyInterestIds.map(
(id) => companyInterestById[id]
);

if (semesterId === 0) {
if (semesterId === 0 && eventValue === '') {
return companyInterests;
}
if (semesterId === 0 && eventValue !== '') {
return companyInterests.filter((companyInterest) =>
companyInterest.events.includes(eventValue)
);
}
if (semesterId !== 0 && eventValue === '') {
return companyInterests.filter((companyInterest) =>
companyInterest.semesters.includes(semesterId)
);
}

return companyInterests.filter((companyInterest) =>
companyInterest.semesters.includes(semesterId)
return companyInterests.filter(
(companyInterest) =>
companyInterest.semesters.includes(semesterId) &&
companyInterest.events.includes(eventValue)
);
}
);
Expand Down
41 changes: 17 additions & 24 deletions app/routes/companyInterest/CompanyInterestListRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { fetchSemesters } from 'app/actions/CompanyActions';
import {
fetchAll,
deleteCompanyInterest,
fetch as fetchCIA,
fetch,
} from 'app/actions/CompanyInterestActions';
import { LoginPage } from 'app/components/LoginForm';
import { selectCompanyInterestList } from 'app/reducers/companyInterest';
Expand All @@ -15,7 +15,8 @@ import type { CompanySemesterEntity } from 'app/reducers/companySemesters';
import replaceUnlessLoggedIn from 'app/utils/replaceUnlessLoggedIn';
import withPreparedDispatch from 'app/utils/withPreparedDispatch';
import CompanyInterestList from './components/CompanyInterestList';
import { getCsvUrl, semesterToText } from './utils';
import { semesterToText } from './utils';
import { EVENT_TYPE_OPTIONS } from './components/CompanyInterestPage';

const mapStateToProps = (state, props) => {
const semesterId = Number(
Expand All @@ -27,6 +28,9 @@ const mapStateToProps = (state, props) => {
const semesterObj: CompanySemesterEntity | null | undefined = semesters.find(
(semester) => semester.id === semesterId
);
const eventValue = qs.parse(props.location.search, {
ignoreQueryPrefix: true,
}).event;
const selectedSemesterOption = {
id: semesterId ? semesterId : 0,
semester: semesterObj != null ? semesterObj.semester : '',
Expand All @@ -41,46 +45,35 @@ const mapStateToProps = (state, props) => {
: 'Vis alle semestre',
};
const selectedEventOption = {
value: 'company_presentation',
label: 'Bedriftspresentasjon',
value: eventValue ? eventValue : '',
label: eventValue
? EVENT_TYPE_OPTIONS.find((eventType) => eventType.value === eventValue)
.label
: 'Vis alle arrangementstyper',
};
const companyInterestList = selectCompanyInterestList(
state,
selectedSemesterOption.id
selectedSemesterOption.id,
selectedEventOption.value
);
const hasMore = state.companyInterest.hasMore;
const fetching = state.companyInterest.fetching;

return {
semesters,
companyInterestList,
hasMore,
fetching,
selectedSemesterOption,

exportSurvey: async (event?: string) => {
const blob = await fetch(
getCsvUrl(
selectedSemesterOption.year,
selectedSemesterOption.semester,
event
),
{
headers: {
Authorization: `Bearer ${state.auth.token}`,
},
}
).then((response) => response.blob());
return {
url: URL.createObjectURL(blob),
};
},
selectedEventOption,
authToken: state.auth.token,
};
};

const mapDispatchToProps = {
fetchAll,
deleteCompanyInterest,
fetch: fetchCIA,
fetch,
push,
};
export default compose(
Expand Down
17 changes: 4 additions & 13 deletions app/routes/companyInterest/components/CompanyInterest.css
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,6 @@
}
}

.event_section {
display: flex;
flex-direction: row;
justify-content: space-between;
margin: 30px auto;
align-items: flex-end;

@media (--small-viewport) {
flex-flow: column wrap;
align-items: center;
}
}

.companyInterestList {
@media (--small-viewport) {
display: none;
Expand Down Expand Up @@ -179,3 +166,7 @@ ion-icon {
.label {
color: rgb(194, 69, 56);
}

.selector {
min-width: 500px;
}

0 comments on commit 3780ce0

Please sign in to comment.