Skip to content

Commit f118729

Browse files
committed
sorting works except based on tags
1 parent 2e1a6df commit f118729

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

frontend/src/components/app/recommendations/Recommendations.vue

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<div class="flex w-full items-stretch sm:items-center justify-center md:justify-start mb-12 relative">
66
<Sort
77
v-bind:position="'left'"
8-
v-bind:options="['Youngest', 'Oldest', 'Closest', 'Furthest', 'Most popular', 'Least popular', 'Most common interests', 'Least common interests']"
8+
v-bind:options="['Closest', 'Furthest', 'Youngest', 'Oldest', 'Most popular', 'Least popular', 'Most common interests', 'Least common interests']"
99
v-on:sort="sort"></Sort>
1010
<FilterSlider
1111
v-bind:min="recommendationsAnalysis.age.min"
@@ -53,13 +53,45 @@ export default {
5353
FilterSlider,
5454
MultipleFiltersDropdown,
5555
},
56+
data: () => ({
57+
loggedInUser: null,
58+
}),
5659
methods: {
57-
sort() {
58-
console.log('sort');
60+
sort(...args) {
61+
const [by] = args;
62+
if (by === 'Closest') {
63+
this.recommendations.sort((a, b) => a.distance - b.distance);
64+
} else if (by === 'Furthest') {
65+
this.recommendations.sort((a, b) => b.distance - a.distance);
66+
} else if (by === 'Youngest') {
67+
this.recommendations.sort((a, b) => a.age - b.age);
68+
} else if (by === 'Oldest') {
69+
this.recommendations.sort((a, b) => b.age - a.age);
70+
} else if (by === 'Most popular') {
71+
this.recommendations.sort((a, b) => b.heat_score - a.heat_score);
72+
} else if (by === 'Least popular') {
73+
this.recommendations.sort((a, b) => a.heat_score - b.heat_score);
74+
} else if (by === 'Most common interests') {
75+
this.recommendations.sort((a, b) => this.count_similarities(a.tags, this.loggedInUser.tags) - this.count_similarities(b.tags, this.loggedInUser.tags));
76+
} else if (by === 'Least common interests') {
77+
this.recommendations.sort((a, b) => this.count_similarities(b.tags, this.loggedInUser.tags) - this.count_similarities(a.tags, this.loggedInUser.tags));
78+
}
79+
},
80+
count_similarities(arrayA, arrayB) {
81+
let matches = 0;
82+
for (let i = 0 ; i < arrayA.length; i++) {
83+
if (arrayB.indexOf(arrayA[i].name) != -1) {
84+
matches++;
85+
}
86+
}
87+
return matches;
5988
},
6089
filter() {
6190
console.log('filter');
6291
},
6392
},
93+
mounted() {
94+
this.loggedInUser = this.$store.getters.getLoggedInUser;
95+
}
6496
};
6597
</script>

frontend/src/components/shared/Sort.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default {
1919
props: ['options', 'name', 'position'],
2020
data: () => ({
2121
closed: true,
22-
currentOption: '',
22+
currentOption: 'Closest',
2323
}),
2424
methods: {
2525
select(option) {

frontend/src/views/app/Browse.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export default {
4949
const recommendationsRequest = await this.$http.get('/recommendations');
5050
this.recommendations = recommendationsRequest.data.recommendations;
5151
}
52+
this.recommendations.sort((a, b) => a.distance - b.distance);
5253
for (let i = 0; i < this.recommendations.length; i += 1) {
5354
if (this.recommendationsAnalysis.age.min === null || this.recommendations[i].age < this.recommendationsAnalysis.age.min) {
5455
this.recommendationsAnalysis.age.min = this.recommendations[i].age;

0 commit comments

Comments
 (0)