From 5799c725ff868ae77415e8bc4a60d2b13058b821 Mon Sep 17 00:00:00 2001 From: Matchu Date: Thu, 21 Jan 2021 16:46:23 -0800 Subject: [PATCH] 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.) --- src/app/WardrobePage/SearchToolbar.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/app/WardrobePage/SearchToolbar.js b/src/app/WardrobePage/SearchToolbar.js index 8571eba..626af13 100644 --- a/src/app/WardrobePage/SearchToolbar.js +++ b/src/app/WardrobePage/SearchToolbar.js @@ -296,7 +296,7 @@ function getSuggestions(value, query, zoneLabels, isLoggedIn) { if (query.filterToZoneLabel == null) { for (const zoneLabel of zoneLabels) { 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) { - textWords.push(query.filterToZoneLabel); + textWords.push(pluralizeZoneLabel(query.filterToZoneLabel)); } if (query.filterToCurrentUserOwnsOrWants === "OWNS") { @@ -334,4 +334,20 @@ function getQueryFilterText(query) { 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;