Skip to content

Commit

Permalink
[#1153] Close all cascade database connection when exit Form
Browse files Browse the repository at this point in the history
  • Loading branch information
ifirmawan committed Feb 14, 2024
1 parent bdd851d commit 66698c1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/src/pages/FormPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
} from 'react-native';
import { Button, Dialog, Text } from '@rneui/themed';
import Icon from 'react-native-vector-icons/Ionicons';
import * as SQLite from 'expo-sqlite';

import { FormContainer } from '../form';
import { SaveDialogMenu, SaveDropdownMenu } from '../form/support';
import { BaseLayout } from '../components';
Expand Down Expand Up @@ -40,7 +42,17 @@ const FormPage = ({ navigation, route }) => {
const [currentDataPoint, setCurrentDataPoint] = useState({});
const [loading, setLoading] = useState(false);

const closeAllCascades = () => {
const { cascades: cascadesFiles } = formJSON;
cascadesFiles.forEach((csFile) => {
const [dbFile] = csFile?.split('/')?.slice(-1);
const connDB = SQLite.openDatabase(dbFile);
connDB.closeAsync();
});
};

const refreshForm = () => {
closeAllCascades();
FormState.update((s) => {
s.currentValues = {};
s.visitedQuestionGroup = [];
Expand Down

0 comments on commit 66698c1

Please sign in to comment.