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

sorting selected semesters in toggle dropdown #855

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
29 changes: 24 additions & 5 deletions src/web/src/components/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
size="sm"
:text="selectedSemester"
class="m-md-2"


>
<b-dropdown-item
v-for="option in semesterOptions"
v-for="option in sortedSemesterOptions"
:key="option.value"
:value="option.value"
@click="selectSemester(option.value)"
Expand Down Expand Up @@ -221,12 +223,28 @@ export default {
}),
...mapState({ sessionId: userTypes.state.SESSION_ID }),
...mapState(["semesters", "selectedSemester"]),
//possibility where I can reorder the semesters
semesterOptions() {
return this.semesters.map(({ semester }) => ({
text: semester,
value: semester,
}));
return this.semesters
.map(({ semester }) => ({
text: semester,
value: semester,
}))
},
sortedSemesterOptions() {
return [...this.semesterOptions].sort((a, b) => {
const [semesterA, yearA] = a.value.split(' ').map(s => s.trim().toLowerCase());
const [semesterB, yearB] = b.value.split(' ').map(s => s.trim().toLowerCase());

// Compare by year
if (yearA > yearB) return -1;
if (yearA < yearB) return 1;

// If year is the same, compare by semester
const order = ['fall', 'summer', 'spring'];
return order.indexOf(semesterA) - order.indexOf(semesterB);
});
}
},
};
</script>
Expand Down Expand Up @@ -278,3 +296,4 @@ export default {
background: hsl(211, 100%, 60%) !important;
}
</style>

Loading