Skip to content

Commit

Permalink
➕💄 adds yew bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
chriamue committed Sep 25, 2023
1 parent 09d4bae commit 83cd627
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 24 deletions.
11 changes: 11 additions & 0 deletions app/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ wasm-bindgen = "0.2.86"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = ['Location'] }
yew = { version = "0.20", features = ["csr"] }
yew-bootstrap = "0.5.18"
2 changes: 1 addition & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<meta name="author" content="chriamue">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link data-trunk href="./styles/index.css" rel="css" />
<link data-trunk href="styles/index.css" rel="css" />
<link data-trunk rel="icon" href="favicon.ico" />
<link data-trunk rel="copy-file" href="src/assets/github-brands.svg" />
</head>
Expand Down
3 changes: 3 additions & 0 deletions app/src/about.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use yew::prelude::*;
use yew_bootstrap::component::{Container, ContainerSize};

#[function_component(About)]
pub fn comp() -> Html {
html! {
<div class="about">
<Container class="bg-info" size={ContainerSize::ExtraLarge}>
<p>{"
The goal of this project is a raspberry pi device with a camera, that
films your garden. If it detects a bird, it takes a picture and identifies
Expand All @@ -15,6 +17,7 @@ pub fn comp() -> Html {
pictures.
"}
</p>
</Container>
</div>
}
}
5 changes: 5 additions & 0 deletions app/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use yew::prelude::*;
use yew_bootstrap::component::*;
use yew_bootstrap::util::*;

use crate::about::About;
use crate::contexts::ApiUrlProvider;
Expand All @@ -15,8 +17,11 @@ pub fn app() -> Html {
<ApiUrlProvider>
<Header />
<ServerInput />
<Line style={Color::Primary} />
<Webcam />
<Line style={Color::Primary} />
<SightingsContainer />
<Line style={Color::Primary} />
<About />
<Footer />
</ApiUrlProvider>
Expand Down
10 changes: 5 additions & 5 deletions app/src/contexts/api_url_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ impl Default for ApiUrl {
.protocol()
.unwrap_or_else(|_| String::from("http:"));
let host = web_sys::window()
.unwrap()
.location()
.host()
.unwrap_or_else(|_| String::from("localhost:8080"));
.unwrap()
.location()
.host()
.unwrap_or_else(|_| String::from("localhost:8080"));
Self {
inner: format!("{}//{}/", protocol, host)
inner: format!("{}//{}/", protocol, host),
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions app/src/server_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::contexts::ApiUrlContext;
use wasm_bindgen::JsCast;
use web_sys::{EventTarget, HtmlInputElement};
use yew::prelude::*;
use yew_bootstrap::{component::{Button, Container, ContainerSize}, util::Color};

#[function_component(ServerInput)]
pub fn server_input() -> Html {
Expand All @@ -22,12 +23,14 @@ pub fn server_input() -> Html {

html! {
<div>
<Container class="bg-primary" size={ContainerSize::Medium}>
<input type="text" value={input_value.clone()} onchange={on_input} placeholder="Enter server URL" />
<button onclick={Callback::from(move |_| {
<Button style={Color::Secondary} onclick={Callback::from(move |_| {
web_sys::console::log_1(&format!("Server URL set to: {}", api_url.inner).into());
})}>
{"Set Server URL"}
</button>
</Button>
</Container>
</div>
}
}
24 changes: 9 additions & 15 deletions app/src/sightings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use chrono::{DateTime, NaiveDateTime, Utc};
use serde::{Deserialize, Serialize};
use std::sync::{Arc, Mutex};
use yew::prelude::*;
use yew_bootstrap::component::Button;
use yew_bootstrap::util::Color;

use crate::contexts::{ApiUrl, ApiUrlContext};

Expand Down Expand Up @@ -112,14 +114,6 @@ impl Component for Sightings {
}

fn changed(&mut self, ctx: &Context<Self>, _old_props: &Self::Properties) -> bool {
web_sys::console::log_1(
&format!(
"Changed sightings {} : {}",
self.api_url,
ctx.props().api_url
)
.into(),
);
if self.api_url != ctx.props().api_url {
self.api_url = ctx.props().api_url.clone();
self.fetch();
Expand All @@ -129,7 +123,7 @@ impl Component for Sightings {
}
}

fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
fn update(&mut self, _ctx: &Context<Self>, msg: Self::Message) -> bool {
match msg {
Msg::ClickLeft => {
self.prev();
Expand Down Expand Up @@ -162,17 +156,17 @@ impl Component for Sightings {
html! {
<>
<div class="nav">
<button class="btn btn-primary" onclick={onleftclick.clone()}>
{"<-"} </button>
<button class="btn btn-primary" onclick={onrightclick.clone()}>{"->"}</button>
<Button style={Color::Primary} onclick={onleftclick.clone()}>
{"<-"} </Button>
<Button style={Color::Primary} onclick={onrightclick.clone()}>{"->"}</Button>
</div>
<div id="images" class="row card justify-content-center d-grid gap-3">
{details}
</div>
<div class="nav">
<button class="btn btn-primary" onclick={onleftclick}>
{"<-"} </button>
<button class="btn btn-primary" onclick={onrightclick}>{"->"}</button>
<Button style={Color::Primary} onclick={onleftclick}>
{"<-"} </Button>
<Button style={Color::Primary} onclick={onrightclick}>{"->"}</Button>
</div>
</>
}
Expand Down
3 changes: 2 additions & 1 deletion app/styles/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
text-align: center;
width: 400px;
background: #42b983;
}
border-radius: 10px;
}

0 comments on commit 83cd627

Please sign in to comment.