@@ -4,6 +4,7 @@ use super::utils;
44use super :: { Page , IFEXIT } ;
55use crossterm:: event:: { self , Event , KeyCode } ;
66use std:: { env, io, process:: Command } ;
7+ use tui:: widgets:: ListState ;
78pub ( crate ) fn subscribe_state ( app : & mut AppSub ) -> io:: Result < IFEXIT > {
89 if let Event :: Key ( key) = event:: read ( ) ? {
910 match app. input_mode {
@@ -30,38 +31,7 @@ pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
3031 } ,
3132 InputMode :: Editing => match key. code {
3233 KeyCode :: Enter => {
33- let input = vec ! [ app. input. clone( ) ] ;
34- let get_list = spider:: get_the_key ( input) ;
35- if let Ok ( list) = get_list {
36- let mut storge: String = String :: new ( ) ;
37- storge. push ( '[' ) ;
38- storge. push ( '\n' ) ;
39- if !list[ 0 ] . is_empty ( ) {
40- //app.subs = list[0].clone();
41- app. stateoflist = true ;
42- app. state [ app. subsindex ] . select ( Some ( 0 ) ) ;
43- for alist in & list[ 0 ] {
44- let information = spider:: Information :: new ( alist. to_string ( ) ) ;
45- app. informations [ 0 ] . push ( information. clone ( ) ) ;
46- storge. push_str ( information. get_the_json_node ( ) . as_str ( ) ) ;
47- }
48- app. subs [ 0 ] = app
49- . informations [ 0 ]
50- . iter ( )
51- . map ( |ainformation| {
52- spider:: remove_quotation ( ainformation. ps . clone ( ) )
53- } )
54- . collect ( ) ;
55- }
56- storge. pop ( ) ;
57- storge. pop ( ) ;
58- storge. push ( '\n' ) ;
59- storge. push ( ']' ) ;
60- utils:: create_json_file ( utils:: Save :: Storage , storge)
61- . unwrap_or_else ( |err| panic ! ( "err {}" , err) ) ;
62- }
63-
64- //app.subs.push(app.input.drain(..).collect());
34+ app. input = "This should be a search bar" . to_string ( ) ;
6535 }
6636 KeyCode :: Char ( c) => {
6737 app. input . push ( c) ;
@@ -80,6 +50,8 @@ pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
8050 //KeyCode::Left => app.unselect(),
8151 KeyCode :: Down => app. next ( ) ,
8252 KeyCode :: Up => app. previous ( ) ,
53+ KeyCode :: Left => app. left ( ) ,
54+ KeyCode :: Right => app. right ( ) ,
8355 KeyCode :: Esc => {
8456 app. unselect ( ) ;
8557 app. input_mode = InputMode :: Normal ;
@@ -137,8 +109,8 @@ pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
137109 let mut subscribe_json: String = "[\n \n " . to_string ( ) ;
138110 for asub in & app. subscription {
139111 subscribe_json. push_str ( & format ! (
140- "{{ \n \
141- \" url\" : \" {}\" \n \
112+ "{{\n \
113+ \" url\" : \" {}\" \n \
142114 }},\n ",
143115 asub
144116 ) ) ;
@@ -151,32 +123,46 @@ pub(crate) fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
151123 // .collect();
152124 let get_list = spider:: get_the_key ( app. subscription . clone ( ) ) ;
153125 if let Ok ( list) = get_list {
154- let mut storge: String = String :: new ( ) ;
155- storge. push ( '[' ) ;
156- storge. push_str ( "\n \n " ) ;
157- if !list. is_empty ( ) && !list[ 0 ] . is_empty ( ) {
158- //app.subs = list[0].clone();
159- app. stateoflist = true ;
160- app. state [ app. subsindex ] . select ( Some ( 0 ) ) ;
161- for alist in & list[ 0 ] {
162- let information = spider:: Information :: new ( alist. to_string ( ) ) ;
163- app. informations [ 0 ] . push ( information. clone ( ) ) ;
164- storge. push_str ( information. get_the_json_node ( ) . as_str ( ) ) ;
126+ if !list. is_empty ( ) {
127+ let mut storge: String = "[\n \n " . to_string ( ) ;
128+ let mut subs : Vec < Vec < String > > =Vec :: new ( ) ;
129+ let mut information : Vec < Vec < spider:: Information > > = Vec :: new ( ) ;
130+ let mut state: Vec < ListState > = Vec :: new ( ) ;
131+ for lista in list {
132+ let mut ainformation: Vec < spider:: Information > = Vec :: new ( ) ;
133+ //let mut asub: Vec<String> = Vec::new();
134+ storge. push_str ( "[\n \n " ) ;
135+ if !lista. is_empty ( ) {
136+ for alist in lista {
137+ let inform = spider:: Information :: new ( alist. to_string ( ) ) ;
138+ ainformation. push ( inform. clone ( ) ) ;
139+ storge. push_str ( & inform. get_the_json_node ( ) ) ;
140+
141+ }
142+ storge. pop ( ) ;
143+ storge. pop ( ) ;
144+ storge. push_str ( "\n ]," ) ;
145+ }
146+ state. push ( ListState :: default ( ) ) ;
147+ subs. push ( ainformation
148+ . iter ( )
149+ . map ( |ainfor| spider:: remove_quotation ( ainfor. ps . clone ( ) ) )
150+ . collect ( ) ) ;
151+ information. push ( ainformation) ;
152+
165153 }
166- app. subs [ 0 ] = app
167- . informations [ 0 ]
168- . iter ( )
169- . map ( |ainformation| {
170- spider:: remove_quotation ( ainformation. ps . clone ( ) )
171- } )
172- . collect ( ) ;
154+ app. state = state;
155+ app. subs = subs;
156+ app. informations = information;
157+ storge. pop ( ) ;
158+ storge. push_str ( "\n ]" ) ;
159+ utils:: create_json_file ( utils:: Save :: Storage , storge)
160+ . unwrap_or_else ( |err| panic ! ( "err {}" , err) ) ;
161+ app. subsindex = 0 ;
162+ app. state [ 0 ] . select ( Some ( 0 ) ) ;
163+ app. stateoflist =true ;
164+
173165 }
174- storge. pop ( ) ;
175- storge. pop ( ) ;
176- storge. push ( '\n' ) ;
177- storge. push ( ']' ) ;
178- utils:: create_json_file ( utils:: Save :: Storage , storge)
179- . unwrap_or_else ( |err| panic ! ( "err {}" , err) ) ;
180166 }
181167 }
182168 _ => { }
0 commit comments