Skip to content

Commit

Permalink
chore: merge offline funcitonality
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-mccombs committed Dec 10, 2020
2 parents 61d2441 + 7711755 commit d7db36c
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 9 deletions.
6 changes: 3 additions & 3 deletions domains/DataCollection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { deleteData, getData } from '../../modules/async-storage';
import { layout } from '../../modules/theme';
import I18n from '../../modules/i18n';

import { customQueryService } from '../../services/parse/crud';
import { customFormsQuery } from '../../modules/cached-resources';
import { retrieveSignOutFunction } from '../../services/parse/auth';

import ComingSoonSVG from '../../assets/graphics/static/Adventurer.svg';
Expand Down Expand Up @@ -61,8 +61,8 @@ const DataCollection = ({ navigation }) => {
}).catch(() => {
setSurveyingOrganization(surveyingOrganization || '');
});
customQueryService(0, 5000, 'FormSpecificationsV2', 'organizations', surveyingOrganization).then((forms) => {
setCustomForms(JSON.parse(JSON.stringify(forms)));
customFormsQuery(surveyingOrganization).then((forms) => {
setCustomForms(forms);
});
}, [surveyingUser, surveyingOrganization]);

Expand Down
4 changes: 2 additions & 2 deletions domains/HomeScreen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from 'react-native-paper';
import { ScrollView } from 'react-native-gesture-handler';

import getTasks from '../../services/tasky';
import { getTasksAsync } from '../../modules/cached-resources';
import { retrieveSignOutFunction } from '../../services/parse/auth';

import { deleteData } from '../../modules/async-storage';
Expand All @@ -23,7 +23,7 @@ const HomeScreen = (props) => {
const { navigation } = props;

const showTasks = async () => {
await getTasks().then((result) => {
await getTasksAsync().then((result) => {
setTasks(result);
});
};
Expand Down
9 changes: 8 additions & 1 deletion modules/cached-resources/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { residentQuery, cacheAutofillData } from './read';
import {
residentQuery,
cacheAutofillData,
customFormsQuery,
getTasksAsync
} from './read';
import {
postIdentificationForm,
postSupplementaryForm,
Expand All @@ -9,6 +14,8 @@ import {
export {
residentQuery,
cacheAutofillData,
customFormsQuery,
getTasksAsync,
postIdentificationForm,
postSupplementaryForm,
postHousehold,
Expand Down
56 changes: 53 additions & 3 deletions modules/cached-resources/read.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { residentIDQuery } from '../../services/parse/crud';
import { residentIDQuery, customQueryService } from '../../services/parse/crud';
import retrievePuenteAutofillData from '../../services/aws';
import { storeData, getData } from '../async-storage';
import checkOnlineStatus from '../offline';
import { getData, storeData } from '../async-storage';
import checkOnlineStatus from '../offline';
import getTasks from '../../services/tasky';

async function residentQuery(queryParams) {
let records = await residentIDQuery(queryParams);
Expand All @@ -19,10 +21,58 @@ async function cacheAutofillData(parameter) {
} else {
return getData('autofill_information')[parameter];
}
})
}

function customFormsQuery(surveyingOrganization) {
return new Promise((resolve, reject) => {
checkOnlineStatus().then((online) => {
if (online) {
customQueryService(0, 5000, 'FormSpecificationsV2', 'organizations', surveyingOrganization).then(async (forms) => {
await storeData(forms, 'customForms');
resolve(JSON.parse(JSON.stringify(forms)));
}, (error) => {
reject(error);
});
} else {
getData('customForms').then((forms) => {
resolve(forms);
}, (error) => {
reject(error);
});
}
}, (error) => {
reject(error);
});
});
}

function getTasksAsync() {
return new Promise((resolve, reject) => {
checkOnlineStatus().then(async (online) => {
if (online) {
await getTasks().then(async (result) => {
await storeData(result, 'tasks');
resolve(result);
}, (error) => {
reject(error);
});
} else {
getData('tasks').then((tasks) => {
resolve(tasks);
}, (error) => {
reject(error);
});
}
}, (error) => {
reject(error);
});
});
}

export {
residentQuery,
cacheAutofillData
cacheAutofillData,
customFormsQuery,
getTasksAsync
};

0 comments on commit d7db36c

Please sign in to comment.