Refactor to using RNP & UI Updates.
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { useQuery } from "@apollo/client";
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FlatList, RefreshControl } from "react-native";
|
||||
import { Button, List, Modal, Portal, Provider } from "react-native-paper";
|
||||
import { FlatList, RefreshControl, View } from "react-native";
|
||||
import { Button, List, Modal, Portal, Searchbar } from "react-native-paper";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { QUERY_ALL_ACTIVE_JOBS } from "../../graphql/jobs.queries";
|
||||
@@ -47,23 +48,80 @@ export function CameraSelectJob({
|
||||
|
||||
const showModal = () => setVisible(true);
|
||||
const hideModal = () => setVisible(false);
|
||||
const containerStyle = { backgroundColor: "white", padding: 20 };
|
||||
|
||||
const onRefresh = async () => {
|
||||
return refetch();
|
||||
};
|
||||
const [searchQuery, setSearchQuery] = React.useState("");
|
||||
|
||||
const onChangeSearch = (query) => setSearchQuery(query);
|
||||
|
||||
const jobs = data
|
||||
? searchQuery === ""
|
||||
? data.jobs
|
||||
: data.jobs.filter(
|
||||
(j) =>
|
||||
(j.ro_number || "")
|
||||
.toString()
|
||||
.toLowerCase()
|
||||
.includes(searchQuery.toLowerCase()) ||
|
||||
(j.ownr_co_nm || "")
|
||||
.toLowerCase()
|
||||
.includes(searchQuery.toLowerCase()) ||
|
||||
(j.ownr_fn || "")
|
||||
.toLowerCase()
|
||||
.includes(searchQuery.toLowerCase()) ||
|
||||
(j.ownr_ln || "")
|
||||
.toLowerCase()
|
||||
.includes(searchQuery.toLowerCase()) ||
|
||||
(j.plate_no || "")
|
||||
.toLowerCase()
|
||||
.includes(searchQuery.toLowerCase()) ||
|
||||
(j.v_model_desc || "")
|
||||
.toLowerCase()
|
||||
.includes(searchQuery.toLowerCase()) ||
|
||||
(j.v_make_desc || "")
|
||||
.toLowerCase()
|
||||
.includes(searchQuery.toLowerCase())
|
||||
)
|
||||
: [];
|
||||
|
||||
return (
|
||||
<Provider>
|
||||
<>
|
||||
<Portal>
|
||||
<Modal
|
||||
visible={visible}
|
||||
onDismiss={hideModal}
|
||||
contentContainerStyle={containerStyle}
|
||||
// eslint-disable-next-line react-native/no-color-literals
|
||||
contentContainerStyle={{
|
||||
paddingTop: 20,
|
||||
paddingBottom: 20,
|
||||
flex: 1,
|
||||
backgroundColor: "white",
|
||||
}}
|
||||
>
|
||||
<View
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
margin: 8,
|
||||
}}
|
||||
>
|
||||
<Button onPress={() => hideModal()}>
|
||||
<Ionicons name="ios-arrow-back" size={32} color="dodgerblue" />
|
||||
</Button>
|
||||
<Searchbar
|
||||
style={{ flex: 1 }}
|
||||
onChangeText={onChangeSearch}
|
||||
value={searchQuery}
|
||||
/>
|
||||
</View>
|
||||
<FlatList
|
||||
refreshControl={
|
||||
<RefreshControl refreshing={loading} onRefresh={onRefresh} />
|
||||
}
|
||||
data={data.jobs}
|
||||
data={[{ id: "temp", ro_number: "Temporary Storage" }, ...jobs]}
|
||||
keyExtractor={(item) => item.id}
|
||||
renderItem={(object) => (
|
||||
<List.Item
|
||||
@@ -71,8 +129,25 @@ export function CameraSelectJob({
|
||||
setCameraJobId(object.item.id);
|
||||
setCameraJob(object.item);
|
||||
hideModal();
|
||||
setSearchQuery("");
|
||||
}}
|
||||
description={`${
|
||||
left={() => {
|
||||
if (object.item.id !== cameraJobId) return null;
|
||||
return (
|
||||
<Ionicons
|
||||
name="ios-checkmark-circle"
|
||||
size={24}
|
||||
color="dodgerblue"
|
||||
style={{ alignSelf: "center" }}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
titleStyle={{
|
||||
...(object.item.id === cameraJobId
|
||||
? { color: "dodgerblue" }
|
||||
: {}),
|
||||
}}
|
||||
title={`${
|
||||
object.item.ro_number ? `${object.item.ro_number} - ` : ``
|
||||
}${object.item.ownr_fn || ""} ${object.item.ownr_ln || ""} ${
|
||||
object.item.ownr_co_nm || ""
|
||||
@@ -85,41 +160,19 @@ export function CameraSelectJob({
|
||||
/>
|
||||
</Modal>
|
||||
</Portal>
|
||||
<Button style={{ marginTop: 30 }} onPress={showModal}>
|
||||
<Button mode="outlined" style={{ margin: 8 }} onPress={showModal}>
|
||||
{cameraJobId
|
||||
? `${cameraJob.ro_number ? `${cameraJob.ro_number} - ` : ``}${
|
||||
cameraJob.ownr_fn || ""
|
||||
} ${cameraJob.ownr_ln || ""} ${cameraJob.ownr_co_nm || ""} - ${
|
||||
cameraJob.v_model_yr || ""
|
||||
} ${cameraJob.v_make_desc || ""} ${cameraJob.v_model_desc || ""}`
|
||||
? cameraJobId === "temp"
|
||||
? t("mediabrowser.labels.temporarystorage")
|
||||
: `${cameraJob.ro_number ? `${cameraJob.ro_number} - ` : ``}${
|
||||
cameraJob.ownr_fn || ""
|
||||
} ${cameraJob.ownr_ln || ""} ${cameraJob.ownr_co_nm || ""} - ${
|
||||
cameraJob.v_model_yr || ""
|
||||
} ${cameraJob.v_make_desc || ""} ${cameraJob.v_model_desc || ""}`
|
||||
: t("mediabrowser.labels.selectjob")}
|
||||
</Button>
|
||||
</Provider>
|
||||
</>
|
||||
);
|
||||
|
||||
// return (
|
||||
// <View
|
||||
// style={{
|
||||
// marginHorizontal: 10,
|
||||
// }}
|
||||
// >
|
||||
// <Picker
|
||||
// selectedValue={cameraJobId}
|
||||
// onValueChange={(value, idx) => {
|
||||
// logImEXEvent("imexmobile_setcamerajobid");
|
||||
// setCameraJobId(value);
|
||||
// setCameraJob(data.jobs[idx]);
|
||||
// }}
|
||||
// >
|
||||
// <Picker.Item
|
||||
// label={t("mediabrowser.labels.selectjob")}
|
||||
// value={null}
|
||||
// key="null"
|
||||
// />
|
||||
|
||||
// </Picker>
|
||||
// </View>
|
||||
// );
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(CameraSelectJob);
|
||||
|
||||
Reference in New Issue
Block a user