search improved & bg white & category disabled on search

This commit is contained in:
Meet Patel
2023-07-31 23:03:37 +05:30
parent eed9b6635d
commit 86da5ff2f4
2 changed files with 13 additions and 7 deletions

View File

@@ -45,7 +45,7 @@ export default function TemplateContainerWithPreview({
value={templateSearch ?? ""}
onChange={(e) => setTemplateSearch(e.target.value)}
placeholder={"Search..."}
className="block rounded-md border border-slate-100 bg-slate-50 p-2 shadow-sm focus:border-slate-500 focus:outline-none focus:ring-0 sm:text-sm md:w-auto"
className="block rounded-md border border-slate-100 bg-white p-2 shadow-sm focus:border-slate-500 focus:outline-none focus:ring-0 sm:text-sm md:w-auto"
/>
</div>
</div>

View File

@@ -61,10 +61,15 @@ export default function TemplateList({
setCategories(fullCategories);
const activeFilter =
!!profile?.objective && profile.objective !== "other" ? RECOMMENDED_CATEGORY_NAME : ALL_CATEGORY_NAME;
setSelectedFilter(activeFilter);
}, [profile]);
if (templateSearch && templateSearch.length > 0) {
setSelectedFilter(ALL_CATEGORY_NAME);
} else {
const activeFilter =
!!profile?.objective && profile.objective !== "other" ? RECOMMENDED_CATEGORY_NAME : ALL_CATEGORY_NAME;
setSelectedFilter(activeFilter);
}
}, [profile, templateSearch]);
const addSurvey = async (activeTemplate) => {
setLoading(true);
@@ -90,8 +95,8 @@ export default function TemplateList({
const searchQuery = templateSearch?.toLowerCase() ?? "";
const searchWords = searchQuery.split(" ");
const matchesSearch = searchWords.some(word =>
templateName?.includes(word) || templateDescription?.includes(word)
const matchesSearch = searchWords.every(word =>
(templateName?.includes(word) || templateDescription?.includes(word))
);
return matchesCategory && matchesSearch;
@@ -105,6 +110,7 @@ export default function TemplateList({
key={category}
type="button"
onClick={() => setSelectedFilter(category)}
disabled={templateSearch && templateSearch.length > 0 ? true : false}
className={cn(
selectedFilter === category
? " bg-slate-800 font-semibold text-white"