11mod changelog;
2- mod icon;
32
43use crate :: changelog:: Changelog ;
54
6- use iced:: clipboard;
75use iced:: font;
86use iced:: widget:: {
97 button, center, column, container, markdown, pick_list, progress_bar,
108 rich_text, row, scrollable, span, stack, text, text_input,
119} ;
12- use iced:: { Element , Fill , FillPortion , Font , Task , Theme } ;
10+ use iced:: { Center , Element , Fill , FillPortion , Font , Task , Theme } ;
1311
1412pub fn main ( ) -> iced:: Result {
1513 iced:: application ( "Changelog Generator" , Generator :: update, Generator :: view)
16- . font ( icon:: FONT_BYTES )
1714 . theme ( Generator :: theme)
1815 . run_with ( Generator :: new)
1916}
2017
2118enum Generator {
2219 Loading ,
23- Empty ,
2420 Reviewing {
2521 changelog : Changelog ,
26- pending : Vec < changelog:: Candidate > ,
22+ pending : Vec < changelog:: Contribution > ,
2723 state : State ,
2824 preview : Vec < markdown:: Item > ,
2925 } ,
26+ Done ,
3027}
3128
3229enum State {
33- Loading ( changelog:: Candidate ) ,
30+ Loading ( changelog:: Contribution ) ,
3431 Loaded {
3532 pull_request : changelog:: PullRequest ,
3633 description : Vec < markdown:: Item > ,
@@ -42,15 +39,16 @@ enum State {
4239#[ derive( Debug , Clone ) ]
4340enum Message {
4441 ChangelogListed (
45- Result < ( Changelog , Vec < changelog:: Candidate > ) , changelog:: Error > ,
42+ Result < ( Changelog , Vec < changelog:: Contribution > ) , changelog:: Error > ,
4643 ) ,
4744 PullRequestFetched ( Result < changelog:: PullRequest , changelog:: Error > ) ,
4845 UrlClicked ( markdown:: Url ) ,
4946 TitleChanged ( String ) ,
5047 CategorySelected ( changelog:: Category ) ,
5148 Next ,
5249 OpenPullRequest ( u64 ) ,
53- CopyPreview ,
50+ ChangelogSaved ( Result < ( ) , changelog:: Error > ) ,
51+ Quit ,
5452}
5553
5654impl Generator {
@@ -64,23 +62,23 @@ impl Generator {
6462 fn update ( & mut self , message : Message ) -> Task < Message > {
6563 match message {
6664 Message :: ChangelogListed ( Ok ( ( changelog, mut pending) ) ) => {
67- if let Some ( candidate ) = pending. pop ( ) {
65+ if let Some ( contribution ) = pending. pop ( ) {
6866 let preview =
6967 markdown:: parse ( & changelog. to_string ( ) ) . collect ( ) ;
7068
7169 * self = Self :: Reviewing {
7270 changelog,
7371 pending,
74- state : State :: Loading ( candidate . clone ( ) ) ,
72+ state : State :: Loading ( contribution . clone ( ) ) ,
7573 preview,
7674 } ;
7775
7876 Task :: perform (
79- candidate . fetch ( ) ,
77+ changelog :: PullRequest :: fetch ( contribution ) ,
8078 Message :: PullRequestFetched ,
8179 )
8280 } else {
83- * self = Self :: Empty ;
81+ * self = Self :: Done ;
8482
8583 Task :: none ( )
8684 }
@@ -108,12 +106,6 @@ impl Generator {
108106
109107 Task :: none ( )
110108 }
111- Message :: ChangelogListed ( Err ( error) )
112- | Message :: PullRequestFetched ( Err ( error) ) => {
113- log:: error!( "{error}" ) ;
114-
115- Task :: none ( )
116- }
117109 Message :: UrlClicked ( url) => {
118110 let _ = webbrowser:: open ( url. as_str ( ) ) ;
119111
@@ -172,19 +164,27 @@ impl Generator {
172164 {
173165 changelog. push ( entry) ;
174166
167+ let save = Task :: perform (
168+ changelog. clone ( ) . save ( ) ,
169+ Message :: ChangelogSaved ,
170+ ) ;
171+
175172 * preview =
176173 markdown:: parse ( & changelog. to_string ( ) ) . collect ( ) ;
177174
178- if let Some ( candidate ) = pending. pop ( ) {
179- * state = State :: Loading ( candidate . clone ( ) ) ;
175+ if let Some ( contribution ) = pending. pop ( ) {
176+ * state = State :: Loading ( contribution . clone ( ) ) ;
180177
181- Task :: perform (
182- candidate. fetch ( ) ,
183- Message :: PullRequestFetched ,
184- )
178+ Task :: batch ( [
179+ save,
180+ Task :: perform (
181+ changelog:: PullRequest :: fetch ( contribution) ,
182+ Message :: PullRequestFetched ,
183+ ) ,
184+ ] )
185185 } else {
186- // TODO: We are done!
187- Task :: none ( )
186+ * self = Self :: Done ;
187+ save
188188 }
189189 } else {
190190 Task :: none ( )
@@ -197,20 +197,32 @@ impl Generator {
197197
198198 Task :: none ( )
199199 }
200- Message :: CopyPreview => {
201- let Self :: Reviewing { changelog, .. } = self else {
202- return Task :: none ( ) ;
203- } ;
200+ Message :: ChangelogSaved ( Ok ( ( ) ) ) => Task :: none ( ) ,
201+
202+ Message :: ChangelogListed ( Err ( error) )
203+ | Message :: PullRequestFetched ( Err ( error) )
204+ | Message :: ChangelogSaved ( Err ( error) ) => {
205+ log:: error!( "{error}" ) ;
204206
205- clipboard :: write ( changelog . to_string ( ) )
207+ Task :: none ( )
206208 }
209+ Message :: Quit => iced:: exit ( ) ,
207210 }
208211 }
209212
210213 fn view ( & self ) -> Element < Message > {
211214 match self {
212215 Self :: Loading => center ( "Loading..." ) . into ( ) ,
213- Self :: Empty => center ( "No changes found!" ) . into ( ) ,
216+ Self :: Done => center (
217+ column ! [
218+ text( "Changelog is up-to-date! 🎉" )
219+ . shaping( text:: Shaping :: Advanced ) ,
220+ button( "Quit" ) . on_press( Message :: Quit ) ,
221+ ]
222+ . spacing ( 10 )
223+ . align_x ( Center ) ,
224+ )
225+ . into ( ) ,
214226 Self :: Reviewing {
215227 changelog,
216228 pending,
@@ -237,8 +249,8 @@ impl Generator {
237249 } ;
238250
239251 let form: Element < _ > = match state {
240- State :: Loading ( candidate ) => {
241- text ! ( "Loading #{}..." , candidate . id) . into ( )
252+ State :: Loading ( contribution ) => {
253+ text ! ( "Loading #{}..." , contribution . id) . into ( )
242254 }
243255 State :: Loaded {
244256 pull_request,
@@ -318,17 +330,16 @@ impl Generator {
318330 }
319331 } ;
320332
321- let preview: Element < _ > = if preview. is_empty ( ) {
333+ let preview = if preview. is_empty ( ) {
322334 center (
323335 container (
324336 text ( "The changelog is empty... so far!" ) . size ( 12 ) ,
325337 )
326338 . padding ( 10 )
327339 . style ( container:: rounded_box) ,
328340 )
329- . into ( )
330341 } else {
331- let content = container (
342+ container (
332343 scrollable (
333344 markdown:: view (
334345 preview,
@@ -343,14 +354,7 @@ impl Generator {
343354 )
344355 . width ( Fill )
345356 . padding ( 10 )
346- . style ( container:: rounded_box) ;
347-
348- let copy = button ( icon:: copy ( ) . size ( 12 ) )
349- . on_press ( Message :: CopyPreview )
350- . style ( button:: text) ;
351-
352- center ( stack ! [ content, container( copy) . align_right( Fill ) ] )
353- . into ( )
357+ . style ( container:: rounded_box)
354358 } ;
355359
356360 let review = column ! [ container( form) . height( Fill ) , progress]
0 commit comments