Skip to content

Use displayName for order of tune list, and for search by text #118

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

Merged
merged 5 commits into from
Apr 1, 2025

Conversation

JayWearsSocks
Copy link
Contributor

For issue #117

Turns out that the order of appearance in defaultTunes.ts does not affect the order the tunes appear in in the player :)

To fix the ordering, I edited the 'getSortedTuneList' function in state.ts. After considering the "firstInSorting" (for the collections of breaks), it uses displayName if available, and otherwise the regular name as before.

To improve the searching, I edited 'filterPatternList' in patter-list-filter.vue. We search in displayName + name if displayName is available, otherwise only in name.

I ran the server locally:
the order of tunes looks good - and "Sound of da Police" appears under S (after Sheffield before Tequila).
I tried a bunch of search terms, and they all work as expected. For example, you can now find "Sound of da police" by searching for "sound".

export function filterPatternList(state: State, params?: Filter | null): string[] {
params = params || DEFAULT_FILTER;

const ret: string[] = [ ];
const tuneNames = getSortedTuneList(state);
const text = params && params.text.trim().toLowerCase() || "";
for(let i = 0; i < tuneNames.length; i++) {
if(text ? (tuneNames[i].toLowerCase().indexOf(text) != -1) : tuneIsInCategory(state.tunes[tuneNames[i]], params.cat))
const toSearch = tuneSearchText(state, tuneNames[i]);
if(text ? (toSearch.toLowerCase().indexOf(text) != -1) : tuneIsInCategory(state.tunes[tuneNames[i]], params.cat))
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer tuneSearchText to return an array of strings ([...tune.displayName ? [tune.displayName] : [], name]) and do toSearch.some((s) => s.toLowerCase().indexOf(text) != -1). I feel like concatenating the two search strings might lead to unexpected search results in some combinations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah good point!

I've combined the "what to search" and the actual searching into a function; I think that makes it easier to read (it took me a while to figure out what was going on...)

bit of refactoring for readability
@JayWearsSocks JayWearsSocks requested a review from cdauth March 29, 2025 12:35
@cdauth cdauth merged commit 0eaf800 into beatboxjs:main Apr 1, 2025
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.

2 participants