1414
1515<script >
1616/* eslint-disable max-len */
17+
1718import NavBar from ' @/components/shared/NavBar.vue' ;
1819import Recommendations from ' @/components/app/recommendations/Recommendations.vue' ;
1920
2021export default {
22+ name: ' Browse' ,
2123 props: [' recommendationsFromSettingUp' ],
2224 components: {
2325 NavBar,
@@ -42,47 +44,70 @@ export default {
4244 },
4345 recommendationsAnalysisDone: false ,
4446 }),
45- async created () {
46- if (this .recommendationsFromSettingUp ) {
47- this .recommendations = this .recommendationsFromSettingUp ;
48- } else {
49- const recommendationsRequest = await this .$http .get (' /recommendations' );
50- this .recommendations = recommendationsRequest .data .recommendations ;
51- }
52- this .recommendations .sort ((a , b ) => a .distance - b .distance );
53- for (let i = 0 ; i < this .recommendations .length ; i += 1 ) {
54- this .recommendations [i].distance = Math .floor (this .recommendations [i].distance );
55- if (this .recommendations [i].age < 18 ) {
56- this .recommendations [i].age = 18 ;
57- }
58- if (this .recommendationsAnalysis .age .min === null || this .recommendations [i].age < this .recommendationsAnalysis .age .min ) {
59- this .recommendationsAnalysis .age .min = this .recommendations [i].age ;
60- }
61- if (this .recommendationsAnalysis .age .max === null || this .recommendations [i].age > this .recommendationsAnalysis .age .max ) {
62- this .recommendationsAnalysis .age .max = this .recommendations [i].age ;
63- }
64- if (this .recommendationsAnalysis .distance .min === null || this .recommendations [i].distance < this .recommendationsAnalysis .distance .min ) {
65- this .recommendationsAnalysis .distance .min = this .recommendations [i].distance ;
47+ methods: {
48+ async fetchUsers () {
49+ if (this .recommendationsFromSettingUp ) {
50+ this .recommendations = this .recommendationsFromSettingUp ;
51+ } else {
52+ const recommendationsRequest = await this .$http .get (' /recommendations' );
53+ this .recommendations = recommendationsRequest .data .recommendations ;
6654 }
67- if (this .recommendationsAnalysis .distance .max === null || this .recommendations [i].distance > this .recommendationsAnalysis .distance .max ) {
68- this .recommendationsAnalysis .distance .max = this .recommendations [i].distance ;
69- }
70- if (this .recommendationsAnalysis .popularity .min === null || this .recommendations [i].heat_score < this .recommendationsAnalysis .popularity .min ) {
71- this .recommendationsAnalysis .popularity .min = this .recommendations [i].heat_score ;
72- }
73- if (this .recommendationsAnalysis .popularity .max === null || this .recommendations [i].heat_score > this .recommendationsAnalysis .popularity .max ) {
74- this .recommendationsAnalysis .popularity .max = this .recommendations [i].heat_score ;
75- }
76- const interests = this .recommendations [i].tags ;
77- this .recommendations [i].interests = [];
78- for (let j = 0 ; j < interests .length ; j += 1 ) {
79- this .recommendations [i].interests .push (interests[j].name );
80- if (this .recommendationsAnalysis .interests .indexOf (interests[j].name ) === - 1 ) {
81- this .recommendationsAnalysis .interests .push (interests[j].name );
55+ this .recommendations .sort ((a , b ) => a .distance - b .distance );
56+ for (let i = 0 ; i < this .recommendations .length ; i += 1 ) {
57+ this .recommendations [i].distance = Math .floor (this .recommendations [i].distance );
58+ if (this .recommendations [i].age < 18 ) {
59+ this .recommendations [i].age = 18 ;
60+ }
61+ if (this .recommendationsAnalysis .age .min === null || this .recommendations [i].age < this .recommendationsAnalysis .age .min ) {
62+ this .recommendationsAnalysis .age .min = this .recommendations [i].age ;
63+ }
64+ if (this .recommendationsAnalysis .age .max === null || this .recommendations [i].age > this .recommendationsAnalysis .age .max ) {
65+ this .recommendationsAnalysis .age .max = this .recommendations [i].age ;
66+ }
67+ if (this .recommendationsAnalysis .distance .min === null || this .recommendations [i].distance < this .recommendationsAnalysis .distance .min ) {
68+ this .recommendationsAnalysis .distance .min = this .recommendations [i].distance ;
69+ }
70+ if (this .recommendationsAnalysis .distance .max === null || this .recommendations [i].distance > this .recommendationsAnalysis .distance .max ) {
71+ this .recommendationsAnalysis .distance .max = this .recommendations [i].distance ;
72+ }
73+ if (this .recommendationsAnalysis .popularity .min === null || this .recommendations [i].heat_score < this .recommendationsAnalysis .popularity .min ) {
74+ this .recommendationsAnalysis .popularity .min = this .recommendations [i].heat_score ;
75+ }
76+ if (this .recommendationsAnalysis .popularity .max === null || this .recommendations [i].heat_score > this .recommendationsAnalysis .popularity .max ) {
77+ this .recommendationsAnalysis .popularity .max = this .recommendations [i].heat_score ;
78+ }
79+ const interests = this .recommendations [i].tags ;
80+ this .recommendations [i].interests = [];
81+ for (let j = 0 ; j < interests .length ; j += 1 ) {
82+ this .recommendations [i].interests .push (interests[j].name );
83+ if (this .recommendationsAnalysis .interests .indexOf (interests[j].name ) === - 1 ) {
84+ this .recommendationsAnalysis .interests .push (interests[j].name );
85+ }
8286 }
8387 }
88+ this .recommendationsAnalysisDone = true ;
89+ },
90+ browseAgain () {
91+ this .recommendations = [];
92+ this .recommendationsAnalysis .age .min = null ;
93+ this .recommendationsAnalysis .age .max = null ;
94+ this .recommendationsAnalysis .distance .min = null ;
95+ this .recommendationsAnalysis .distance .max = null ;
96+ this .recommendationsAnalysis .popularity .min = null ;
97+ this .recommendationsAnalysis .popularity .max = null ;
98+ this .recommendationsAnalysis .interests = [];
99+ this .recommendationsAnalysisDone = false ;
100+ },
101+ },
102+ async created () {
103+ await this .fetchUsers ();
104+ },
105+ deactivated () {
106+ if (! this .$route .path .startsWith (' /users' )) {
107+ this .browseAgain ();
108+ this .fetchUsers ();
109+ this .$el .scrollTop = 0 ;
84110 }
85- this .recommendationsAnalysisDone = true ;
86111 },
87112};
88113
0 commit comments