Pārlūkot izejas kodu

fix(Home page): filtering stations should use be a 'computed' value

Signed-off-by: Jonathan <theflametrooper@gmail.com>
Jonathan 3 gadi atpakaļ
vecāks
revīzija
d6c29e9476
1 mainītis faili ar 22 papildinājumiem un 22 dzēšanām
  1. 22 22
      frontend/src/pages/Home/index.vue

+ 22 - 22
frontend/src/pages/Home/index.vue

@@ -23,7 +23,7 @@
 					</a>
 				</div>
 				<router-link
-					v-for="(station, index) in filteredStations()"
+					v-for="(station, index) in filteredStations"
 					:key="index"
 					:to="{
 						name: 'station',
@@ -194,7 +194,27 @@ export default {
 			loggedIn: state => state.user.auth.loggedIn,
 			userId: state => state.user.auth.userId,
 			modals: state => state.modals.modals.home
-		})
+		}),
+		filteredStations() {
+			const privacyOrder = ["public", "unlisted", "private"];
+			return this.stations
+				.filter(
+					station =>
+						JSON.stringify(Object.values(station)).indexOf(
+							this.searchQuery
+						) !== -1
+				)
+				.sort(
+					(a, b) =>
+						this.isFavorite(b) - this.isFavorite(a) ||
+						this.isOwner(b) - this.isOwner(a) ||
+						this.isPlaying(b) - this.isPlaying(a) ||
+						a.paused - b.paused ||
+						privacyOrder.indexOf(a.privacy) -
+							privacyOrder.indexOf(b.privacy) ||
+						b.userCount - a.userCount
+				);
+		}
 	},
 	mounted() {
 		io.getSocket(socket => {
@@ -278,26 +298,6 @@ export default {
 			});
 			this.socket.emit("apis.joinRoom", "home", () => {});
 		},
-		filteredStations() {
-			const privacyOrder = ["public", "unlisted", "private"];
-			return this.stations
-				.filter(
-					station =>
-						JSON.stringify(Object.values(station)).indexOf(
-							this.searchQuery
-						) !== -1
-				)
-				.sort(
-					(a, b) =>
-						this.isFavorite(b) - this.isFavorite(a) ||
-						this.isOwner(b) - this.isOwner(a) ||
-						this.isPlaying(b) - this.isPlaying(a) ||
-						a.paused - b.paused ||
-						privacyOrder.indexOf(a.privacy) -
-							privacyOrder.indexOf(b.privacy) ||
-						b.userCount - a.userCount
-				);
-		},
 		isOwner(station) {
 			return station.owner === this.userId;
 		},