Minor cleanup and add KeyboardAvoidingView to global search.

This commit is contained in:
Patrick Fic
2025-10-29 10:22:31 -07:00
parent 9c5ee8ed16
commit 0ae416cc90
12 changed files with 129 additions and 51 deletions

View File

@@ -3,7 +3,7 @@ import { useLocalSearchParams } from "expo-router";
import debounce from "lodash/debounce";
import { useCallback, useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { FlatList, View } from "react-native";
import { FlatList, KeyboardAvoidingView, Platform } from "react-native";
import { ActivityIndicator, Icon, Text } from "react-native-paper";
import env from "../../env";
import ErrorDisplay from "../error/error-display";
@@ -40,7 +40,7 @@ export default function GlobalSearch() {
const [error, setError] = useState(null);
const [results, setResults] = useState([]);
const { t } = useTranslation();
// Placeholder: Replace with actual API call (e.g., Apollo client query, REST fetch, Redux saga dispatch)
const performSearch = useCallback(async (query) => {
// Defensive trimr
const q = (query || "").trim();
@@ -57,7 +57,7 @@ export default function GlobalSearch() {
?.filter((hit) => hit._index === "jobs")
.map((hit) => hit._source);
setResults(jobResults);
setResults([...jobResults, { id: "footer-spacer", height: 128 }]);
} else {
setError("No results available. Try again.");
}
@@ -79,23 +79,35 @@ export default function GlobalSearch() {
if (globalSearch === undefined || globalSearch.trim() === "") {
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<KeyboardAvoidingView
behavior={Platform.OS === "ios" ? "padding" : "height"}
style={{
flex: 1,
justifyContent: "center",
alignItems: "center",
}}
>
<Icon size={64} source="cloud-search" />
<Text variant="bodyMedium" style={{ margin: 12, textAlign: "center" }}>
{t("globalsearch.labels.entersearch")}
</Text>
</View>
</KeyboardAvoidingView>
);
}
return (
<View style={{ flex: 1 }}>
{loading && <ActivityIndicator size="large" />}
<KeyboardAvoidingView
style={{ flex: 1 }}
behavior={Platform.OS === "ios" ? "padding" : "height"}
>
{loading && <ActivityIndicator size="large" style={{ margin: 24 }} />}
{error && <ErrorDisplay errorMessage={error} />}
<Text variant="titleSmall" style={{ margin: 12, alignSelf: "center" }}>
{results.length} results found
</Text>
{!loading && (
<Text variant="titleSmall" style={{ margin: 12, alignSelf: "center" }}>
{results.length} results found
</Text>
)}
<FlatList
style={{ flex: 1 }}
@@ -103,6 +115,6 @@ export default function GlobalSearch() {
keyExtractor={(item) => item.id?.toString()}
renderItem={(object) => <JobListItem item={object.item} />}
/>
</View>
</KeyboardAvoidingView>
);
}