diff --git a/src/features/search/components/SearchResultList.tsx b/src/features/search/components/SearchResultList.tsx
index bf4a046..a6f8e49 100644
--- a/src/features/search/components/SearchResultList.tsx
+++ b/src/features/search/components/SearchResultList.tsx
@@ -1,12 +1,300 @@
import React from "react";
-import { ActivityIndicator, FlatList, Pressable, StyleSheet, Text, View } from "react-native";
+import {
+ ActivityIndicator,
+ FlatList,
+ Pressable,
+ ScrollView,
+ StyleSheet,
+ Text,
+ View,
+} from "react-native";
import { Ionicons } from "@expo/vector-icons";
import { Colors } from "@/theme";
-import type { FacetedSearchItem } from "../types/search.types";
+import type { FacetedSearchItem, SearchModuleOption } from "../types/search.types";
-interface Props { items: FacetedSearchItem[]; total: number; loading: boolean; fetchingMore: boolean; onLoadMore:()=>void; onPress:(item:FacetedSearchItem)=>void; }
-export function SearchResultList({items,total,loading,fetchingMore,onLoadMore,onPress}:Props){
- if(loading&&!items.length) return Searching content…;
- return item.content_id} contentContainerStyle={items.length?styles.list:styles.empty} ListHeaderComponent={items.length?{total} result{total===1?"":"s"}:null} renderItem={({item})=>onPress(item)} style={({pressed})=>[styles.card,pressed&&styles.pressed]}>{item.title}{item.module_name} · {item.template_name}{item.summary?{item.summary}:null}} ListEmptyComponent={No matching contentTry a broader scope or remove one of the filters.} ListFooterComponent={fetchingMore?:null} onEndReached={onLoadMore} onEndReachedThreshold={.35}/>;
+interface Props {
+ items: FacetedSearchItem[];
+ total: number;
+ loading: boolean;
+ fetchingMore: boolean;
+ onLoadMore: () => void;
+ onPress: (item: FacetedSearchItem) => void;
+ matchingModules?: SearchModuleOption[];
+ onSelectModule?: (module: SearchModuleOption) => void;
+ activeModuleCode?: string | null;
}
-const styles=StyleSheet.create({list:{paddingHorizontal:20,paddingBottom:28},empty:{flexGrow:1},count:{paddingVertical:9,fontSize:12,fontWeight:"700",color:Colors.textSecondary},card:{flexDirection:"row",alignItems:"center",gap:12,padding:15,marginBottom:10,borderRadius:16,backgroundColor:Colors.white,borderWidth:1,borderColor:"#EEF0F2",shadowColor:"#000",shadowOpacity:.05,shadowRadius:6,shadowOffset:{width:0,height:2},elevation:1},pressed:{opacity:.75},cardText:{flex:1},title:{fontSize:16,fontWeight:"800",color:Colors.textPrimary},meta:{marginTop:3,fontSize:11.5,fontWeight:"600",color:Colors.primaryDark},summary:{marginTop:6,fontSize:12.5,lineHeight:18,color:Colors.textSecondary},center:{flex:1,alignItems:"center",justifyContent:"center",padding:32},emptyTitle:{marginTop:8,fontSize:16,fontWeight:"800",color:Colors.textPrimary},muted:{marginTop:5,textAlign:"center",fontSize:12.5,color:Colors.textSecondary}});
+
+export function SearchResultList({
+ items,
+ total,
+ loading,
+ fetchingMore,
+ onLoadMore,
+ onPress,
+ matchingModules = [],
+ onSelectModule,
+ activeModuleCode,
+}: Props) {
+ if (loading && !items.length && !matchingModules.length) {
+ return (
+
+
+ Searching content…
+
+ );
+ }
+
+ const headerComponent = (
+
+ {matchingModules.length > 0 ? (
+
+
+ Matching Modules ({matchingModules.length})
+
+
+ {matchingModules.map((mod) => {
+ const isActive = activeModuleCode === mod.code;
+ return (
+ onSelectModule?.(mod)}
+ >
+
+
+
+
+
+ {mod.name}
+
+
+ {isActive ? "Filtered" : "Filter by module"}
+
+
+
+
+ );
+ })}
+
+
+ ) : null}
+
+ {items.length > 0 ? (
+
+ {total} result{total === 1 ? "" : "s"}
+
+ ) : null}
+
+ );
+
+ return (
+ item.content_id}
+ contentContainerStyle={items.length ? styles.list : styles.empty}
+ ListHeaderComponent={headerComponent}
+ renderItem={({ item }) => (
+ onPress(item)}
+ style={({ pressed }) => [styles.card, pressed && styles.pressed]}
+ >
+
+ {item.title}
+
+ {item.module_name} · {item.template_name}
+
+ {item.summary ? (
+
+ {item.summary}
+
+ ) : null}
+
+
+
+ )}
+ ListEmptyComponent={
+ !loading ? (
+
+
+ No matching content
+
+ Try a broader search term or remove one of the filters.
+
+
+ ) : null
+ }
+ ListFooterComponent={
+ fetchingMore ? (
+
+ ) : null
+ }
+ onEndReached={onLoadMore}
+ onEndReachedThreshold={0.35}
+ />
+ );
+}
+
+const styles = StyleSheet.create({
+ list: {
+ paddingHorizontal: 20,
+ paddingBottom: 28,
+ },
+ empty: {
+ flexGrow: 1,
+ paddingHorizontal: 20,
+ },
+ headerWrapper: {
+ paddingBottom: 4,
+ },
+ modulesSection: {
+ marginBottom: 12,
+ marginTop: 6,
+ },
+ modulesHeading: {
+ fontSize: 12,
+ fontWeight: "800",
+ color: Colors.textSecondary,
+ textTransform: "uppercase",
+ marginBottom: 8,
+ letterSpacing: 0.5,
+ },
+ modulesScroll: {
+ gap: 8,
+ paddingRight: 10,
+ },
+ moduleCard: {
+ flexDirection: "row",
+ alignItems: "center",
+ gap: 8,
+ paddingVertical: 8,
+ paddingHorizontal: 12,
+ borderRadius: 12,
+ backgroundColor: "#F3F7F5",
+ borderWidth: 1,
+ borderColor: "#E2ECE6",
+ },
+ moduleCardActive: {
+ backgroundColor: Colors.primary,
+ borderColor: Colors.primary,
+ },
+ moduleIconBox: {
+ justifyContent: "center",
+ alignItems: "center",
+ },
+ moduleTextContainer: {
+ maxWidth: 180,
+ },
+ moduleName: {
+ fontSize: 13,
+ fontWeight: "700",
+ color: Colors.textPrimary,
+ },
+ moduleNameActive: {
+ color: Colors.white,
+ },
+ moduleBadge: {
+ fontSize: 10,
+ color: Colors.textSecondary,
+ marginTop: 1,
+ },
+ moduleBadgeActive: {
+ color: "rgba(255,255,255,0.85)",
+ },
+ count: {
+ paddingVertical: 9,
+ fontSize: 12,
+ fontWeight: "700",
+ color: Colors.textSecondary,
+ },
+ card: {
+ flexDirection: "row",
+ alignItems: "center",
+ gap: 12,
+ padding: 15,
+ marginBottom: 10,
+ borderRadius: 16,
+ backgroundColor: Colors.white,
+ borderWidth: 1,
+ borderColor: "#EEF0F2",
+ shadowColor: "#000",
+ shadowOpacity: 0.05,
+ shadowRadius: 6,
+ shadowOffset: { width: 0, height: 2 },
+ elevation: 1,
+ },
+ pressed: {
+ opacity: 0.75,
+ },
+ cardText: {
+ flex: 1,
+ },
+ title: {
+ fontSize: 16,
+ fontWeight: "800",
+ color: Colors.textPrimary,
+ },
+ meta: {
+ marginTop: 3,
+ fontSize: 11.5,
+ fontWeight: "600",
+ color: Colors.primaryDark,
+ },
+ summary: {
+ marginTop: 6,
+ fontSize: 12.5,
+ lineHeight: 18,
+ color: Colors.textSecondary,
+ },
+ center: {
+ flex: 1,
+ alignItems: "center",
+ justifyContent: "center",
+ padding: 32,
+ },
+ emptyTitle: {
+ marginTop: 8,
+ fontSize: 16,
+ fontWeight: "800",
+ color: Colors.textPrimary,
+ },
+ muted: {
+ marginTop: 5,
+ textAlign: "center",
+ fontSize: 12.5,
+ color: Colors.textSecondary,
+ },
+});
diff --git a/src/features/search/hooks/use-faceted-search.ts b/src/features/search/hooks/use-faceted-search.ts
index f87636e..f86d7aa 100644
--- a/src/features/search/hooks/use-faceted-search.ts
+++ b/src/features/search/hooks/use-faceted-search.ts
@@ -1,4 +1,4 @@
-import { useInfiniteQuery } from "@tanstack/react-query";
+import { keepPreviousData, useInfiniteQuery } from "@tanstack/react-query";
import { useSettingsStore } from "@/store/settings.store";
import { searchContents } from "../api/search.api";
import type { FacetedSearchRequest } from "../types/search.types";
@@ -24,8 +24,10 @@ export function useFacetedSearch(
queryFn: ({ pageParam }) =>
searchContents({ ...request, page: pageParam }, preview),
initialPageParam: 1,
+ placeholderData: keepPreviousData,
enabled,
getNextPageParam: (last) =>
last.page * last.page_size < last.total ? last.page + 1 : undefined,
});
}
+
diff --git a/src/features/search/screens/FacetedSearchScreen.tsx b/src/features/search/screens/FacetedSearchScreen.tsx
index f968b68..3d31cd1 100644
--- a/src/features/search/screens/FacetedSearchScreen.tsx
+++ b/src/features/search/screens/FacetedSearchScreen.tsx
@@ -1,4 +1,4 @@
-import React, { useEffect, useMemo, useState } from "react";
+import React, { useCallback, useEffect, useMemo, useState } from "react";
import { Platform, Pressable, StyleSheet, Text, TextInput, View } from "react-native";
import { SafeAreaView } from "react-native-safe-area-context";
import { Ionicons } from "@expo/vector-icons";
@@ -18,6 +18,7 @@ import type {
FacetFilter,
FilterLogic,
SearchFacetDefinition,
+ SearchModuleOption,
SearchScope,
} from "../types/search.types";
@@ -147,6 +148,38 @@ export default function FacetedSearchScreen({
);
};
+ const matchingModules = useMemo(() => {
+ const q = (debouncedQuery || query).trim().toLowerCase();
+ if (!q || isModuleMode || !capabilities.data?.modules) return [];
+ const tokens = q.split(/\s+/).filter(Boolean);
+ return capabilities.data.modules.filter((m) => {
+ const name = m.name.toLowerCase();
+ const code = m.code.toLowerCase();
+ if (name.includes(q) || code.includes(q)) return true;
+ return tokens.some(
+ (tok) => tok.length >= 2 && (name.includes(tok) || code.includes(tok)),
+ );
+ });
+ }, [debouncedQuery, query, isModuleMode, capabilities.data?.modules]);
+
+ const activeModuleCode = useMemo(() => {
+ return effectiveScope.module_codes?.length === 1
+ ? effectiveScope.module_codes[0]
+ : null;
+ }, [effectiveScope.module_codes]);
+
+ const handleToggleModuleScope = useCallback(
+ (module: SearchModuleOption) => {
+ const currentCodes = effectiveScope.module_codes ?? [];
+ const isAlreadySelected = currentCodes.includes(module.code);
+ handleScopeChange({
+ ...effectiveScope,
+ module_codes: isAlreadySelected ? null : [module.code],
+ });
+ },
+ [effectiveScope, handleScopeChange],
+ );
+
return (
@@ -285,6 +318,9 @@ export default function FacetedSearchScreen({
total={merged.total}
loading={capabilities.isLoading || search.isLoading}
fetchingMore={search.isFetchingNextPage}
+ matchingModules={matchingModules}
+ onSelectModule={handleToggleModuleScope}
+ activeModuleCode={activeModuleCode}
onLoadMore={() => {
if (search.hasNextPage && !search.isFetchingNextPage) {
void search.fetchNextPage();