maixnor_super_amazing_component_lib/
lib.rs1use serde::Deserialize;
2use yew::prelude::*;
3
4#[derive(Properties, PartialEq, Clone, Deserialize)]
5struct Video {
6 id: usize,
7 title: String,
8 speaker: String,
9 url: String,
10}
11
12#[derive(Properties, PartialEq)]
13struct VideosListProps {
14 videos: Vec<Video>,
15 on_click: Callback<Video>,
16}
17
18#[function_component(VideosList)]
19fn videos_list(VideosListProps { videos, on_click }: &VideosListProps) -> Html {
20 let on_click = on_click.clone();
21 videos.iter().map(|video| {
22 let on_video_select = {
23 let on_click = on_click.clone();
24 let video = video.clone();
25 Callback::from(move |_| {
26 on_click.emit(video.clone())
27 })
28 };
29
30 html! {
31 <p key={video.id} onclick={on_video_select}>{format!("{}: {}", video.speaker, video.title)}</p>
32 }
33 }).collect()
34}
35
36#[derive(Properties, PartialEq)]
37struct VideosDetailsProps {
38 video: Video,
39}
40
41#[function_component(VideoDetails)]
42fn video_details(VideosDetailsProps { video }: &VideosDetailsProps) -> Html {
43 html! {
44 <div>
45 <h3>{ video.title.clone() }</h3>
46 <img src="https://via.placeholder.com/640x360.png?text=Video+Player+Placeholder" alt="video thumbnail" />
47 </div>
48 }
49}