@@ -4,6 +4,7 @@ use crate::vfs_data::{find_node, format_path, resolve_path, VfsKind, VfsNode};
44use micro_cli:: Parser ;
55use shell_parser:: integration:: { CommandInfo , ExecutableCommand } ;
66use std:: cmp:: Ordering ;
7+ use wasm_bindgen_futures:: spawn_local;
78use yew:: prelude:: * ;
89
910#[ derive( Parser , Debug , Default ) ]
@@ -112,7 +113,20 @@ impl LsCommand {
112113 ( None , None ) => a. metadata . name . cmp ( & b. metadata . name ) ,
113114 } ) ;
114115
115- ctx. terminal . push_component ( render_posts ( & posts) ) ;
116+ let on_post_click = {
117+ let terminal = ctx. terminal . clone ( ) ;
118+ Callback :: from ( move |metadata : VfsNode | {
119+ let terminal = terminal. clone ( ) ;
120+ let path = format ! ( "/posts/{}" , metadata. path. clone( ) ) ;
121+
122+ spawn_local ( async move {
123+ terminal. execute_command ( & format ! ( "navigate {path}" ) ) . await ;
124+ } ) ;
125+ } )
126+ } ;
127+
128+ ctx. terminal
129+ . push_component ( render_posts ( & posts, on_post_click) ) ;
116130 Ok ( ( ) )
117131 }
118132}
@@ -147,12 +161,12 @@ impl PostEntry {
147161 }
148162}
149163
150- fn render_posts ( posts : & [ PostEntry ] ) -> Html {
164+ fn render_posts ( posts : & [ PostEntry ] , on_click : Callback < VfsNode > ) -> Html {
151165 html ! {
152166 <div class="py-6 space-y-3" >
153167 { for posts. iter( ) . map( |post| {
154168 html! {
155- <PostItem metadata={ post. metadata. clone( ) } />
169+ <PostItem metadata={ post. metadata. clone( ) } on_click= { on_click . clone ( ) } />
156170 }
157171 } ) }
158172 </div>
0 commit comments