Skip to content

Commit

Permalink
feat: cache autofill workinggit add . 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-mccombs committed Dec 5, 2020
1 parent 49defe4 commit c51e8ce
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 11 deletions.
28 changes: 23 additions & 5 deletions components/FormikFields/PaperInputPicker/AutoFill/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ import {
import Autocomplete from 'react-native-autocomplete-input';

import retrievePuenteAutofillData from '../../../../services/aws';
import { cacheAutofillData } from '../../../../modules/cached-resources';

import I18n from '../../../../modules/i18n';
import { getData } from '../../../../modules/async-storage';

YellowBox.ignoreWarnings(['VirtualizedLists should never be nested']);

const getFields = (parameter) => {
cacheAutofillData(parameter).then((result) => {
return result;
})
}
export default class AutoFill extends Component {
constructor(props) {
super(props);
Expand All @@ -22,12 +29,23 @@ export default class AutoFill extends Component {

componentDidMount() {
const { parameter } = this.props;
retrievePuenteAutofillData(parameter)
.then((data) => {
this.state.fields = data;
cacheAutofillData(parameter)
.then(async () => {
// const data = await getData('autofill_information')[parameter]
const data = await getData('autofill_information')
const result = data[parameter];
this.state.fields = result;
});
}

// getFields(parameter) {
// cacheAutofillData(parameter).then((result) => {
// return result;
// })
// }



findField(query) {
// method called everytime when we change the value of the input
if (query === '') {
Expand Down Expand Up @@ -97,8 +115,8 @@ export default class AutoFill extends Component {
{fields.length > 0 ? (
<Text style={styles.infoText}>{query}</Text>
) : (
<Text style={styles.infoText}>{placeholder}</Text>
)}
<Text style={styles.infoText}>{placeholder}</Text>
)}
</View>
</View>
);
Expand Down
26 changes: 22 additions & 4 deletions modules/cached-resources/read.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
import { residentIDQuery } from '../../services/parse/crud';
import retrievePuenteAutofillData from '../../services/aws';
import { storeData } from '../async-storage'
import { storeData, getData } from '../async-storage'
import checkOnlineStatus from '../offline';

async function residentQuery(queryParams) {
let records = await residentIDQuery(queryParams);
records = JSON.parse(JSON.stringify(records));
return records;
}

function cacheAutofillData() {
retrievePuenteAutofillData('all').then((result) => {
storeData(result, 'autofill_information')
async function cacheAutofillData(paramter) {
console.log("REally first hi");
checkOnlineStatus().then((connected) => {
console.log("Connected", connected);
if (connected) {
retrievePuenteAutofillData('all').then((result) => {
storeData(result, 'autofill_information')
console.log("Resulkt", result)
return result[paramter];
// const data = await getData('autofill_information')
// console.log(paramter, data[paramter]);
// return data[paramter];
}, (error) => {
reject("1", error);
})
}
else {
return getData('autofill_information')[paramter];
}
})
console.log("First hi");
}

export {
Expand Down
12 changes: 10 additions & 2 deletions services/aws/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ function retrievePuenteAutofillData(parameter) {
.then((response) => {
if (parameter !== 'all') {
const results = [];
const resultsCapitalized = [];
response.data.forEach((object) => {
if (!results.includes(object[parameter].toUpperCase().trim()) && object[parameter] != "") {
const objectCapitilized = object[parameter].toUpperCase().trim()
if (!resultsCapitalized.includes(objectCapitilized) && object[parameter] != "") {
resultsCapitalized.push(objectCapitilized);
results.push(object[parameter]);
}
});
Expand All @@ -27,13 +30,18 @@ function retrievePuenteAutofillData(parameter) {
const allData = {}
keys.forEach((key) => {
const results = [];
const resultsCapitalized = [];
response.data.forEach((object) => {
if (!results.includes(object[key].toUpperCase().trim()) && object[key] != "") {
const objectCapitilized = object[key].toUpperCase().trim()
console.log(object)
if (!resultsCapitalized.includes(objectCapitilized) && object[key] != "") {
resultsCapitalized.push(objectCapitilized);
results.push(object[key]);
}
})
allData[key] = results;
})
console.log(allData);
return allData;
}
})
Expand Down

0 comments on commit c51e8ce

Please sign in to comment.