feat: dashboard skeleton
This commit is contained in:
80
src/screen/dashboard/titlebar.rs
Normal file
80
src/screen/dashboard/titlebar.rs
Normal file
@@ -0,0 +1,80 @@
|
||||
use gpui::{ParentElement, Styled, TitlebarOptions, div};
|
||||
|
||||
use crate::component::button::button;
|
||||
use crate::query::{self, QueryStatus, read_query, use_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_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.background)
|
||||
.text_color(g.current_theme.colors.text)
|
||||
.relative()
|
||||
.child(repo_selector(cx))
|
||||
.child(user_avatar)
|
||||
}
|
||||
}
|
||||
|
||||
impl RepoSelector {
|
||||
pub fn new(cx: &mut gpui::Context<Self>) -> Self {
|
||||
use_query(api::repo::List, cx);
|
||||
use_query(api::user::Fetch, cx);
|
||||
|
||||
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