Browse Source

Worked on dynamic homepage stations.

KrisVos130 8 years ago
parent
commit
8b84eac86c

+ 9 - 1
backend/logic/actions/apis.js

@@ -1,7 +1,8 @@
 'use strict';
 
 const request = require('request'),
-	  config  = require('config');
+	  config  = require('config'),
+		utils = require('../utils');
 
 module.exports = {
 
@@ -32,6 +33,13 @@ module.exports = {
 
 			cb({ status: 'success', data: JSON.parse(body) });
 		});
+	},
+
+	joinRoom: (sessionId, page, cb) => {
+		if (page === 'home') {
+			utils.socketJoinRoom(sessionId, page);
+		}
+		cb({});
 	}
 
 };

+ 10 - 4
backend/logic/actions/stations.js

@@ -16,6 +16,8 @@ const defaultSong = {
 	artists: ['Alan Walker'],
 	duration: 212,
 	skipDuration: 0,
+	likes: 0,
+	dislikes: 0,
 	thumbnail: 'https://i.scdn.co/image/2ddde58427f632037093857ebb71a67ddbdec34b'
 };
 
@@ -36,8 +38,11 @@ cache.sub('station.resume', (stationName) => {
 });
 
 cache.sub('station.create', (stationId) => {
-	stations.initializeAndReturnStation(stationId, () => {
+	stations.initializeAndReturnStation(stationId, (err, station) => {
 		//TODO Emit to homepage and admin station page
+		if (!err) {
+			io.io.to('home').emit("event:stations.created", station);
+		}
 	});
 });
 
@@ -230,9 +235,10 @@ module.exports = {
 		], (err, station) => {
 			console.log(err, 123986);
 			if (err) return cb(err);
-			stations.calculateSongForStation(station);
-			cache.pub('station.create', data.name);
-			return cb(null, { 'status': 'success', 'message': 'Successfully created station.' });
+			stations.calculateSongForStation(station, () => {
+				cache.pub('station.create', data.name);
+				return cb(null, { 'status': 'success', 'message': 'Successfully created station.' });
+			});
 		});
 	},
 

+ 6 - 4
frontend/components/pages/Home.vue

@@ -5,7 +5,7 @@
 			<div class="group-title">Official Stations</div>
 			<div class="group-stations">
 				<div class="stations-station" v-for="station in stations.official" v-link="{ path: '/official/' + station._id }" @click="this.$dispatch('joinStation', station._id)">
-					<img class="station-image" :src="station.playlist[station.currentSongIndex].thumbnail" />
+					<img class="station-image" :src="station.currentSong.thumbnail" />
 					<div class="station-info">
 						<div class="station-grid-left">
 							<h3>{{ station.displayName }}</h3>
@@ -22,7 +22,7 @@
 			<div class="group-title">Community Stations</div>
 			<div class="group-stations">
 				<div class="stations-station" v-for="station in stations.community" v-link="{ path: '/community/' + station._id }" @click="this.$dispatch('joinStation', station._id)">
-					<img class="station-image" :src="station.playlist[station.currentSongIndex].thumbnail" />
+					<img class="station-image" :src="station.currentSong.thumbnail" />
 					<div class="station-info">
 						<div class="station-grid-left">
 							<h3>{{ station.displayName }}</h3>
@@ -69,8 +69,10 @@
 							else _this.stations.community.push(station);
 						});
 					});
-					_this.socket.emit("");
-					_this.socket.on("");
+					_this.socket.emit("apis.joinRoom", 'home', () => {});
+					_this.socket.on('event:stations.created', (station) => {
+						_this.stations[station.type].push(station);
+					});
 					clearInterval(socketInterval);
 				}
 			}, 100);