-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
main.rs
84 lines (79 loc) · 2.73 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#![deny(missing_docs)]
//! Simple showcase example.
use ::chrono::NaiveDate;
use ::time::Date;
use ::uuid::Uuid;
use leptos::*;
use leptos_struct_table::*;
/// This generates the component BookTable
#[derive(TableRow, Clone)]
#[table(sortable, impl_vec_data_provider)]
pub struct Book {
/// Id of the entry.
pub id: Uuid,
/// Title of the book.
pub title: String,
/// Author of the book.
pub author: String,
/// Date when book has been published.
pub publish_date: Option<NaiveDate>,
/// Date when book was read
pub read_date: Option<Date>,
/// Description of the book. Optional.
#[table(none_value = "-")]
pub description: Option<String>,
/// Example on hidden member.
#[table(skip)]
pub hidden_field: String,
}
fn main() {
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
mount_to_body(|| {
let rows = vec![
Book {
id: Uuid::new_v4(),
title: "The Great Gatsby".to_string(),
author: "F. Scott Fitzgerald".to_string(),
publish_date: Some(NaiveDate::from_ymd_opt(1925, 4, 10).unwrap()),
read_date: Some(Date::from_calendar_date(2024, ::time::Month::January, 2).unwrap()),
description: Some(
"A story of wealth, love, and the American Dream in the 1920s.".to_string(),
),
hidden_field: "hidden".to_string(),
},
Book {
id: Uuid::new_v4(),
title: "The Grapes of Wrath".to_string(),
author: "John Steinbeck".to_string(),
publish_date: Some(NaiveDate::from_ymd_opt(1939, 4, 14).unwrap()),
read_date: None,
description: None,
hidden_field: "not visible in the table".to_string(),
},
Book {
id: Uuid::new_v4(),
title: "Nineteen Eighty-Four".to_string(),
author: "George Orwell".to_string(),
publish_date: Some(NaiveDate::from_ymd_opt(1949, 6, 8).unwrap()),
read_date: None,
description: None,
hidden_field: "hidden".to_string(),
},
Book {
id: Uuid::new_v4(),
title: "Ulysses".to_string(),
author: "James Joyce".to_string(),
publish_date: Some(NaiveDate::from_ymd_opt(1922, 2, 2).unwrap()),
read_date: None,
description: None,
hidden_field: "hidden".to_string(),
},
];
view! {
<table>
<TableContent rows=rows />
</table>
}
})
}