Skip to content

Commit

Permalink
feat: create searchbar for human id
Browse files Browse the repository at this point in the history
  • Loading branch information
hopetambala committed Sep 26, 2020
1 parent 21db589 commit 8e1217a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 28 deletions.
60 changes: 41 additions & 19 deletions components/HouseholdManager/index.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,69 @@
import * as React from 'react';
import React, { useState, useEffect } from 'react';

import {
View,
View
} from 'react-native';

import {
Text, Button, Chip, Searchbar
} from 'react-native-paper';

import { layout } from '../../modules/theme';
import { residentIDQuery } from '../../services/parse/crud';

const HouseholdManager = (props) => {
const { data } = props;
const [searchQuery, setSearchQuery] = React.useState('');
const [selectPerson, setSelectPerson] = React.useState();
const onChangeSearch = (query) => setSearchQuery(query);
const HouseholdManager = () => {
const [data, setData] = useState([]);
const [query, setQuery] = useState('');
const [residents, setResidents] = useState([]);
const [selectPerson, setSelectPerson] = useState();

useEffect(() => {
fetchData();
}, []);

const fetchData = async () => {
let records = await residentIDQuery();
records = JSON.parse(JSON.stringify(records));

setData(records);
setResidents(records.slice());
};

const filterList = () => data.filter(
(listItem) => listItem.fname
.toLowerCase()
.includes(searchQuery.toLowerCase())
|| listItem.lname
.toLowerCase()
.includes(searchQuery.toLowerCase())
|| listItem.nickname
.toLowerCase()
.includes(searchQuery.toLowerCase())
(listItem) => {
const fname = listItem.fname || ' ';
const lname = listItem.lname || ' ';
const nickname = listItem.nickname || ' ';
return fname.toLowerCase().includes(query.toLowerCase())
|| lname
.toLowerCase()
.includes(query.toLowerCase())
|| nickname
.toLowerCase()
.includes(query.toLowerCase());
}
);

const onChangeSearch = (input) => {
setResidents(data.slice());
setQuery(input);
};

return (
<View>
<Text>Search Individual</Text>
<Searchbar
placeholder="Search"
placeholder="Type Here..."
onChangeText={onChangeSearch}
value={searchQuery}
value={query}
/>

{searchQuery !== '' && filterList(data).map((listItem,) => (
{query !== '' && filterList(residents).map((listItem,) => (
<View style={layout.buttonGroupContainer}>
<Button onPress={() => setSelectPerson(listItem)} key={listItem}>{listItem.fname}</Button>
</View>
))}

{selectPerson && (
<Chip icon="information">
{selectPerson.fname}
Expand Down
9 changes: 1 addition & 8 deletions domains/DataCollection/Forms/IdentificationForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ import HouseholdManager from '../../../../components/HouseholdManager';
// .required()
// });

const list = [
{ fname: 'Mario', lname: 'Bros', nickname: 'Red Guy' },
{ fname: 'Pippy', lname: 'The Skippy', nickname: 'Froggy' },
{ fname: 'Donkey', lname: 'Kong', nickname: 'brownie' },
{ fname: 'Zippy', lname: 'Lippy', nickname: 'zipper' },
];

const IdentificationForm = ({
scrollViewScroll, setScrollViewScroll, setSelectedForm
}) => {
Expand Down Expand Up @@ -108,7 +101,7 @@ const IdentificationForm = ({
</View>
))}

<HouseholdManager data={list} />
<HouseholdManager />

{formikProps.isSubmitting ? (
<ActivityIndicator />
Expand Down
15 changes: 14 additions & 1 deletion services/parse/crud/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import { Parse } from 'parse/react-native';
function retrieveHelloFunction() {
Parse.Cloud.run('hello').then((result) => result);
}
function residentIDQuery() {
return new Promise((resolve, reject) => {
Parse.Cloud.run('genericQuery').then((result) => {
resolve(result);
}, (error) => {
reject(error);
});
});
}

function postObjectsToClass(params) {
return new Promise((resolve, reject) => {
Expand All @@ -14,4 +23,8 @@ function postObjectsToClass(params) {
});
}

export { retrieveHelloFunction, postObjectsToClass };
export {
retrieveHelloFunction,
residentIDQuery,
postObjectsToClass
};

0 comments on commit 8e1217a

Please sign in to comment.