Skip to content

Commit 01e01d5

Browse files
committed
Add support for adding profile picture
1 parent 682b23e commit 01e01d5

File tree

9 files changed

+28
-13
lines changed

9 files changed

+28
-13
lines changed

pgml-dashboard/src/components/navigation/navbar/web_app/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::components::{StaticNav, StaticNavLink};
2+
use crate::models::User;
23
use crate::utils::config;
34
use pgml_components::component;
45
use sailfish::TemplateOnce;
@@ -9,14 +10,16 @@ pub struct WebApp {
910
pub standalone_dashboard: bool,
1011
pub links: Vec<StaticNavLink>,
1112
pub account_management_nav: StaticNav,
13+
pub user: User,
1214
}
1315

1416
impl WebApp {
15-
pub fn new(links: Vec<StaticNavLink>, account_management_nav: StaticNav) -> WebApp {
17+
pub fn new(links: Vec<StaticNavLink>, account_management_nav: StaticNav, user: User) -> WebApp {
1618
WebApp {
1719
standalone_dashboard: config::standalone_dashboard(),
1820
links,
1921
account_management_nav,
22+
user,
2023
}
2124
}
2225
}

pgml-dashboard/src/components/navigation/navbar/web_app/template.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
<!-- Button to toggle collapsed menu for less than lg screens -->
2323
<button class="navbar-toggler collapsed topnav-controlls" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
24-
<%+ ProfileIcon::new() %>
24+
<%+ ProfileIcon::new(user.profile_picture.clone()) %>
2525
</button>
2626
</div>
2727

@@ -63,7 +63,7 @@
6363
<li class="d-none d-lg-flex nav-item align-items-center">
6464
<%+
6565
Dropdown::nav(account_management_nav.links.clone())
66-
.icon(ProfileIcon::new().into())
66+
.icon(ProfileIcon::new(user.profile_picture.clone()).into())
6767
.expandable()
6868
%>
6969
</li>

pgml-dashboard/src/components/profile_icon/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ use sailfish::TemplateOnce;
33

44
#[derive(TemplateOnce, Default)]
55
#[template(path = "profile_icon/template.html")]
6-
pub struct ProfileIcon;
6+
pub struct ProfileIcon {
7+
pub profile_picture: Option<String>,
8+
}
79

810
impl ProfileIcon {
9-
pub fn new() -> ProfileIcon {
10-
ProfileIcon
11+
pub fn new(profile_picture: Option<String>) -> ProfileIcon {
12+
ProfileIcon { profile_picture }
1113
}
1214
}
1315

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
<% if let Some(profile_picture) = profile_picture { %>
2+
<img src="<%- profile_picture %>" width="44" height="44" class="rounded-circle">
3+
<% } else { %>
4+
15
<svg class="rounded-circle" width="44" height="44" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
26
<path d="M5 20V19C5 16.2386 7.23858 14 10 14H14C16.7614 14 19 16.2386 19 19V20M16 7C16 9.20914 14.2091 11 12 11C9.79086 11 8 9.20914 8 7C8 4.79086 9.79086 3 12 3C14.2091 3 16 4.79086 16 7Z" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
37
</svg>
8+
9+
<% } %>

pgml-dashboard/src/models.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,13 +961,15 @@ impl UploadedFile {
961961
pub struct User {
962962
pub id: i64,
963963
pub email: String,
964+
pub profile_picture: Option<String>,
964965
}
965966

966967
impl Default for User {
967968
fn default() -> User {
968969
User {
969970
id: -1,
970971
email: "".to_string(),
972+
profile_picture: None,
971973
}
972974
}
973975
}

pgml-dashboard/src/templates/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ pub struct WebAppBase<'a> {
127127
pub upper_left_nav: StaticNav,
128128
pub lower_left_nav: StaticNav,
129129
pub body_components: Vec<Component>,
130+
pub user: models::User,
130131
}
131132

132133
impl<'a> WebAppBase<'a> {
@@ -139,6 +140,7 @@ impl<'a> WebAppBase<'a> {
139140
account_management_nav: context.account_management_nav.clone(),
140141
upper_left_nav: context.upper_left_nav.clone(),
141142
lower_left_nav: context.lower_left_nav.clone(),
143+
user: context.user.clone(),
142144
..Default::default()
143145
}
144146
}

pgml-dashboard/static/css/scss/components/_icon.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@
110110
color: #{$neon-tint-100};
111111
}
112112

113-
svg {
113+
svg,img {
114114
border-color: #{$neon-tint-100};
115115
}
116116

117117
}
118118

119-
svg {
119+
svg,img {
120120
border: 2px solid #{$gray-700};
121121
background-color: #{$gray-500};
122122
}

pgml-dashboard/templates/content/playground.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ <h3 class="h3">icons</h3>
1919
<%+ GithubIcon::new() %>
2020
</div>
2121
<div class="mb-3">
22-
<%+ ProfileIcon %>
22+
<%+ ProfileIcon::new(None) %>
2323
</div>
2424

2525
<h3 class="h3">Dropdowns</h3>
@@ -33,7 +33,7 @@ <h3 class="h3">Dropdowns</h3>
3333
StaticNavLink::new("Starts Active".into(), "#test".into()).active(true)
3434
]
3535
).collapsable()
36-
.icon(ProfileIcon::new().into()) %>
36+
.icon(ProfileIcon::new(None).into()) %>
3737
</div>
3838
<div class="col-6" style="min-height: 400px;">
3939
<%+ Dropdown::nav(

pgml-dashboard/templates/layout/web_app_base.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
<main>
2525
<div class="container-fluid p-0 min-vh-lg-100">
2626
<div class="row gx-0 min-vh-lg-100 gy-0">
27-
<%+ WebAppNavbar::new(left_nav_links, account_management_nav) %>
27+
<%+ WebAppNavbar::new(left_nav_links, account_management_nav, user) %>
2828

2929
<div class="d-flex">
30-
<%+ WebAppLeftNav::new( upper_left_nav, lower_left_nav, dropdown_nav ) %>
30+
<%+ WebAppLeftNav::new(upper_left_nav, lower_left_nav, dropdown_nav) %>
3131

3232
<div class="clear-from-under-navbar flex-grow-1 min-vw-0">
3333
<div class="px-4 px-sm-5 py-3" style="position: absolute">
34-
<%- Breadcrumbs::render( breadcrumbs ) %>
34+
<%- Breadcrumbs::render(breadcrumbs) %>
3535
</div>
3636

3737
<div class="px-xs-2 px-md-5 overflow-hidden" style="padding-top: 57px;">

0 commit comments

Comments
 (0)