Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ function App() {
<div className="App">
<StateContext.Provider value={{ state, setState }}>
<BrowserRouter>
<div style={{ opacity: 0, position: 'absolute', zIndex: -1 }}>
<GenericOdkForm />
</div>
<Routes>
<Route
path={ROUTE_MAP.root}
Expand Down
13 changes: 8 additions & 5 deletions src/pages/AssessmentType.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,21 @@ const AssessmentType = () => {
}

const handleInput = async (setter, val, type) => {
if (!navigator.onLine) setToLocalForage('syncData', true);
setter(val);
let appData = await getFromLocalForage('appData') || {};
appData[type] = val;
setToLocalForage('appData', appData);
}

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(() => {
Expand Down
17 changes: 16 additions & 1 deletion src/pages/forms/GenericOdkForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const GenericOdkForm = () => {
const [surveyUrl, setSurveyUrl] = useState("");
let { formName } = useParams();
const scheduleId = useRef();
const [formSubmitted] = useState(false);
const formSpec = {
forms: {
[formName]: {
Expand Down Expand Up @@ -143,14 +144,27 @@ 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")
else
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 (
<CommonLayout back={ROUTE_MAP.assessment_type}>
<div className="flex flex-col items-center">
Expand All @@ -172,6 +186,7 @@ const GenericOdkForm = () => {
/>
</>
)}
{/* <div className="mt-5 p-4 border border-orange-300" onClick={clearFormCache}> Clear saved data</div> */}
</div>
</CommonLayout>
);
Expand Down