|
5 | 5 | <div class="flex w-full items-stretch sm:items-center justify-center md:justify-start mb-12 relative"> |
6 | 6 | <Sort |
7 | 7 | 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']" |
9 | 9 | v-on:sort="sort"></Sort> |
10 | 10 | <FilterSlider |
11 | 11 | v-bind:min="recommendationsAnalysis.age.min" |
@@ -53,13 +53,45 @@ export default { |
53 | 53 | FilterSlider, |
54 | 54 | MultipleFiltersDropdown, |
55 | 55 | }, |
| 56 | + data: () => ({ |
| 57 | + loggedInUser: null, |
| 58 | + }), |
56 | 59 | 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; |
59 | 88 | }, |
60 | 89 | filter() { |
61 | 90 | console.log('filter'); |
62 | 91 | }, |
63 | 92 | }, |
| 93 | + mounted() { |
| 94 | + this.loggedInUser = this.$store.getters.getLoggedInUser; |
| 95 | + } |
64 | 96 | }; |
65 | 97 | </script> |
0 commit comments