Skip to content

Commit

Permalink
A few tweaks to intimate partner violence tile
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Schroer committed Dec 13, 2023
1 parent 886de2f commit f700b4d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
9 changes: 8 additions & 1 deletion app/components/search/SearchResults/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
SearchResults as SearchResultsProps,
} from "react-instantsearch/connectors";
import { whiteLabel } from "utils";
import { CATEGORIES } from "pages/ServiceDiscoveryForm/constants";
import { SearchMap } from "components/search/SearchMap/SearchMap";
import ResultsPagination from "components/search/Pagination/ResultsPagination";
import { Texting } from "components/Texting";
Expand Down Expand Up @@ -44,7 +45,12 @@ const SearchResults = ({

if (!searchResults) return null;

const hits = transformHits(searchResults.hits as unknown as SearchHit[]);
const category = CATEGORIES.find((c) => c.id === categoryId);
const alphabetizeResults = category && category.alphabetizeResults;
const hits = transformHits(
searchResults.hits as unknown as SearchHit[],
alphabetizeResults
);

return (
<div className={styles.searchResultsAndMapContainer}>
Expand Down Expand Up @@ -93,6 +99,7 @@ const SearchResult = ({
const [textingIsOpen, setTextingIsOpen] = useState(false);
const [clinicianActionsIsOpen, setClinicianActionsIsOpen] = useState(false);
const [handoutModalIsOpen, setHandoutModalIsOpen] = useState(false);

type HandoutLanguage = "es" | "tl" | "zh-TW" | "vi" | "ru" | "ar";
const handoutUrl = (hitId: number, language: HandoutLanguage | null) => {
const handoutRoute =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export const SubcategoryRefinements = ({
selectedSubcategories: SelectedSubcategories;
setSelectedSubcategories: (categories: SelectedSubcategories) => void;
}) => {
if (subcategories.length === 0) return null;

// Add generic "See All" element to subcategory array if it is not there yet
if (!subcategories[0] || subcategories[0].id !== seeAllPseudoId) {
subcategories.unshift({ id: seeAllPseudoId, name: "See All" });
Expand Down
12 changes: 10 additions & 2 deletions app/models/SearchHits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ export type SearchHit = ServiceHit | OrganizationHit;
* Transform Algolia search hits such that each hit has a recurringSchedule that
* uses the time helper classes.
*/
export const transformHits = (hits: SearchHit[]) =>
hits.flatMap((hit) => {
export const transformHits = (
hits: SearchHit[],
sortAlphabetically: boolean = false
) => {
const hitsWithSchedule = hits.flatMap((hit) => {
switch (hit.type) {
case "resource":
return {
Expand All @@ -62,3 +65,8 @@ export const transformHits = (hits: SearchHit[]) =>
return [];
}
});

return sortAlphabetically
? hitsWithSchedule.sort((a, b) => (a.name < b.name ? -1 : 1))
: hitsWithSchedule;
};
2 changes: 2 additions & 0 deletions app/pages/ServiceDiscoveryForm/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type Step =

export interface ServiceCategory {
algoliaCategoryName: string;
alphabetizeResults?: boolean;
disableGeoLocation?: boolean;
id: string;
name: string;
Expand Down Expand Up @@ -165,6 +166,7 @@ export const CATEGORIES: Readonly<ServiceCategory[]> = [
},
{
algoliaCategoryName: "Ucsf-intimatepartnerviolence",
alphabetizeResults: true,
disableGeoLocation: true,
id: "2000006",
name: "Intimate Partner Violence Resources",
Expand Down
2 changes: 2 additions & 0 deletions app/pages/UcsfDiscoveryForm/UcsfDiscoveryForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ const Page = () => {
let nextButtonText = "Next: ";
if (nextStepName === "subcategories") {
nextButtonText += "Service Type";
} else if (nextStepName === "eligibilities") {
nextButtonText += "Patient Identity";
} else if (nextStepName === "results") {
nextButtonText += "Show Results";
}
Expand Down

0 comments on commit f700b4d

Please sign in to comment.