Files
novem/src/screen/dashboard/titlebar.rs

80 lines
2.0 KiB
Rust
Raw Normal View History

use gpui::{ParentElement, Styled, div};
2026-04-20 15:13:26 +01:00
2026-04-21 11:50:04 +01:00
use crate::component::button::button;
use crate::query::{self, QueryStatus, read_query, use_lazy_query};
2026-04-21 11:50:04 +01:00
use crate::{
api, app,
component::{
font_icon::{FontIcon, font_icon},
text::text,
},
};
2026-04-20 15:13:26 +01:00
2026-04-21 20:30:41 +01:00
pub struct TitleBar {
fetch_user_query: query::Entity<api::user::Fetch>,
}
2026-04-20 15:13:26 +01:00
pub struct RepoSelector {}
2026-04-26 16:06:49 +01:00
pub fn new(cx: &mut gpui::Context<TitleBar>) -> TitleBar {
TitleBar {
2026-05-06 01:42:38 +08:00
fetch_user_query: use_lazy_query(api::user::Fetch, cx),
2026-04-21 11:50:04 +01:00
}
}
2026-04-20 15:13:26 +01:00
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>();
2026-04-21 20:30:41 +01:00
let user = read_query(&self.fetch_user_query, cx);
2026-04-21 11:50:04 +01:00
let user_avatar = match user {
| QueryStatus::Err(api::Error::Unauthenticated) => div().absolute().right_2p5().child(
2026-04-23 11:18:43 +01:00
button("login-btn")
2026-04-26 00:29:31 +01:00
.leading(font_icon(FontIcon::Github))
2026-04-21 20:30:41 +01:00
.label("Login"),
),
2026-04-21 11:50:04 +01:00
| _ => div(),
2026-04-21 11:50:04 +01:00
};
2026-04-20 15:13:26 +01:00
div()
2026-04-21 11:50:04 +01:00
.flex_row()
.justify_center()
.items_center()
2026-04-20 15:13:26 +01:00
.w_full()
2026-04-21 11:50:04 +01:00
.h_10()
2026-04-20 15:13:26 +01:00
.flex()
.px(g.safe_area.size.width)
.py_2()
.bg(g.current_theme.colors.surface_chrome)
2026-04-20 15:13:26 +01:00
.text_color(g.current_theme.colors.text)
2026-04-21 11:50:04 +01:00
.relative()
2026-05-06 01:42:38 +08:00
.border_b_1()
.border_color(g.current_theme.colors.border)
2026-04-20 15:13:26 +01:00
.child(repo_selector(cx))
2026-04-21 11:50:04 +01:00
.child(user_avatar)
2026-04-20 15:13:26 +01:00
}
}
impl RepoSelector {
pub fn new(_cx: &mut gpui::Context<Self>) -> Self {
2026-04-20 15:13:26 +01:00
Self {}
}
}
2026-04-26 00:29:31 +01:00
fn repo_selector<T: 'static>(_cx: &gpui::Context<T>) -> gpui::Div {
2026-04-20 15:13:26 +01:00
div()
.flex()
.flex_row()
.items_center()
.gap_1()
.text_xs()
2026-04-26 00:29:31 +01:00
.child(font_icon(FontIcon::FolderGit).size_3())
2026-04-23 11:18:43 +01:00
.child(text("test/repo"))
2026-04-26 00:29:31 +01:00
.child(font_icon(FontIcon::ChevronDown).size_3())
2026-04-20 15:13:26 +01:00
}