Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some suggested changes #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/app/dropdowns/dropdowns.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { Http, Response } from '@angular/http';
import arrayShuffler from '../../helpers/array-shuffler';
import arrayShuffler from '../helpers/array-shuffler';

@Component({
selector: 'app-dropdowns',
Expand All @@ -24,6 +24,7 @@ export class DropdownsComponent implements OnInit {
// this.firmnessCheeses = firmnessCheeses;
}

// I would like to see this call moved to a service and injected using dependency injection.
getAnimal(animal) {
const animalURL = 'http://cheeswhiz.herokuapp.com/api/cheese/animal/';
this.http.get(animalURL + animal)
Expand All @@ -34,6 +35,7 @@ export class DropdownsComponent implements OnInit {
});
}

// I would like to see this call moved to a service and injected using dependency injection.
getFirmness(firmness) {
const firmnessURL = 'http://cheeswhiz.herokuapp.com/api/cheese/firmness/';
this.http.get(firmnessURL + firmness)
Expand Down
11 changes: 11 additions & 0 deletions src/app/helpers/array-shuffler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//helper function to shuffle an array
// moved this file inside your src folder.
export default function arrayShuffler( array ) {
for ( let i = array.length - 1; i > 0; i-- ) {
let j = Math.floor( Math.random() * ( i + 1 ) );
let temp = array[ i ];
array[ i ] = array[ j ];
array[ j ] = temp;
}
return array;
}
19 changes: 10 additions & 9 deletions src/app/player/player.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { Http, Response } from '@angular/http';
import { DomSanitizer, SafeResourceUrl, SafeUrl } from '@angular/platform-browser';
import arrayShuffler from '../../helpers/array-shuffler';
import arrayShuffler from '../helpers/array-shuffler';


@Component({
Expand All @@ -27,15 +27,15 @@ export class PlayerComponent implements OnInit {
this.playlists = [];
this.url = 'https://embed.spotify.com/?uri=';
}

// this call can also be moved to a different service and injected using dependency injection
getSpotify() {
this.loading = true;
let query = 'jazz blues';
let urlR = `https://api.spotify.com/v1/search?q=${query}&type=playlist&market=US&limit=50`;
const query = 'jazz blues';
const urlR = `https://api.spotify.com/v1/search?q=${query}&type=playlist&market=US&limit=50`;
return this.http.get(urlR)
.subscribe((res: Response) => {
let rObj = res.json();
let pArray = rObj.playlists.items;
const rObj = res.json();
const pArray = rObj.playlists.items;
this.playlists = pArray.map((element) => {
return element.uri;
});
Expand All @@ -46,19 +46,20 @@ export class PlayerComponent implements OnInit {

nextPlaylist() {
this.loading = true;
if(this.count === 49) {
if ( this.count === 49 ) {
this.count = -1;
}
this.count++;
let tempUrl = this.url + this.playlists[this.count];
const tempUrl = this.url + this.playlists[this.count];
this.spotify = this.sanitizer.bypassSecurityTrustResourceUrl(tempUrl);
setTimeout(() => {
this.loading = false;
}, 1500);
}

ngOnInit() {
this.spotify = this.sanitizer.bypassSecurityTrustResourceUrl('https://embed.spotify.com/?uri=spotify:user:gita1503:playlist:2qkXmULVYKfaQVLYQiuMJA');
this.spotify = this.sanitizer
.bypassSecurityTrustResourceUrl('https://embed.spotify.com/?uri=spotify:user:gita1503:playlist:2qkXmULVYKfaQVLYQiuMJA');
this.getSpotify();
}

Expand Down
10 changes: 0 additions & 10 deletions src/helpers/array-shuffler.js

This file was deleted.

Loading