Skip to content

Commit 3b7eb26

Browse files
committed
fixed some examples
1 parent eab0351 commit 3b7eb26

3 files changed

Lines changed: 67 additions & 58 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ repository = "https://github.com/Synphonyte/leptos-struct-table"
1313

1414
[dependencies]
1515
leptos = { version = "0.7.0" }
16-
leptos-struct-table-macro = { version = "0.12.0", path = "../leptos-struct-table-macro" }
17-
leptos-use = { version = "0.15.0", path = "../leptos-use" }
16+
leptos-struct-table-macro = { version = "0.12.0" }
17+
leptos-use = { version = "0.15.2" }
1818
rust_decimal = { version = "1.35", optional = true }
1919
chrono = { version = "0.4", optional = true }
2020
send_wrapper = "0.6"

examples/editable/src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ pub struct Book {
2121
}
2222

2323
impl TableDataProvider<Book> for RwSignal<Vec<Book>> {
24-
async fn get_rows(&self, range: Range<usize>) -> Result<(Vec<Book>, Range<usize>), String> {
25-
Ok((self.get_untracked()[range.clone()].to_vec(), range))
24+
async fn get_rows(&self, _: Range<usize>) -> Result<(Vec<Book>, Range<usize>), String> {
25+
let books = self.get_untracked().to_vec();
26+
let len = books.len();
27+
Ok((books, 0..len))
2628
}
2729

2830
async fn row_count(&self) -> Option<usize> {

examples/i18n/src/main.rs

Lines changed: 61 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -35,62 +35,69 @@ fn main() {
3535
console_error_panic_hook::set_once();
3636

3737
mount_to_body(|| {
38-
let rows = vec![
39-
Book {
40-
id: Uuid::new_v4(),
41-
title: "The Great Gatsby".to_string(),
42-
author: "F. Scott Fitzgerald".to_string(),
43-
publish_date: Some(NaiveDate::from_ymd_opt(1925, 4, 10).unwrap()),
44-
read_date: Some(Date::from_calendar_date(2024, ::time::Month::January, 2).unwrap()),
45-
desc: Some(
46-
"A story of wealth, love, and the American Dream in the 1920s.".to_string(),
47-
),
48-
hidden_field: "hidden".to_string(),
49-
},
50-
Book {
51-
id: Uuid::new_v4(),
52-
title: "The Grapes of Wrath".to_string(),
53-
author: "John Steinbeck".to_string(),
54-
publish_date: Some(NaiveDate::from_ymd_opt(1939, 4, 14).unwrap()),
55-
read_date: None,
56-
desc: None,
57-
hidden_field: "not visible in the table".to_string(),
58-
},
59-
Book {
60-
id: Uuid::new_v4(),
61-
title: "Nineteen Eighty-Four".to_string(),
62-
author: "George Orwell".to_string(),
63-
publish_date: Some(NaiveDate::from_ymd_opt(1949, 6, 8).unwrap()),
64-
read_date: None,
65-
desc: None,
66-
hidden_field: "hidden".to_string(),
67-
},
68-
Book {
69-
id: Uuid::new_v4(),
70-
title: "Ulysses".to_string(),
71-
author: "James Joyce".to_string(),
72-
publish_date: Some(NaiveDate::from_ymd_opt(1922, 2, 2).unwrap()),
73-
read_date: None,
74-
desc: None,
75-
hidden_field: "hidden".to_string(),
76-
},
77-
];
38+
view! {
39+
<I18nContextProvider>
40+
<App />
41+
</I18nContextProvider>
42+
}
43+
})
44+
}
7845

79-
let i18n = provide_i18n_context();
46+
#[component]
47+
pub fn App() -> impl IntoView {
48+
let rows = vec![
49+
Book {
50+
id: Uuid::new_v4(),
51+
title: "The Great Gatsby".to_string(),
52+
author: "F. Scott Fitzgerald".to_string(),
53+
publish_date: Some(NaiveDate::from_ymd_opt(1925, 4, 10).unwrap()),
54+
read_date: Some(Date::from_calendar_date(2024, ::time::Month::January, 2).unwrap()),
55+
desc: Some("A story of wealth, love, and the American Dream in the 1920s.".to_string()),
56+
hidden_field: "hidden".to_string(),
57+
},
58+
Book {
59+
id: Uuid::new_v4(),
60+
title: "The Grapes of Wrath".to_string(),
61+
author: "John Steinbeck".to_string(),
62+
publish_date: Some(NaiveDate::from_ymd_opt(1939, 4, 14).unwrap()),
63+
read_date: None,
64+
desc: None,
65+
hidden_field: "not visible in the table".to_string(),
66+
},
67+
Book {
68+
id: Uuid::new_v4(),
69+
title: "Nineteen Eighty-Four".to_string(),
70+
author: "George Orwell".to_string(),
71+
publish_date: Some(NaiveDate::from_ymd_opt(1949, 6, 8).unwrap()),
72+
read_date: None,
73+
desc: None,
74+
hidden_field: "hidden".to_string(),
75+
},
76+
Book {
77+
id: Uuid::new_v4(),
78+
title: "Ulysses".to_string(),
79+
author: "James Joyce".to_string(),
80+
publish_date: Some(NaiveDate::from_ymd_opt(1922, 2, 2).unwrap()),
81+
read_date: None,
82+
desc: None,
83+
hidden_field: "hidden".to_string(),
84+
},
85+
];
8086

81-
let on_switch = move |_| {
82-
let new_lang = match i18n.get_locale() {
83-
Locale::en => Locale::de,
84-
Locale::de => Locale::en,
85-
};
86-
i18n.set_locale(new_lang);
87+
let i18n = use_i18n();
88+
89+
let on_switch = move |_| {
90+
let new_lang = match i18n.get_locale() {
91+
Locale::en => Locale::de,
92+
Locale::de => Locale::en,
8793
};
94+
i18n.set_locale(new_lang);
95+
};
8896

89-
view! {
90-
<button on:click=on_switch>{t!(i18n, click_to_change_lang)}</button>
91-
<table>
92-
<TableContent rows=rows scroll_container="html" />
93-
</table>
94-
}
95-
})
97+
view! {
98+
<button on:click=on_switch>{t!(i18n, click_to_change_lang)}</button>
99+
<table>
100+
<TableContent rows=rows scroll_container="html" />
101+
</table>
102+
}
96103
}

0 commit comments

Comments
 (0)