@@ -16,11 +16,14 @@ use crate::{
16
16
terminal:: Terminal ,
17
17
ui:: {
18
18
self ,
19
- entries:: Entries ,
20
- login:: LoginMethods ,
21
- prompt:: Prompt ,
22
- subscription:: Subscription ,
23
- tabs:: { Tab , Tabs } ,
19
+ components:: {
20
+ entries:: Entries ,
21
+ login:: Login ,
22
+ prompt:: Prompt ,
23
+ subscription:: Subscription ,
24
+ tabs:: { Tab , Tabs } ,
25
+ Components ,
26
+ } ,
24
27
theme:: Theme ,
25
28
} ,
26
29
} ;
@@ -43,17 +46,14 @@ pub enum AuthenticateState {
43
46
}
44
47
45
48
pub struct LoginState {
46
- pub login_methods : LoginMethods ,
49
+ pub login_methods : Login ,
47
50
pub auth_state : AuthenticateState ,
48
51
}
49
52
50
53
pub struct State {
51
54
pub screen : Screen ,
52
55
pub login : LoginState ,
53
- pub tabs : Tabs ,
54
- pub prompt : Prompt ,
55
- pub subscription : Subscription ,
56
- pub entries : Entries ,
56
+ pub components : Components ,
57
57
}
58
58
59
59
pub struct Application {
@@ -78,13 +78,15 @@ impl Application {
78
78
let state = State {
79
79
screen : Screen :: Login ,
80
80
login : LoginState {
81
- login_methods : LoginMethods :: new ( ) ,
81
+ login_methods : Login :: new ( ) ,
82
82
auth_state : AuthenticateState :: NotAuthenticated ,
83
83
} ,
84
- tabs : Tabs :: new ( ) ,
85
- subscription : Subscription :: new ( ) ,
86
- entries : Entries :: new ( ) ,
87
- prompt : Prompt :: new ( ) ,
84
+ components : Components {
85
+ tabs : Tabs :: new ( ) ,
86
+ prompt : Prompt :: new ( ) ,
87
+ subscription : Subscription :: new ( ) ,
88
+ entries : Entries :: new ( ) ,
89
+ } ,
88
90
} ;
89
91
90
92
Self {
@@ -170,7 +172,7 @@ impl Application {
170
172
if self . should_render {
171
173
self . render ( ) ;
172
174
self . should_render = false ;
173
- self . state . prompt . clear_error_message ( ) ;
175
+ self . state . components . prompt . clear_error_message ( ) ;
174
176
}
175
177
176
178
if self . should_quit {
@@ -204,8 +206,10 @@ impl Application {
204
206
self . complete_device_authroize_flow ( device_access_token)
205
207
}
206
208
Command :: MoveTabSelection ( direction) => {
207
- match self . state . tabs . move_selection ( direction) {
208
- Tab :: Subscription if !self . state . subscription . has_subscription ( ) => {
209
+ match self . state . components . tabs . move_selection ( direction) {
210
+ Tab :: Subscription
211
+ if !self . state . components . subscription . has_subscription ( ) =>
212
+ {
209
213
next = Some ( Command :: FetchSubscription {
210
214
after : None ,
211
215
first : 50 ,
@@ -216,7 +220,7 @@ impl Application {
216
220
self . should_render = true ;
217
221
}
218
222
Command :: MoveSubscribedFeed ( direction) => {
219
- self . state . subscription . move_selection ( direction) ;
223
+ self . state . components . subscription . move_selection ( direction) ;
220
224
self . should_render = true ;
221
225
}
222
226
Command :: PromptFeedSubscription => {
@@ -239,15 +243,18 @@ impl Application {
239
243
self . fetch_subscription ( after, first)
240
244
}
241
245
Command :: UpdateSubscription ( sub) => {
242
- self . state . subscription . update_subscription ( sub) ;
246
+ self . state . components . subscription . update_subscription ( sub) ;
243
247
self . should_render = true ;
244
248
}
245
249
Command :: CompleteSubscribeFeed { feed } => {
246
- self . state . subscription . add_subscribed_feed ( feed) ;
250
+ self . state . components . subscription . add_subscribed_feed ( feed) ;
247
251
self . should_render = true ;
248
252
}
249
253
Command :: CompleteUnsubscribeFeed { url } => {
250
- self . state . subscription . remove_unsubscribed_feed ( url) ;
254
+ self . state
255
+ . components
256
+ . subscription
257
+ . remove_unsubscribed_feed ( url) ;
251
258
self . should_render = true ;
252
259
}
253
260
Command :: OpenFeed => {
@@ -257,18 +264,18 @@ impl Application {
257
264
self . fetch_entries ( after, first) ;
258
265
}
259
266
Command :: UpdateEntries ( payload) => {
260
- self . state . entries . update_entries ( payload) ;
267
+ self . state . components . entries . update_entries ( payload) ;
261
268
self . should_render = true ;
262
269
}
263
270
Command :: MoveEntry ( direction) => {
264
- self . state . entries . move_selection ( direction) ;
271
+ self . state . components . entries . move_selection ( direction) ;
265
272
self . should_render = true ;
266
273
}
267
274
Command :: OpenEntry => {
268
275
self . open_entry ( ) ;
269
276
}
270
277
Command :: HandleError { message } => {
271
- self . state . prompt . set_error_message ( message) ;
278
+ self . state . components . prompt . set_error_message ( message) ;
272
279
self . should_render = true ;
273
280
}
274
281
}
@@ -312,7 +319,7 @@ impl Application {
312
319
KeyCode :: BackTab => {
313
320
return Some ( Command :: MoveTabSelection ( Direction :: Left ) )
314
321
}
315
- _ => match self . state . tabs . current ( ) {
322
+ _ => match self . state . components . tabs . current ( ) {
316
323
Tab :: Feeds => match key. code {
317
324
KeyCode :: Char ( 'j' ) => {
318
325
return Some ( Command :: MoveEntry ( Direction :: Down ) )
@@ -379,6 +386,7 @@ impl Application {
379
386
// TODO: prompt deletion confirm
380
387
let Some ( url) = self
381
388
. state
389
+ . components
382
390
. subscription
383
391
. selected_feed_url ( )
384
392
. map ( ToOwned :: to_owned)
@@ -414,14 +422,20 @@ impl Application {
414
422
415
423
impl Application {
416
424
fn open_feed ( & mut self ) {
417
- let Some ( feed_website_url) = self . state . subscription . selected_feed_website_url ( ) else {
425
+ let Some ( feed_website_url) = self
426
+ . state
427
+ . components
428
+ . subscription
429
+ . selected_feed_website_url ( )
430
+ else {
418
431
return ;
419
432
} ;
420
433
open:: that ( feed_website_url) . ok ( ) ;
421
434
}
422
435
423
436
fn open_entry ( & mut self ) {
424
- let Some ( entry_website_url) = self . state . entries . selected_entry_website_url ( ) else {
437
+ let Some ( entry_website_url) = self . state . components . entries . selected_entry_website_url ( )
438
+ else {
425
439
return ;
426
440
} ;
427
441
open:: that ( entry_website_url) . ok ( ) ;
0 commit comments