11import type { FC } from 'react' ;
2- import { useCallback } from 'react' ;
2+ import { useMemo , useCallback } from 'react' ;
33import type { Release } from '@octokit/webhooks-types' ;
44import moment from 'moment/moment' ;
55import { Badge , Divider , List , Text } from 'react-native-paper' ;
@@ -14,6 +14,10 @@ import Markdown from 'react-native-markdown-display';
1414import SettingsSurface , {
1515 settingsSurfaceBorderRadius ,
1616} from '@/components/styled/SettingsSurface' ;
17+ import useHasAuthConfigured from '@/hooks/useHasAuthConfigured' ;
18+ import capitalize from '@/utils/capitalize' ;
19+ import type { SettingsState } from '@/types/settings' ;
20+ import useAppLanguage from '@/hooks/useAppLanguage' ;
1721
1822export interface FirmwareListItemProps {
1923 release : Release ;
@@ -24,6 +28,11 @@ const rules: RenderRules = {
2428 link : ( node , children ) => < RNText key = { node . key } > { children } </ RNText > ,
2529} ;
2630
31+ const needsCapitalization : Record < SettingsState [ 'language' ] , boolean > = {
32+ en : false ,
33+ de : true ,
34+ } ;
35+
2736const FirmwareListItem : FC < FirmwareListItemProps > = ( {
2837 release,
2938 latestReleaseTag,
@@ -32,6 +41,9 @@ const FirmwareListItem: FC<FirmwareListItemProps> = ({
3241 const currentRelease = useDtuState ( state => state ?. systemStatus ?. git_hash ) ;
3342 // const navigation = useNavigation() as NavigationProp<ParamListBase>;
3443
44+ const authStringConfigured = useHasAuthConfigured ( ) ;
45+ const language = useAppLanguage ( ) ;
46+
3547 const handleOpenGithub = useCallback ( async ( ) => {
3648 const url = release . html_url ;
3749
@@ -44,6 +56,20 @@ const FirmwareListItem: FC<FirmwareListItemProps> = ({
4456
4557 }, []);*/
4658
59+ const downloadDisabled = useMemo (
60+ ( ) => true || release . tag_name === currentRelease || ! authStringConfigured ,
61+ [ authStringConfigured , currentRelease , release . tag_name ] ,
62+ ) ;
63+
64+ const description = useMemo ( ( ) => {
65+ const date = moment ( release . published_at ) . format ( 'LLLL' ) ;
66+ const timeAgo = moment ( release . published_at ) . fromNow ( ) ;
67+ const capitalized = needsCapitalization [ language ]
68+ ? capitalize ( timeAgo )
69+ : timeAgo ;
70+ return `${ t ( 'firmwares.publishedAgo' , { timeAgo : capitalized } ) } \n${ date } ` ;
71+ } , [ release . published_at , language , t ] ) ;
72+
4773 return (
4874 < List . Accordion
4975 key = { `firmware-${ release . id } ` }
@@ -63,7 +89,7 @@ const FirmwareListItem: FC<FirmwareListItemProps> = ({
6389 ) : null }
6490 </ View >
6591 }
66- description = { moment ( release . published_at ) . format ( 'lll' ) }
92+ description = { description }
6793 >
6894 < SettingsSurface style = { { marginHorizontal : 8 , flex : 1 } } >
6995 < View style = { { padding : 8 , flex : 1 } } >
@@ -90,9 +116,9 @@ const FirmwareListItem: FC<FirmwareListItemProps> = ({
90116 style = { {
91117 borderBottomLeftRadius : settingsSurfaceBorderRadius ,
92118 borderBottomRightRadius : settingsSurfaceBorderRadius ,
93- opacity : 0.5 ,
119+ opacity : downloadDisabled ? 0.5 : 1 ,
94120 } }
95- disabled = { true || release . tag_name === currentRelease }
121+ disabled = { downloadDisabled }
96122 />
97123 </ SettingsSurface >
98124 </ List . Accordion >
0 commit comments