Skip to content

Commit

Permalink
Different solution for reversing arrays added
Browse files Browse the repository at this point in the history
  • Loading branch information
Ascensionist committed Aug 15, 2024
1 parent d1081aa commit 2476176
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
8 changes: 7 additions & 1 deletion app/client/src/components/LibraryAlbums.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ export default {
},
async reverseSort() {
this.isReversed = !this.isReversed;
this.albums.reverse();
var half = Math.floor(this.albums.length / 2);
for (var i = 0; i < half; i++) {
var temp = this.albums[this.albums.length - 1 - i];
this.albums[this.albums.length - 1 - i] = this.albums[i];
this.albums[i] = temp;
}
},
},
mounted() {
Expand Down
8 changes: 7 additions & 1 deletion app/client/src/components/LibraryArtists.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,13 @@ export default {
},
async reverseSort() {
this.isReversed = !this.isReversed;
this.artists.reverse();
var half = Math.floor(this.artists.length / 2);
for (var i = 0; i < half; i++) {
var temp = this.artists[this.artists.length - 1 - i];
this.artists[this.artists.length - 1 - i] = this.artists[i];
this.artists[i] = temp;
}
}
},
mounted() {
Expand Down
8 changes: 7 additions & 1 deletion app/client/src/components/LibraryPlaylists.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,13 @@ export default {
},
async reverseSort() {
this.isReversed = !this.isReversed;
this.playlists.reverse();
var half = Math.floor(this.playlists.length / 2);
for (var i = 0; i < half; i++) {
var temp = this.playlists[this.playlists.length - 1 - i];
this.playlists[this.playlists.length - 1 - i] = this.playlists[i];
this.playlists[i] = temp;
}
},
},
mounted() {
Expand Down
11 changes: 9 additions & 2 deletions app/client/src/components/LibraryTracks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,17 @@ export default {
},
async reverseSort() {
//Preload tracks if not sorted yet
if (this.tracks.length < this.count)
if (this.tracks.length < this.count) {
await this.sort(0);
}
this.isReversed = !this.isReversed;
this.tracks.reverse();
var half = Math.floor(this.tracks.length / 2);
for (var i = 0; i < half; i++) {
var temp = this.tracks[this.tracks.length - 1 - i];
this.tracks[this.tracks.length - 1 - i] = this.tracks[i];
this.tracks[i] = temp;
}
},
removedTrack(id) {
this.tracks.splice(this.tracks.findIndex(t => t.id == id), 1);
Expand Down
8 changes: 7 additions & 1 deletion app/client/src/views/PlaylistPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,13 @@ export default {
if (this.playlist.tracks.length < this.playlist.trackCount)
await this.sort(0);
this.isReversed = !this.isReversed;
this.playlist.tracks.reverse();
var half = Math.floor(this.playlist.tracks.length / 2);
for (var i = 0; i < half; i++) {
var temp = this.playlist.tracks[this.playlist.tracks.length - 1 - i];
this.playlist.tracks[this.playlist.tracks.length - 1 - i] = this.playlist.tracks[i];
this.playlist.tracks[i] = temp;
}
},
},
mounted() {
Expand Down

0 comments on commit 2476176

Please sign in to comment.