From bb9df1a48f63c5ec1a3da4854d8777a3eaabc75e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Camblor?= Date: Thu, 31 Oct 2024 00:33:58 +0100 Subject: [PATCH] #74 implemented speakers search --- mobile/src/models/VoxxrinSpeaker.ts | 15 +++++++++++++++ mobile/src/state/useEventSpeakers.ts | 11 +++++++---- mobile/src/views/event/SpeakersDirectoryPage.vue | 7 +++---- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/mobile/src/models/VoxxrinSpeaker.ts b/mobile/src/models/VoxxrinSpeaker.ts index 27e8191b..4538e907 100644 --- a/mobile/src/models/VoxxrinSpeaker.ts +++ b/mobile/src/models/VoxxrinSpeaker.ts @@ -64,3 +64,18 @@ export const createVoxxrinSpeakerFromFirestore = (conferenceDescriptor: VoxxrinC }) } } + +export const speakerMatchesSearchTerms = (speaker: VoxxrinLineupSpeaker, searchTerms: string|undefined): boolean => { + if(!searchTerms) { + return true; + } + + const speakerSearchableContent = ` + ${speaker.fullName} + ${speaker.companyName || ''} + ${speaker.bio} + ${speaker.talks.map(talk => `${talk.title} ${talk.format.title} ${talk.track.title}`).join("\n")} + `.toLowerCase() + + return searchTerms.split(" ").every(searchTerm => speakerSearchableContent.includes(searchTerm.toLowerCase())); +} diff --git a/mobile/src/state/useEventSpeakers.ts b/mobile/src/state/useEventSpeakers.ts index 5b8ae240..0953d860 100644 --- a/mobile/src/state/useEventSpeakers.ts +++ b/mobile/src/state/useEventSpeakers.ts @@ -5,11 +5,11 @@ import {collection, CollectionReference, doc, DocumentReference} from "firebase/ import {db} from "@/state/firebase"; import {resolvedEventFirestorePath} from "../../../shared/utilities/event-utils"; import {LineupSpeaker} from "../../../shared/event-lineup.firestore"; -import {createVoxxrinSpeakerFromFirestore} from "@/models/VoxxrinSpeaker"; +import {createVoxxrinSpeakerFromFirestore, speakerMatchesSearchTerms} from "@/models/VoxxrinSpeaker"; import {match} from "ts-pattern"; import {sortBy} from "@/models/utils"; -export function useLineupSpeakers(eventDescriptorRef: Ref) { +export function useLineupSpeakers(eventDescriptorRef: Ref, searchTermsRef: Ref) { const firestoreSpeakersRef = deferredVuefireUseCollection([ eventDescriptorRef ], ([eventDescriptor]) => eventLineupSpeakersCollections(eventDescriptor), @@ -27,14 +27,17 @@ export function useLineupSpeakers(eventDescriptorRef: Ref { const firestoreSpeakersLineup = toValue(firestoreSpeakersRef), - eventDescriptor = toValue(eventDescriptorRef); + eventDescriptor = toValue(eventDescriptorRef), + searchTerms = toValue(searchTermsRef); if(!firestoreSpeakersLineup || !eventDescriptor) { return undefined; } const speakers = sortBy( - [...firestoreSpeakersLineup.values()].map(fSpeaker => createVoxxrinSpeakerFromFirestore(eventDescriptor, fSpeaker)), + [...firestoreSpeakersLineup.values()] + .map(fSpeaker => createVoxxrinSpeakerFromFirestore(eventDescriptor, fSpeaker)) + .filter(speaker => speakerMatchesSearchTerms(speaker, searchTerms)), sp => sp.fullName ); return speakers; diff --git a/mobile/src/views/event/SpeakersDirectoryPage.vue b/mobile/src/views/event/SpeakersDirectoryPage.vue index 80a9505d..e587ea1b 100644 --- a/mobile/src/views/event/SpeakersDirectoryPage.vue +++ b/mobile/src/views/event/SpeakersDirectoryPage.vue @@ -46,7 +46,9 @@ const spacedEventIdRef = useCurrentSpaceEventIdRef(); const {conferenceDescriptor: confDescriptor} = useSharedConferenceDescriptor(spacedEventIdRef); const { triggerTabbedPageNavigate } = useTabbedPageNav(); - const { speakers } = useLineupSpeakers(confDescriptor) + + const searchTermsRef = ref(undefined); + const { speakers } = useLineupSpeakers(confDescriptor, searchTermsRef) const baseUrl = import.meta.env.BASE_URL; @@ -57,9 +59,6 @@ { id: "compact", icon: list, label: LL.value.Compact_list_mode(), preSelected: true }, ] as const - const searchTermsRef = ref(undefined); - // TODO: take searchTermsRef into consideration when looking for speakers/talks - async function openSpeakerDetails(speaker: VoxxrinSimpleSpeaker) { if(speaker) { // TODO: Re-enable this once *tabbed* talk details as feedback viewer routing has been fixed