Skip to content

Commit 26a5e69

Browse files
committed
add footer
1 parent 28966d7 commit 26a5e69

File tree

9 files changed

+114
-4
lines changed

9 files changed

+114
-4
lines changed

devblog/devblog/client/src/api.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use gloo::console::log;
22
use gloo_net::http::{Headers, Method, RequestBuilder, Response};
3-
// use serde_json::to_string_pretty;
43
use wasm_bindgen::JsValue;
54

65
const URL: &str = "https://localhost:44482/api/";
@@ -12,6 +11,7 @@ pub enum Api {
1211
GetPostsCount,
1312
GetPagesCount,
1413
GetUsers,
14+
GetCurrentUser,
1515
SignIn,
1616
SignUp,
1717
}
@@ -53,6 +53,7 @@ impl Api {
5353
Api::GetPostsCount => format!("{}posts/countPosts", URL),
5454
Api::GetPagesCount => format!("{}posts/countPages", URL),
5555
Api::GetUsers => format!("{}accounts", URL),
56+
Api::GetCurrentUser => format!("{}accounts/user", URL),
5657
Api::SignIn => format!("{}accounts/signin", URL),
5758
Api::SignUp => format!("{}accounts/signup", URL),
5859
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use crate::store::Store;
2+
use stylist::Style;
3+
use yew::{function_component, html, Html};
4+
use yewdux::prelude::*;
5+
6+
const STYLE: &str = include_str!("styles/footer.css");
7+
8+
#[function_component(Footer)]
9+
pub fn footer() -> Html {
10+
let style = Style::new(STYLE).unwrap();
11+
let store = use_store_value::<Store>();
12+
13+
html! {
14+
<div class={style}>
15+
<div class="footer">
16+
// <DeleteAccount />
17+
// {loggedIn &&
18+
<span>{"Welcome "}{store.username.clone()}</span>
19+
// }
20+
</div>
21+
</div>
22+
}
23+
}

devblog/devblog/client/src/components/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod comment;
2+
pub mod footer;
23
pub mod items;
34
pub mod navbar;
45
pub mod pager;

devblog/devblog/client/src/components/navbar.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub fn navbar() -> Html {
2424
<Link<Route> to={Route::AddPost}>{"AddPost"}</Link<Route>>
2525
<Link<Route> to={Route::About}>{"About"}</Link<Route>>
2626
<Link<Route> to={Route::Insights}>{"Insights"}</Link<Route>>
27+
<Link<Route> to={Route::Account}>{"Account"}</Link<Route>>
2728
<Link<Route> to={Route::SignIn}>{"SignIn"}</Link<Route>>
2829
<Link<Route> to={Route::SignOut}>{"SignOut"}</Link<Route>>
2930
<Link<Route> to={Route::SignUp}>{"SignUp"}</Link<Route>>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.footer {
2+
height: 50;
3+
width: 100vw;
4+
bottom: 0;
5+
left: 0;
6+
position: fixed;
7+
z-index: 10;
8+
display: flex;
9+
}
10+
11+
.footer button,
12+
.footer>span {
13+
padding: 5px;
14+
margin: 10px;
15+
}
16+
17+
.footer button {
18+
height: fit-content;
19+
}
20+
21+
.footer>span {
22+
margin-left: auto;
23+
margin-right: 20px;
24+
}

devblog/devblog/client/src/helpers.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub fn onsubmit(
4949
let obj: Store = serde_json::from_str(&res.text().await.unwrap()).unwrap();
5050
dispatch_clone.reduce_mut(move |store| {
5151
store.token = obj.token;
52+
store.username = obj.username;
5253
});
5354
nav.push(&Route::Home);
5455
}

devblog/devblog/client/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ mod pages;
66
mod router;
77
mod store;
88

9-
use crate::router::{switch, Route};
9+
use crate::{
10+
components::footer::Footer,
11+
router::{switch, Route},
12+
};
1013
use api::*;
1114
use components::navbar::Navbar;
1215
use models::*;
@@ -29,6 +32,7 @@ pub fn app() -> Html {
2932
<BrowserRouter>
3033
<Navbar />
3134
<Switch<Route> render={switch} />
35+
<Footer />
3236
</BrowserRouter>
3337
</div>
3438
}
Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,55 @@
1+
use gloo_net::http::{Headers, Method};
2+
use stylist::Style;
13
use yew::prelude::*;
4+
use yewdux::use_store_value;
5+
6+
use crate::{
7+
helpers::{self, CustomCallback},
8+
store::Store,
9+
Api, User,
10+
};
11+
12+
const STYLE: &str = include_str!("styles/account.css");
213

314
#[function_component(Account)]
415
pub fn account() -> Html {
16+
let style = Style::new(STYLE).unwrap();
17+
let user = use_state(User::default);
18+
let user_cb = CustomCallback::new(&user);
19+
let store = use_store_value::<Store>();
20+
21+
// get current user
22+
use_effect_with((), |_| {
23+
wasm_bindgen_futures::spawn_local(async move {
24+
let hdrs = Headers::new();
25+
let auth = format!("Bearer {}", store.token.clone());
26+
hdrs.append("Authorization", &auth);
27+
28+
let res = Api::GetCurrentUser
29+
.fetch(Some(hdrs), None, Method::GET)
30+
.await;
31+
32+
helpers::emit(&user_cb, res.unwrap()).await;
33+
})
34+
});
35+
536
html! {
6-
<section>
7-
<h1>{"Account Page"}</h1>
37+
<section class={style}>
38+
<div class="account">
39+
<div>
40+
<h1>{"Account Details"}</h1>
41+
<p>{"Username: "}{&user.username}</p>
42+
<p>{"Email: "}{&user.email}</p>
43+
</div>
44+
<div>
45+
<h1>{"Email Preferences"}</h1>
46+
<input type="checkbox"
47+
checked={user.subscribed}
48+
// onClick={handleSubscribeChange}
49+
/>
50+
<span>{"Subscribed"}</span>
51+
</div>
52+
</div>
853
</section>
954
}
1055
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.account {
2+
font-family: 'Chivo Mono', monospace;
3+
font-size: 16px;
4+
margin-top: 100px;
5+
6+
}
7+
8+
.account>div>h1 {
9+
border-bottom: 1px solid grey;
10+
}

0 commit comments

Comments
 (0)