Skip to content

Commit d2b2ce1

Browse files
committed
display manual search results based
1 parent 057ec6c commit d2b2ce1

File tree

1 file changed

+66
-12
lines changed

1 file changed

+66
-12
lines changed

frontend/src/views/app/Search.vue

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,33 @@
22
<!-- eslint-disable max-len -->
33
<div class="mx-4 sm:mx-16 lg:mx-32">
44
<NavBar v-bind:currentRoute="'Search'"></NavBar>
5-
<section v-if="searchSubmitted">results</section>
6-
<section v-if="!searchSubmitted" class="flex flex-col my-8 md:my-12">
5+
<section v-if="recommendationsAnalysisDone" class="mx-auto">
6+
<div class="sort-button rounded-md text-lg lg:text-2xl w-24 ml-auto" v-on:click="searchAgain()">
7+
<h1 class="noSelect capitalize">←</h1>
8+
</div>
9+
<Recommendations
10+
v-bind:title="'Potential matches'"
11+
v-bind:recommendationsReceived="recommendations"
12+
v-bind:recommendationsAnalysis="filters"></Recommendations>
13+
</section>
14+
<section v-if="!recommendationsAnalysisDone" class="flex flex-col my-8 md:my-12">
715
<div>
816
<FilterSlider
917
v-bind:min="18"
1018
v-bind:max="100"
1119
v-bind:name="'age'"
1220
v-on:saveFilter="saveFilter"></FilterSlider>
1321
<FilterSlider
14-
v-bind:min="18"
15-
v-bind:max="100"
22+
v-bind:min="0"
23+
v-bind:max="1000"
24+
v-bind:unit="'km'"
25+
v-bind:oneHandle="true"
1626
v-bind:name="'distance'"
1727
v-on:saveFilter="saveFilter"></FilterSlider>
1828
<FilterSlider
1929
v-bind:min="18"
2030
v-bind:max="100"
31+
v-bind:unit="'pts'"
2132
v-bind:name="'popularity'"
2233
v-on:saveFilter="saveFilter"></FilterSlider>
2334
</div>
@@ -50,23 +61,24 @@
5061
import NavBar from '@/components/shared/NavBar.vue';
5162
import FilterSlider from '@/components/shared/FilterSlider.vue';
5263
import MultipleFilters from '@/components/shared/MultipleFilters.vue';
64+
import Recommendations from '@/components/app/recommendations/Recommendations.vue';
5365
5466
export default {
55-
props: ['recommendationsFromSettingUp'],
5667
components: {
5768
MultipleFilters,
5869
NavBar,
5970
FilterSlider,
71+
Recommendations,
6072
},
6173
data: () => ({
62-
searchSubmitted: false,
74+
recommendations: [],
6375
filters: {
6476
age: {
6577
min: null,
6678
max: null,
6779
},
6880
distance: {
69-
min: null,
81+
min: 0,
7082
max: null,
7183
},
7284
popularity: {
@@ -75,19 +87,61 @@ export default {
7587
},
7688
interests: [],
7789
},
90+
recommendationsAnalysisDone: false,
7891
}),
7992
methods: {
8093
saveFilter(...range) {
81-
const [name, min, max] = range;
82-
this.filters[name].min = min;
83-
this.filters[name].max = max;
94+
const [name, min, max, oneHandle] = range;
95+
if (oneHandle) {
96+
this.filters[name].max = min;
97+
} else {
98+
this.filters[name].min = min;
99+
this.filters[name].max = max;
100+
}
84101
},
85102
saveFilterMultiple(...multiple) {
86103
const [name, filters] = multiple;
87104
this.filters[name] = filters;
88105
},
89-
search() {
90-
this.searchSubmitted = true;
106+
async search() {
107+
if (this.filters.interests.length === 0) {
108+
this.filters.interests = [
109+
'swimming', 'wine', 'reading', 'foodie', 'netflix', 'music', 'yoga', 'golf',
110+
'photography', 'baking', 'shopping', 'outdoors', 'art', 'travel', 'hiking',
111+
'running', 'volunteering', 'cycling', 'climbing', 'tea', 'fishing', 'soccer',
112+
'museum', 'dancing', 'surfing', 'karaoke', 'parties', 'diy',
113+
'walking', 'cat lover', 'movies', 'gardening', 'trivia', 'working out',
114+
'cooking', 'gamer', 'brunch', 'blogging', 'picknicking', 'athlete',
115+
'dog lover', 'politics', 'environmentalism', 'instagram', 'spirituality',
116+
'language exchange', 'sports', 'comedy', 'fashion', 'disney', 'vlogging',
117+
'astrology', 'board games', 'craft beer', 'coffee', 'writer',
118+
];
119+
}
120+
const searchRequest = await this.$http.post('/search', {
121+
min_age: this.filters.age.min,
122+
max_age: this.filters.age.max,
123+
min_score: this.filters.popularity.min,
124+
max_score: this.filters.popularity.max,
125+
max_distance: this.filters.distance.max,
126+
tags: this.filters.interests,
127+
});
128+
this.recommendations = searchRequest.data.search_results;
129+
this.recommendations.sort((a, b) => a.distance - b.distance);
130+
for (let i = 0; i < this.recommendations.length; i += 1) {
131+
if (this.recommendations[i].age < 18) {
132+
this.recommendations[i].age = 18;
133+
}
134+
const interests = this.recommendations[i].tags;
135+
this.recommendations[i].interests = [];
136+
this.recommendations[i].distance = Math.floor(this.recommendations[i].distance);
137+
for (let j = 0; j < interests.length; j += 1) {
138+
this.recommendations[i].interests.push(interests[j].name);
139+
}
140+
}
141+
this.recommendationsAnalysisDone = true;
142+
},
143+
searchAgain() {
144+
this.recommendationsAnalysisDone = false;
91145
},
92146
},
93147
};

0 commit comments

Comments
 (0)