Skip to content

Commit a51a22f

Browse files
committed
Merge pull request #549 from Soundnode/like-from-player
add ability to like from player, closes #259
2 parents 01f40aa + a631e5f commit a51a22f

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

app/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ <h4 id="playerUser" class="player_user" ng-click="goToUser($event)"></h4>
149149
<span class="player_timeCurrent" id="player-timecurrent"></span>
150150
<span class="player_duration" id="player-duration"></span>
151151
</div>
152+
<div class="player_actions">
153+
<span class="player_favorite" ng-click="favorite($event)" ng-if="isSongPlaying">
154+
&nbsp;<i class="fa fa-heart"></i>
155+
</span>
156+
</div>
152157
</div>
153158
<div class="player_controls">
154159
<span class="player_prevSong" ng-click="prevSong($event)">

app/public/js/player/playerCtrl.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
'use strict';
22

3-
app.controller('PlayerCtrl', function ($scope, $rootScope, playerService, queueService, hotkeys, $state, $log, $timeout) {
3+
app.controller('PlayerCtrl', function (
4+
$scope,
5+
$rootScope,
6+
playerService,
7+
queueService,
8+
hotkeys,
9+
$state,
10+
$log,
11+
$timeout,
12+
SCapiService,
13+
notificationFactory
14+
) {
415
$scope.imgPath = 'public/img/temp-playing.png';
516

617
$timeout(function() {
@@ -109,6 +120,34 @@ app.controller('PlayerCtrl', function ($scope, $rootScope, playerService, queueS
109120
$state.go('profile', { id: trackObj.songUserId });
110121
};
111122

123+
$scope.favorite = function($event) {
124+
var userId = $rootScope.userId;
125+
var track = queueService.getTrack();
126+
127+
if ( $event.currentTarget.classList.contains('active') ) {
128+
129+
SCapiService.deleteFavorite(userId, track.songId)
130+
.then(function(status) {
131+
if ( typeof status == "object" ) {
132+
notificationFactory.success("Song removed from likes!");
133+
$event.currentTarget.classList.remove('active');
134+
}
135+
}, function() {
136+
notificationFactory.error("Something went wrong!");
137+
})
138+
} else {
139+
SCapiService.saveFavorite(userId, track.songId)
140+
.then(function(status) {
141+
if ( typeof status == "object" ) {
142+
notificationFactory.success("Song added to likes!");
143+
$event.currentTarget.classList.add('active');
144+
}
145+
}, function(status) {
146+
notificationFactory.error("Something went wrong!");
147+
});
148+
}
149+
};
150+
112151

113152
/*
114153
* Add native media shortcuts

app/public/stylesheets/css/app.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/public/stylesheets/sass/_components/_player.scss

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
white-space: nowrap;
2525
overflow: hidden;
2626
text-overflow: ellipsis;
27-
padding: 13px 10px 0;
27+
padding: 5px 10px 0;
2828
cursor: pointer;
2929
}
3030

@@ -137,6 +137,21 @@
137137
}
138138
}
139139

140+
.player_favorite {
141+
margin: 0 0 0 10px;
142+
143+
.fa {
144+
color: #949599;
145+
font-size: 12px;
146+
}
147+
148+
&.active {
149+
.fa {
150+
color: #f50;
151+
}
152+
}
153+
}
154+
140155
.player_progress {
141156
position: absolute;
142157
top: -20px;

0 commit comments

Comments
 (0)