feat: clean up the titlebar
This commit is contained in:
@@ -1,24 +1,19 @@
|
||||
use gpui::{ParentElement, Styled, div};
|
||||
use gpui::{ParentElement, Styled, StyledImage, div, img};
|
||||
|
||||
use crate::component::button::button;
|
||||
use crate::query::{self, QueryStatus, read_query, use_lazy_query};
|
||||
use crate::query::{self, QueryStatus, read_query, use_query};
|
||||
use crate::{
|
||||
api, app,
|
||||
component::{
|
||||
font_icon::{FontIcon, font_icon},
|
||||
text::text,
|
||||
},
|
||||
component::font_icon::{FontIcon, font_icon},
|
||||
};
|
||||
|
||||
pub struct TitleBar {
|
||||
fetch_user_query: query::Entity<api::user::Fetch>,
|
||||
}
|
||||
|
||||
pub struct RepoSelector {}
|
||||
|
||||
pub fn new(cx: &mut gpui::Context<TitleBar>) -> TitleBar {
|
||||
TitleBar {
|
||||
fetch_user_query: use_lazy_query(api::user::Fetch, cx),
|
||||
fetch_user_query: use_query(api::user::Fetch, cx),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,13 +27,20 @@ impl gpui::Render for TitleBar {
|
||||
let user = read_query(&self.fetch_user_query, cx);
|
||||
|
||||
let user_avatar = match user {
|
||||
| QueryStatus::Err(api::Error::Unauthenticated) => div().absolute().right_2p5().child(
|
||||
button("login-btn")
|
||||
.leading(font_icon(FontIcon::Github))
|
||||
.label("Login"),
|
||||
),
|
||||
| QueryStatus::Err(_) => div().absolute().right_2p5().child(
|
||||
button("login-btn")
|
||||
.leading(font_icon(FontIcon::Github))
|
||||
.label("Login"),
|
||||
),
|
||||
|
||||
| _ => div(),
|
||||
| QueryStatus::Loading => div(),
|
||||
|
||||
| QueryStatus::Loaded(user) => div().size_6().child(
|
||||
img(gpui::SharedString::from(user.avatar_url.clone()))
|
||||
.rounded_full()
|
||||
.size_5()
|
||||
.object_fit(gpui::ObjectFit::ScaleDown),
|
||||
),
|
||||
};
|
||||
|
||||
div()
|
||||
@@ -48,30 +50,14 @@ impl gpui::Render for TitleBar {
|
||||
.w_full()
|
||||
.h_10()
|
||||
.flex()
|
||||
.px(g.safe_area.size.width)
|
||||
.py_2()
|
||||
.bg(gpui::red())
|
||||
.pl(g.safe_area.size.width)
|
||||
.pr_2()
|
||||
.pt_2()
|
||||
.bg(g.current_theme.colors.background)
|
||||
.text_color(g.current_theme.colors.text)
|
||||
.relative()
|
||||
.child(repo_selector(cx))
|
||||
.child(div().flex_1())
|
||||
.child(user_avatar)
|
||||
}
|
||||
}
|
||||
|
||||
impl RepoSelector {
|
||||
pub fn new(_cx: &mut gpui::Context<Self>) -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
fn repo_selector<T: 'static>(_cx: &gpui::Context<T>) -> gpui::Div {
|
||||
div()
|
||||
.flex()
|
||||
.flex_row()
|
||||
.items_center()
|
||||
.gap_1()
|
||||
.text_xs()
|
||||
.child(font_icon(FontIcon::FolderGit).size_3())
|
||||
.child(text("test/repo"))
|
||||
.child(font_icon(FontIcon::ChevronDown).size_3())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user