80 lines
2.0 KiB
Rust
80 lines
2.0 KiB
Rust
use gpui::{ParentElement, Styled, div};
|
|
|
|
use crate::component::button::button;
|
|
use crate::query::{self, QueryStatus, read_query, use_lazy_query};
|
|
use crate::{
|
|
api, app,
|
|
component::{
|
|
font_icon::{FontIcon, font_icon},
|
|
text::text,
|
|
},
|
|
};
|
|
|
|
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),
|
|
}
|
|
}
|
|
|
|
impl gpui::Render for TitleBar {
|
|
fn render(
|
|
&mut self,
|
|
_window: &mut gpui::Window,
|
|
cx: &mut gpui::Context<Self>,
|
|
) -> impl gpui::IntoElement {
|
|
let g = cx.global::<app::Global>();
|
|
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"),
|
|
),
|
|
|
|
| _ => div(),
|
|
};
|
|
|
|
div()
|
|
.flex_row()
|
|
.justify_center()
|
|
.items_center()
|
|
.w_full()
|
|
.h_10()
|
|
.flex()
|
|
.px(g.safe_area.size.width)
|
|
.py_2()
|
|
.bg(g.current_theme.colors.surface_chrome)
|
|
.text_color(g.current_theme.colors.text)
|
|
.relative()
|
|
.border_b_1()
|
|
.border_color(g.current_theme.colors.border)
|
|
.child(repo_selector(cx))
|
|
.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())
|
|
}
|