Use plural zone names and "Zone:" prefix in search

We were getting away with singular stuff like "Hat" in the filter text for a while, but once it became "Hat you own" it got too weird imo!

Now, we say "Hats" and "Hats you own" in the filter text. We keep the singular in the search suggestion, but with the "Zone:" prefix, which is something I've been wanting anyway. (It should help with the show all suggestions UI coming soon, too.)
This commit is contained in:
Emi Matchu 2021-01-21 16:46:23 -08:00
parent 82c1eefb13
commit 5799c725ff

View file

@ -296,7 +296,7 @@ function getSuggestions(value, query, zoneLabels, isLoggedIn) {
if (query.filterToZoneLabel == null) { if (query.filterToZoneLabel == null) {
for (const zoneLabel of zoneLabels) { for (const zoneLabel of zoneLabels) {
if (wordMatches(zoneLabel, lastWord)) { if (wordMatches(zoneLabel, lastWord)) {
suggestions.push({ zoneLabel, text: zoneLabel }); suggestions.push({ zoneLabel, text: `Zone: ${zoneLabel}` });
} }
} }
} }
@ -316,7 +316,7 @@ function getQueryFilterText(query) {
} }
if (query.filterToZoneLabel) { if (query.filterToZoneLabel) {
textWords.push(query.filterToZoneLabel); textWords.push(pluralizeZoneLabel(query.filterToZoneLabel));
} }
if (query.filterToCurrentUserOwnsOrWants === "OWNS") { if (query.filterToCurrentUserOwnsOrWants === "OWNS") {
@ -334,4 +334,20 @@ function getQueryFilterText(query) {
return textWords.join(" "); return textWords.join(" ");
} }
/**
* pluralizeZoneLabel hackily tries to convert a zone name to a plural noun!
*
* HACK: It'd be more reliable and more translatable to do this by just
* manually creating the plural for each zone. But, ehh! ¯\_ ()_/¯
*/
function pluralizeZoneLabel(zoneLabel) {
if (zoneLabel.endsWith("ss")) {
return zoneLabel + "es";
} else if (zoneLabel.endsWith("s")) {
return zoneLabel;
} else {
return zoneLabel + "s";
}
}
export default SearchToolbar; export default SearchToolbar;