|
| 1 | +import moment from 'moment'; |
| 2 | + |
1 | 3 | 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'; |
3 | 16 |
|
| 17 | +import { useAppDispatch, useAppSelector } from '@/store'; |
| 18 | +import { StyledSafeAreaView } from '@/style'; |
4 | 19 | import type { PropsWithNavigation } from '@/views/navigation/NavigationStack'; |
5 | 20 |
|
6 | 21 | 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 | + |
7 | 45 | return ( |
8 | 46 | <> |
9 | 47 | <Appbar.Header> |
10 | | - <Appbar.Content title="Debug" /> |
| 48 | + <Appbar.Content title={t('settings.debug')} /> |
11 | 49 | </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> |
12 | 96 | </> |
13 | 97 | ); |
14 | 98 | }; |
|
0 commit comments