1- import { useCallback , useEffect , useState } from 'react' ;
2-
3- import { getReleaseUrl } from '@suite/github' ;
41import { Translation } from '@suite/intl' ;
5- import { Badge , Banner , Card , Paragraph , Row , TextButton } from '@trezor/components' ;
6-
7- import { MarkdownWithComponents } from 'src/components/suite' ;
8-
9- type State = { status : 'loading' } | { status : 'loaded' ; changelog : string } | { status : 'error' } ;
10-
11- type ReleaseHeaderProps = {
12- version : string ;
13- } ;
2+ import { Banner , Card , Column } from '@trezor/components' ;
143
15- const ReleaseHeader = ( { version } : ReleaseHeaderProps ) => (
16- < Row gap = { 12 } alignItems = "center" >
17- < Paragraph typographyStyle = "body-sm" intent = "neutral" priority = "secondary" >
18- < Translation id = "TR_RELEASE_NOTES_VERSION" />
19- </ Paragraph >
20- < Badge intent = "neutral" size = "small" >
21- { version }
22- </ Badge >
23- </ Row >
24- ) ;
25-
26- const GithubFooter = ( { url } : { url : string } ) => (
27- < TextButton
28- href = { url }
29- target = "_blank"
30- intent = "neutral"
31- priority = "secondary"
32- size = "small"
33- isUnderlined
34- >
35- < Translation id = "TR_CHANGELOG_ON_GITHUB" />
36- </ TextButton >
37- ) ;
4+ import { ReleaseNoteCard } from './ReleaseNoteCard' ;
5+ import { useReleaseNotes } from './useReleaseNotes' ;
386
397export const ReleaseNotes = ( ) => {
40- const [ state , setState ] = useState < State > ( { status : 'loading' } ) ;
41- const suiteCurrentVersion = process . env . VERSION || '' ;
42-
43- const loadLocalChangelog = useCallback ( async ( ) => {
44- try {
45- const response = await fetch ( ( process . env . ASSET_PREFIX ?? '' ) + '/release-notes.md' ) ;
46- if ( ! response . ok ) {
47- setState ( { status : 'error' } ) ;
48-
49- return ;
50- }
51- setState ( { status : 'loaded' , changelog : await response . text ( ) } ) ;
52- } catch {
53- setState ( { status : 'error' } ) ;
54- }
55- } , [ ] ) ;
56-
57- useEffect ( ( ) => {
58- loadLocalChangelog ( ) ;
59- } , [ loadLocalChangelog ] ) ;
8+ const { releases, updatableRelease, isLoading, hasFailed } = useReleaseNotes ( ) ;
609
61- if ( state . status === 'loading' ) {
10+ if ( isLoading ) {
6211 return < Banner isLoading description = { < Translation id = "TR_RELEASE_NOTES_LOADING" /> } /> ;
6312 }
6413
65- if ( state . status === 'error' ) {
14+ if ( hasFailed || releases . length === 0 ) {
6615 return (
6716 < Card >
6817 < Translation id = "TR_COULD_NOT_RETRIEVE_CHANGELOG" />
@@ -71,11 +20,17 @@ export const ReleaseNotes = () => {
7120 }
7221
7322 return (
74- < Card
75- header = { < ReleaseHeader version = { suiteCurrentVersion } /> }
76- footer = { < GithubFooter url = { getReleaseUrl ( suiteCurrentVersion ) } /> }
77- >
78- < MarkdownWithComponents > { state . changelog } </ MarkdownWithComponents >
79- </ Card >
23+ < Column gap = { 16 } >
24+ { releases . map ( release => (
25+ < ReleaseNoteCard
26+ key = { release . version }
27+ version = { release . version }
28+ publishedAt = { release . publishedAt }
29+ notes = { release . notes }
30+ isCurrent = { release . isCurrent }
31+ isUpdatable = { release . version === updatableRelease ?. version }
32+ />
33+ ) ) }
34+ </ Column >
8035 ) ;
8136} ;
0 commit comments