Skip to content

Commit c035722

Browse files
Implement debug screen
1 parent 7561a5e commit c035722

File tree

4 files changed

+89
-4
lines changed

4 files changed

+89
-4
lines changed

src/translations/translation-files

src/types/opendtu/github.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface WithTimestamp<T> {
1515
}
1616

1717
export interface GithubState {
18+
// OpenDTU releases
1819
latestRelease: WithTimestamp<Release | null>;
1920
releases: WithTimestamp<Release[]>;
2021

src/views/navigation/screens/DebugScreen.tsx

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,98 @@
1+
import moment from 'moment';
2+
13
import type { FC } from 'react';
2-
import { Appbar } from 'react-native-paper';
4+
import { useCallback } from 'react';
5+
import { useTranslation } from 'react-i18next';
6+
import { ScrollView } from 'react-native';
7+
import { Box } from 'react-native-flex-layout';
8+
import { Appbar, IconButton, List, Text, useTheme } from 'react-native-paper';
9+
10+
import {
11+
clearLatestAppRelease,
12+
clearLatestRelease,
13+
setLatestAppRelease,
14+
} from '@/slices/github';
15+
import { setDebugEnabled } from '@/slices/settings';
316

17+
import { useAppDispatch, useAppSelector } from '@/store';
18+
import { StyledSafeAreaView } from '@/style';
419
import type { PropsWithNavigation } from '@/views/navigation/NavigationStack';
520

621
const DebugScreen: FC<PropsWithNavigation> = () => {
22+
const { t } = useTranslation();
23+
const theme = useTheme();
24+
const dispatch = useAppDispatch();
25+
26+
const latestAppRelease = useAppSelector(
27+
state => state.github.latestAppRelease.lastUpdate,
28+
);
29+
const latestOpenDtuRelease = useAppSelector(
30+
state => state.github.latestRelease.lastUpdate,
31+
);
32+
33+
const handleClearLatestAppRelease = useCallback(() => {
34+
dispatch(clearLatestAppRelease());
35+
}, [dispatch]);
36+
37+
const handleClearLatestOpenDtuRelease = useCallback(() => {
38+
dispatch(clearLatestRelease());
39+
}, [dispatch]);
40+
41+
const handleDisableDebugMode = useCallback(() => {
42+
dispatch(setDebugEnabled({ debugEnabled: false }));
43+
}, [dispatch]);
44+
745
return (
846
<>
947
<Appbar.Header>
10-
<Appbar.Content title="Debug" />
48+
<Appbar.Content title={t('settings.debug')} />
1149
</Appbar.Header>
50+
<StyledSafeAreaView theme={theme}>
51+
<Box style={{ width: '100%', flex: 1 }}>
52+
<ScrollView>
53+
<List.Section>
54+
<List.Subheader>{t('debug.cache')}</List.Subheader>
55+
<List.Item
56+
title={t('debug.latestAppReleaseCacheCreated')}
57+
description={
58+
latestAppRelease
59+
? moment(latestAppRelease).toLocaleString()
60+
: ''
61+
}
62+
right={props => (
63+
<IconButton
64+
{...props}
65+
icon="delete"
66+
onPress={handleClearLatestAppRelease}
67+
/>
68+
)}
69+
/>
70+
<List.Item
71+
title={t('debug.latestOpenDtuReleaseCacheCreated')}
72+
description={
73+
latestOpenDtuRelease
74+
? moment(latestOpenDtuRelease).toLocaleString()
75+
: ''
76+
}
77+
right={props => (
78+
<IconButton
79+
{...props}
80+
icon="delete"
81+
onPress={handleClearLatestOpenDtuRelease}
82+
/>
83+
)}
84+
/>
85+
</List.Section>
86+
<List.Section>
87+
<List.Subheader>{t('debug.other')}</List.Subheader>
88+
<List.Item
89+
title={t('debug.disableDebugMode')}
90+
onPress={handleDisableDebugMode}
91+
/>
92+
</List.Section>
93+
</ScrollView>
94+
</Box>
95+
</StyledSafeAreaView>
1296
</>
1397
);
1498
};

src/views/navigation/tabs/MainSettingsTab.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ const MainSettingsTab: FC = () => {
185185
) : null}
186186
</List.Section>
187187
<Text style={{ textAlign: 'center' }} onPress={handleUnlockDebug}>
188-
Version {packageJson.version}
188+
{t('version')} {packageJson.version}
189189
</Text>
190190
</ScrollView>
191191
</Box>

0 commit comments

Comments
 (0)