From a34d06210f0bc13d97d9f5293d0cc1afd8ffa262 Mon Sep 17 00:00:00 2001 From: amit-s19 Date: Mon, 19 Jun 2023 14:58:50 +0530 Subject: [PATCH] Init Commit --- src/App.js | 3 +++ src/pages/AssessmentType.jsx | 13 ++++++++----- src/pages/forms/GenericOdkForm.jsx | 17 ++++++++++++++++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/App.js b/src/App.js index 61c60aa..0a638ce 100644 --- a/src/App.js +++ b/src/App.js @@ -89,6 +89,9 @@ function App() {
+
+ +
{ } const handleInput = async (setter, val, type) => { - if (!navigator.onLine) setToLocalForage('syncData', true); setter(val); let appData = await getFromLocalForage('appData') || {}; appData[type] = val; @@ -38,10 +37,14 @@ const AssessmentType = () => { } const saveDataOnline = async () => { - saveDataToHasura({ - text_input: textData, - date_input: dateData - }) + if (!navigator.onLine) { + setToLocalForage('syncData', true); + toast('Your data has been saved and will be synced with server once internet is available ✅') + } else + saveDataToHasura({ + text_input: textData, + date_input: dateData + }) } useEffect(() => { diff --git a/src/pages/forms/GenericOdkForm.jsx b/src/pages/forms/GenericOdkForm.jsx index cde5c8f..1431371 100644 --- a/src/pages/forms/GenericOdkForm.jsx +++ b/src/pages/forms/GenericOdkForm.jsx @@ -14,6 +14,7 @@ const GenericOdkForm = () => { const [surveyUrl, setSurveyUrl] = useState(""); let { formName } = useParams(); const scheduleId = useRef(); + const [formSubmitted] = useState(false); const formSpec = { forms: { [formName]: { @@ -143,7 +144,8 @@ const GenericOdkForm = () => { }, []); const getSurveyUrl = async () => { - let surveyUrl = await getOfflineCapableForm('widgets'); + let surveyUrl = await getOfflineCapableForm('Nursing Form-Medical (CRP)'); + // let surveyUrl = await getOfflineCapableForm('widgets'); console.log("SurveyURL:", surveyUrl); if (!surveyUrl) setSurveyUrl("https://8065-samagradevelop-workflow-871i2twcw0a.ws-us98.gitpod.io/x/wnoqac4d") @@ -151,6 +153,18 @@ const GenericOdkForm = () => { setSurveyUrl(surveyUrl); } + + // TODO + const clearFormCache = async () => { + let formUri = await getFromLocalForage('formUri'); + const formId = formUri.slice(formUri.lastIndexOf('/') + 1); + const enketoDB = indexedDB.open('enketo', 3); + indexedDB.databases().then(r => console.log(r)) + console.log(enketoDB) + } + + + return (
@@ -172,6 +186,7 @@ const GenericOdkForm = () => { /> )} + {/*
Clear saved data
*/}
);