-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #181 from heatherpark/style/code-cleanup
(refactor) Clean up code for landing page and mixtape search
- Loading branch information
Showing
22 changed files
with
153 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
.text { | ||
font-style: italic; | ||
margin-bottom: 25px; | ||
text-transform: none; | ||
width: 470px; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/** components **/ | ||
export { SoundCloudSearchComponent } from './search.component'; | ||
export { SoundCloudSearchInputComponent } from './search-input.component'; | ||
export { SoundCloudSearchResultsComponent } from './search-results.component'; | ||
export { SoundCloudSearchInputComponent } from './input/search-input.component'; | ||
export { SoundCloudSearchResultsComponent } from './results/search-results.component'; | ||
|
||
/** services **/ | ||
export { SearchSoundCloud } from './search.service'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** components **/ | ||
export { SoundCloudSearchInputComponent } from './search-input.component'; | ||
|
||
/** models **/ | ||
export { SearchParams } from './search-params.model'; |
6 changes: 3 additions & 3 deletions
6
...mixtape/search/search-input.component.css → ...e/search/input/search-input.component.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Component, EventEmitter, OnInit, Output } from '@angular/core'; | ||
import 'rxjs/Rx'; | ||
|
||
import { SearchParams } from './index'; | ||
import { SearchSoundCloud } from '../search.service'; | ||
import { Store } from '../../../store/store'; | ||
|
||
@Component({ | ||
selector: 'sc-search-input', | ||
templateUrl: 'app/mixtape/search/input/search-input.component.html', | ||
styleUrls: ['app/mixtape/search/input/search-input.component.css'], | ||
providers: [SearchSoundCloud] | ||
}) | ||
export class SoundCloudSearchInputComponent implements OnInit { | ||
resultMax: number; | ||
search: SearchParams; | ||
|
||
constructor(private store: Store, | ||
private searchSoundCloud: SearchSoundCloud) {} | ||
|
||
// SearchSoundCloud service makes POST request to server | ||
// upon receiving search results via SoundCloud API, update state | ||
onSubmit(searchParams: SearchParams) { | ||
if (this.search.q) { | ||
this.searchSoundCloud.search(searchParams) | ||
.subscribe( | ||
this.resultsHandler.bind(this), | ||
error => console.log('error: ', error)); | ||
} | ||
this.search.q = ''; | ||
} | ||
|
||
ngOnInit() { | ||
this.resultMax = 30; | ||
this.search = { | ||
q: '', | ||
limit: this.resultMax | ||
}; | ||
} | ||
|
||
resultsHandler(results) { | ||
const currentState = this.store.getState(); | ||
results = JSON.parse(results._body); | ||
|
||
this.store.setState( | ||
Object.assign({}, currentState, { | ||
mixtape: { | ||
playlist: currentState.mixtape.playlist, | ||
// update 'searchResults' | ||
searchResults: results | ||
} | ||
}) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export class SearchParams { | ||
q: string; | ||
limit: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/** components **/ | ||
export { SoundCloudSearchResultsComponent } from './search-results.component'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
56 changes: 56 additions & 0 deletions
56
src/app/mixtape/search/results/search-results.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Component } from '@angular/core'; | ||
import { Observable } from 'rxjs/Observable'; | ||
import 'rxjs/Rx'; | ||
|
||
import { PlaylistService } from '../../shared/index'; | ||
import { Song } from '../../shared/index'; | ||
import { Store } from '../../../store/store'; | ||
|
||
@Component({ | ||
selector: 'sc-search-results', | ||
templateUrl: 'app/mixtape/search/results/search-results.component.html', | ||
styleUrls: ['app/mixtape/search/results/search-results.component.css'], | ||
providers: [PlaylistService] | ||
}) | ||
export class SoundCloudSearchResultsComponent { | ||
searchResults: Observable<Song[]>; | ||
|
||
constructor(private store: Store, | ||
private playlistService: PlaylistService) { | ||
// listen for 'searchResults' state changes | ||
// update 'this.searchResults' accordingly | ||
this.store | ||
.changes | ||
.pluck('mixtape', 'searchResults') | ||
.subscribe( | ||
(searchResults: Observable<Song[]>) => this.searchResults = searchResults, | ||
error => console.log('error: ', error)); | ||
} | ||
|
||
// add song to playlist in database via POST request | ||
// change 'playlist' state upon adding song | ||
addSong(songData) { | ||
this.playlistService.addToPlaylist(songData) | ||
.subscribe( | ||
this.addSongToPlaylistState.bind(this), | ||
error => console.log('error: ', error)); | ||
} | ||
|
||
addSongToPlaylistState(song) { | ||
const currentState = this.store.getState(); | ||
song = [JSON.parse(song._body)]; | ||
|
||
this.store.setState( | ||
Object.assign({}, currentState, { | ||
mixtape: { | ||
// add new song to 'playlist' state | ||
playlist: [ | ||
...currentState.mixtape.playlist, | ||
...song | ||
], | ||
searchResults: currentState.mixtape.searchResults | ||
} | ||
}) | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** services **/ | ||
export { PlaylistService } from './playlist.service'; | ||
|
||
/** interfaces **/ | ||
export { Song } from './song'; | ||
/** models **/ | ||
export { Song } from './song.model'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.