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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI idea for Genre search scoping #11

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tcbyrd
Copy link
Contributor

@tcbyrd tcbyrd commented Feb 13, 2017

After looking through the search documentation, I noticed that the query (q) parameter had an option to filter results based on genre. To test this out, I started by just typing in genre:jazz in the input field and noticed it worked out of the box! If you are on Song, it only returns songs in that genre. If you are on Artist, it only returns artists in that genre.

The problem is knowing the syntax and what genres to type. When I pulled in the list from the API, there are a total of 126 different genres and they're not all immediately obvious (I had to google pagode for instance 馃槅).

So the initial idea I had was to pull in a random genre as a "Tip!" just below the search box:

random-genre

Every time you refresh the page you get a new genre. And some of those genres may be ones you've never even heard of! Your search is then scoped to that genre.

Example searching for just "Louis":

image

vs Searching for Louis in Genre:Jazz:

image

Thoughts? I think the implementation needs a bit of polish if done this way. Maybe something like how GitHub's repository search UI adds a header to the input field that just says "this repository". So you could lose the genre: part of the syntax and just have an input field add-on with a human readable name of the Genre and a button to randomly pick another genre.

I wasn't 馃挴 sure how to get React to handle this though. I ran into a warning about controlled vs uncontrolled input fields because I was using the seedGenre function to try and modify the data in the input field, but I'm sure there's a workaround there I'm not thinking of.

@cheshire137
Copy link
Owner

I like this idea!

I ran into a warning about controlled vs uncontrolled input fields because I was using the seedGenre function to try and modify the data in the input field

You probably want an onChange and a value property on your input. value can be set to some this.state property, and onChange can be a handler that calls setState. Check out the text input in the PlaylistForm component for an example.

@@ -189,15 +192,21 @@ class SeedSearchForm extends React.Component {
)
}

seedGenre(event) {
const seedInput = document.getElementById("seed")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually it's a red flag if you're using functions like getElementById or querySelector in a React app.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah! I knew it felt wrong to be doing it that way.


import SearchResultArtist from './search-result-artist.jsx'
import SearchResultTrack from './search-result-track.jsx'

const genreValue = "genre:" + Genres.fields[Math.floor(Math.random()*Genres.fields.length)]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about putting this in a function, something like getGenreFilter?

@@ -217,6 +226,7 @@ class SeedSearchForm extends React.Component {
</div>
</div>
{this.seedTypeControls()}
<strong>Tip!</strong> Try a genre search by typing <a onClick={e => this.seedGenre(e)}>{genreValue}</a>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe setGenreFilter as a name. You could also pass genreValue to the function as the second parameter so you don't have to look at the innerHTML.

class Genres {
}

Genres.fields = ['acoustic', 'afrobeat', 'alt-rock', 'alternative', 'ambient',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about values or names?

'sad', 'salsa', 'samba', 'sertanejo', 'show-tunes', 'singer-songwriter', 'ska',
'sleep', 'songwriter', 'soul', 'soundtracks', 'spanish', 'study', 'summer',
'swedish', 'synth-pop', 'tango', 'techno', 'trance', 'trip-hop', 'turkish',
'work-out', 'world-music']
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be better to get the list of genres via a Spotify API call, in case they add/remove some in the future. Was the list available via an endpoint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeh that list came from their API. I need to dig into this a bit more. As I was testing different genres, a handful of them didn't return any results when the filter was applied a day later, so it probably needs to be fetched from the API to even work properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants