• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

akvo / nmis-mobile / 5713781609

31 Jul 2023 10:50AM UTC coverage: 79.711% (+0.2%) from 79.531%
5713781609

push

github

ifirmawan
[#98] Revert GetStarted snapshot to main

624 of 831 branches covered (75.09%)

Branch coverage included in aggregate %.

1305 of 1589 relevant lines covered (82.13%)

17.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.66
/app/src/pages/Home.js
1
import React, { useState, useEffect, useMemo } from 'react';
2
import { Button } from '@rneui/themed';
3
import Icon from 'react-native-vector-icons/Ionicons';
4
import { BaseLayout } from '../components';
5
import { FormState, UserState, UIState } from '../store';
6
import { crudForms } from '../database/crud';
7
import { i18n } from '../lib';
8

9
const Home = ({ navigation }) => {
3✔
10
  const [search, setSearch] = useState(null);
13✔
11
  const [data, setData] = useState([]);
13✔
12
  const activeLang = UIState.useState((s) => s.lang);
13✔
13
  const trans = i18n.text(activeLang);
13✔
14

15
  const currentUserName = UserState.useState((s) => s.name);
13✔
16
  const subTitleText = currentUserName ? `${trans.userLabel} ${currentUserName}` : null;
13!
17

18
  const goToManageForm = (id) => {
13✔
19
    const findForm = data.find((d) => d?.id === id);
1✔
20
    FormState.update((s) => {
1✔
21
      s.form = findForm;
×
22
    });
23
    navigation.navigate('ManageForm', { id: id, name: findForm.name });
1✔
24
  };
25

26
  const goToUsers = () => {
13✔
27
    navigation.navigate('Users');
1✔
28
  };
29

30
  useEffect(() => {
13✔
31
    FormState.update((s) => {
6✔
32
      s.form = {};
×
33
    });
34
    crudForms.selectLatestFormVersion().then((results) => {
6✔
35
      const forms = results.map((r) => ({
12✔
36
        ...r,
37
        subtitles: [
38
          `${trans.versionLabel}${r.version}`,
39
          `${trans.submittedLabel} 20`,
40
          `${trans.draftLabel}1`,
41
          `${trans.syncLabel}11`,
42
        ],
43
      }));
44
      setData(forms);
6✔
45
    });
46
  }, []);
47

48
  const filteredData = useMemo(() => {
13✔
49
    return data.filter(
13✔
50
      (d) => (search && d?.name?.toLowerCase().includes(search.toLowerCase())) || !search,
14✔
51
    );
52
  }, [data, search]);
53

54
  return (
13✔
55
    <BaseLayout
56
      title={trans.homePageTitle}
57
      subTitle={subTitleText}
58
      search={{
59
        show: true,
60
        placeholder: trans.homeSearch,
61
        value: search,
62
        action: setSearch,
63
      }}
64
      leftComponent={
65
        <Button type="clear" testID="button-users" onPress={goToUsers}>
66
          <Icon name="person" size={18} />
67
        </Button>
68
      }
69
    >
70
      <BaseLayout.Content data={filteredData} action={goToManageForm} columns={2} />
71
    </BaseLayout>
72
  );
73
};
74

75
export default Home;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc