@@ -6,7 +6,10 @@ use icon::Icon;
66use leptos:: { either:: Either , prelude:: * } ;
77use leptos_router:: components:: A ;
88
9- use crate :: { server:: Entries , utils:: format_bytes} ;
9+ use crate :: {
10+ server:: Entries ,
11+ utils:: { encode_path, format_bytes} ,
12+ } ;
1013
1114#[ derive( Debug , Clone , Copy , PartialEq , PartialOrd , Ord , Eq ) ]
1215pub enum EntryType {
@@ -23,14 +26,15 @@ pub struct Entry {
2326 relative_time : String ,
2427}
2528
26- pub fn EntryComponent ( data : Entry ) -> impl IntoView {
29+ #[ component]
30+ pub fn EntryComponent ( entry : Entry ) -> impl IntoView {
2731 let Entry {
2832 type_,
2933 href,
3034 name,
3135 size,
3236 relative_time,
33- } = data ;
37+ } = entry ;
3438
3539 let inner = view ! {
3640 <div class="grid gap-2 w-full entry grid-cols-(--entry-cols-mobile) md:grid-cols-(--entry-cols)" >
@@ -74,7 +78,7 @@ pub fn FileEntries(path: Signal<PathBuf>, entries: Entries) -> impl IntoView {
7478 last_modified,
7579 } => Entry {
7680 type_ : EntryType :: File ,
77- href : format ! ( "/files/{}" , path. join( & name) . display ( ) ) ,
81+ href : format ! ( "/files/{}" , encode_path ( path. join( & name) ) ) ,
7882 name : name. clone ( ) ,
7983 size : Some ( format_bytes ( size) ) ,
8084 relative_time : last_modified. humanize ( ) ,
@@ -84,7 +88,7 @@ pub fn FileEntries(path: Signal<PathBuf>, entries: Entries) -> impl IntoView {
8488 last_modified,
8589 } => Entry {
8690 type_ : EntryType :: Folder ,
87- href : format ! ( "/index/{}" , path. join( & name) . display ( ) ) ,
91+ href : format ! ( "/index/{}" , encode_path ( path. join( & name) ) ) ,
8892 name : name. clone ( ) ,
8993 size : None ,
9094 relative_time : last_modified. humanize ( ) ,
@@ -94,7 +98,11 @@ pub fn FileEntries(path: Signal<PathBuf>, entries: Entries) -> impl IntoView {
9498
9599 entries. sort_unstable ( ) ;
96100
97- Either :: Right (
98- view ! { <div class="file-view" >{ entries. into_iter( ) . map( EntryComponent ) . collect_view( ) } </div> } ,
99- )
101+ Either :: Right ( view ! {
102+ <div class="file-view" >
103+ <For each=move || entries. clone( ) key=|entry| entry. href. clone( ) let : entry>
104+ <EntryComponent entry=entry />
105+ </For >
106+ </div>
107+ } )
100108}
0 commit comments