@@ -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