wip: refactor
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use coop_ui::{
|
||||
button::{Button, ButtonVariants},
|
||||
popup_menu::PopupMenuExt,
|
||||
Icon, IconName, Sizable,
|
||||
};
|
||||
use gpui::*;
|
||||
@@ -12,6 +13,8 @@ use crate::{
|
||||
states::{metadata::MetadataRegistry, signal::SignalRegistry},
|
||||
};
|
||||
|
||||
actions!(account, [ToDo]);
|
||||
|
||||
pub struct Account {
|
||||
public_key: PublicKey,
|
||||
metadata: Model<Option<Metadata>>,
|
||||
@@ -83,5 +86,12 @@ impl Render for Account {
|
||||
}
|
||||
})
|
||||
})
|
||||
.popup_menu(move |this, _cx| {
|
||||
this.menu("Profile", Box::new(ToDo))
|
||||
.menu("Contacts", Box::new(ToDo))
|
||||
.menu("Settings", Box::new(ToDo))
|
||||
.separator()
|
||||
.menu("Change account", Box::new(ToDo))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use coop_ui::{
|
||||
button::{Button, ButtonCustomVariant, ButtonRounded, ButtonVariants},
|
||||
dock::{DockArea, DockItem, DockPlacement},
|
||||
theme::{ActiveTheme, Theme, ThemeMode},
|
||||
ContextModal, IconName, Root, Sizable, TitleBar,
|
||||
theme::Theme,
|
||||
Root, TitleBar,
|
||||
};
|
||||
use gpui::*;
|
||||
use prelude::FluentBuilder;
|
||||
@@ -11,14 +10,20 @@ use std::sync::Arc;
|
||||
|
||||
use super::{
|
||||
account::Account,
|
||||
dock::{chat::ChatPanel, left_dock::LeftDock, welcome::WelcomePanel},
|
||||
dock::{chat::ChatPanel, contact::ContactPanel, left_dock::LeftDock, welcome::WelcomePanel},
|
||||
onboarding::Onboarding,
|
||||
};
|
||||
use crate::states::{account::AccountRegistry, chat::Room};
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Deserialize)]
|
||||
pub enum PanelKind {
|
||||
Room(Arc<Room>),
|
||||
Contact,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Deserialize)]
|
||||
pub struct AddPanel {
|
||||
pub room: Arc<Room>,
|
||||
pub panel: PanelKind,
|
||||
pub position: DockPlacement,
|
||||
}
|
||||
|
||||
@@ -80,19 +85,6 @@ impl AppView {
|
||||
}
|
||||
}
|
||||
|
||||
fn change_theme_mode(&mut self, _: &ClickEvent, cx: &mut ViewContext<Self>) {
|
||||
let mode = match cx.theme().mode.is_dark() {
|
||||
true => ThemeMode::Light,
|
||||
false => ThemeMode::Dark,
|
||||
};
|
||||
|
||||
// Change theme
|
||||
Theme::change(mode, cx);
|
||||
|
||||
// Rerender
|
||||
cx.refresh();
|
||||
}
|
||||
|
||||
fn init_layout(dock_area: WeakView<DockArea>, cx: &mut WindowContext) {
|
||||
let left = DockItem::panel(Arc::new(LeftDock::new(cx)));
|
||||
let center = Self::init_dock_items(&dock_area, cx);
|
||||
@@ -129,11 +121,22 @@ impl AppView {
|
||||
}
|
||||
|
||||
fn on_action_add_panel(&mut self, action: &AddPanel, cx: &mut ViewContext<Self>) {
|
||||
let chat_panel = Arc::new(ChatPanel::new(&action.room, cx));
|
||||
match &action.panel {
|
||||
PanelKind::Room(room) => {
|
||||
let panel = Arc::new(ChatPanel::new(room, cx));
|
||||
|
||||
self.dock.update(cx, |dock_area, cx| {
|
||||
dock_area.add_panel(chat_panel, action.position, cx);
|
||||
});
|
||||
self.dock.update(cx, |dock_area, cx| {
|
||||
dock_area.add_panel(panel, action.position, cx);
|
||||
});
|
||||
}
|
||||
PanelKind::Contact => {
|
||||
let panel = Arc::new(ContactPanel::new(cx));
|
||||
|
||||
self.dock.update(cx, |dock_area, cx| {
|
||||
dock_area.add_panel(panel, action.position, cx);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,59 +152,18 @@ impl Render for AppView {
|
||||
.child(
|
||||
TitleBar::new()
|
||||
// Left side
|
||||
.child(
|
||||
div()
|
||||
.flex()
|
||||
.items_center()
|
||||
.gap_2()
|
||||
.child(
|
||||
div().when_some(
|
||||
self.account.read(cx).as_ref(),
|
||||
|this, account| this.child(account.clone()),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
Button::new("new")
|
||||
.custom(
|
||||
ButtonCustomVariant::new(cx)
|
||||
.shadow(false)
|
||||
.color(cx.theme().primary)
|
||||
.border(cx.theme().primary)
|
||||
.foreground(cx.theme().primary_foreground)
|
||||
.active(cx.theme().primary_active)
|
||||
.hover(cx.theme().primary_hover),
|
||||
)
|
||||
.xsmall()
|
||||
.rounded(ButtonRounded::Size(px(24.)))
|
||||
.label("Compose")
|
||||
.on_click(move |_, cx| {
|
||||
cx.open_modal(move |modal, _| {
|
||||
modal.title("Compose").child("TODO").min_h(px(300.))
|
||||
});
|
||||
}),
|
||||
),
|
||||
)
|
||||
.child(div())
|
||||
// Right side
|
||||
.child(
|
||||
div()
|
||||
.flex()
|
||||
.items_center()
|
||||
.justify_end()
|
||||
.gap_1()
|
||||
.px_2()
|
||||
.gap_2()
|
||||
.child(
|
||||
Button::new("theme-mode")
|
||||
.map(|this| {
|
||||
if cx.theme().mode.is_dark() {
|
||||
this.icon(IconName::Sun)
|
||||
} else {
|
||||
this.icon(IconName::Moon)
|
||||
}
|
||||
})
|
||||
.small()
|
||||
.ghost()
|
||||
.on_click(cx.listener(Self::change_theme_mode)),
|
||||
),
|
||||
.when_some(self.account.read(cx).as_ref(), |this, account| {
|
||||
this.child(account.clone())
|
||||
}),
|
||||
),
|
||||
)
|
||||
.child(self.dock.clone())
|
||||
@@ -213,8 +175,6 @@ impl Render for AppView {
|
||||
}
|
||||
|
||||
div()
|
||||
.bg(cx.theme().background)
|
||||
.text_color(cx.theme().foreground)
|
||||
.size_full()
|
||||
.child(content)
|
||||
.child(div().absolute().top_8().children(notification_layer))
|
||||
|
||||
72
crates/app/src/views/dock/contact.rs
Normal file
72
crates/app/src/views/dock/contact.rs
Normal file
@@ -0,0 +1,72 @@
|
||||
use coop_ui::{
|
||||
button::Button,
|
||||
dock::{Panel, PanelEvent, PanelState},
|
||||
popup_menu::PopupMenu,
|
||||
};
|
||||
use gpui::*;
|
||||
|
||||
pub struct ContactPanel {
|
||||
name: SharedString,
|
||||
closeable: bool,
|
||||
zoomable: bool,
|
||||
focus_handle: FocusHandle,
|
||||
}
|
||||
|
||||
impl ContactPanel {
|
||||
pub fn new(cx: &mut WindowContext) -> View<Self> {
|
||||
cx.new_view(Self::view)
|
||||
}
|
||||
|
||||
fn view(cx: &mut ViewContext<Self>) -> Self {
|
||||
Self {
|
||||
name: "Contacts".into(),
|
||||
closeable: true,
|
||||
zoomable: true,
|
||||
focus_handle: cx.focus_handle(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Panel for ContactPanel {
|
||||
fn panel_id(&self) -> SharedString {
|
||||
"Contact".into()
|
||||
}
|
||||
|
||||
fn title(&self, _cx: &WindowContext) -> AnyElement {
|
||||
self.name.clone().into_any_element()
|
||||
}
|
||||
|
||||
fn closeable(&self, _cx: &WindowContext) -> bool {
|
||||
self.closeable
|
||||
}
|
||||
|
||||
fn zoomable(&self, _cx: &WindowContext) -> bool {
|
||||
self.zoomable
|
||||
}
|
||||
|
||||
fn popup_menu(&self, menu: PopupMenu, _cx: &WindowContext) -> PopupMenu {
|
||||
menu.track_focus(&self.focus_handle)
|
||||
}
|
||||
|
||||
fn toolbar_buttons(&self, _cx: &WindowContext) -> Vec<Button> {
|
||||
vec![]
|
||||
}
|
||||
|
||||
fn dump(&self, _cx: &AppContext) -> PanelState {
|
||||
PanelState::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl EventEmitter<PanelEvent> for ContactPanel {}
|
||||
|
||||
impl FocusableView for ContactPanel {
|
||||
fn focus_handle(&self, _: &AppContext) -> gpui::FocusHandle {
|
||||
self.focus_handle.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for ContactPanel {
|
||||
fn render(&mut self, _cx: &mut gpui::ViewContext<Self>) -> impl IntoElement {
|
||||
div().size_full().child("TODO")
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ use crate::{
|
||||
get_client,
|
||||
states::{chat::Room, metadata::MetadataRegistry, signal::SignalRegistry},
|
||||
utils::{ago, get_room_id, show_npub},
|
||||
views::app::AddPanel,
|
||||
views::app::{AddPanel, PanelKind},
|
||||
};
|
||||
|
||||
pub struct InboxItem {
|
||||
@@ -73,7 +73,7 @@ impl InboxItem {
|
||||
let room = Arc::new(Room::new(&self.event, cx));
|
||||
|
||||
cx.dispatch_action(Box::new(AddPanel {
|
||||
room,
|
||||
panel: PanelKind::Room(room),
|
||||
position: coop_ui::dock::DockPlacement::Center,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -189,9 +189,8 @@ impl Render for Inbox {
|
||||
}
|
||||
|
||||
v_flex()
|
||||
.gap_1()
|
||||
.pt_2()
|
||||
.px_2()
|
||||
.gap_1()
|
||||
.child(
|
||||
div()
|
||||
.id("inbox")
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
use coop_ui::{
|
||||
button::Button,
|
||||
button::{Button, ButtonVariants},
|
||||
dock::{Panel, PanelEvent, PanelState},
|
||||
popup_menu::PopupMenu,
|
||||
scroll::ScrollbarAxis,
|
||||
StyledExt,
|
||||
v_flex, ContextModal, Icon, IconName, Sizable, StyledExt,
|
||||
};
|
||||
use gpui::*;
|
||||
|
||||
use crate::views::app::{AddPanel, PanelKind};
|
||||
|
||||
use super::inbox::Inbox;
|
||||
|
||||
pub struct LeftDock {
|
||||
@@ -79,8 +81,54 @@ impl FocusableView for LeftDock {
|
||||
|
||||
impl Render for LeftDock {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
div()
|
||||
.child(self.inbox.clone())
|
||||
v_flex()
|
||||
.scrollable(self.view_id, ScrollbarAxis::Vertical)
|
||||
.pt_3()
|
||||
.gap_3()
|
||||
.child(
|
||||
v_flex()
|
||||
.px_2()
|
||||
.gap_1()
|
||||
.child(
|
||||
Button::new("new")
|
||||
.small()
|
||||
.ghost()
|
||||
.not_centered()
|
||||
.bold()
|
||||
.icon(Icon::new(IconName::Plus))
|
||||
.label("Compose")
|
||||
.on_click(|_, cx| {
|
||||
cx.open_modal(move |modal, _| modal.title("Compose").child("TODO"));
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
Button::new("contacts")
|
||||
.small()
|
||||
.ghost()
|
||||
.not_centered()
|
||||
.bold()
|
||||
.icon(Icon::new(IconName::Group))
|
||||
.label("Contacts")
|
||||
.on_click(|_, cx| {
|
||||
cx.dispatch_action(Box::new(AddPanel {
|
||||
panel: PanelKind::Contact,
|
||||
position: coop_ui::dock::DockPlacement::Center,
|
||||
}))
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
Button::new("find")
|
||||
.small()
|
||||
.ghost()
|
||||
.not_centered()
|
||||
.bold()
|
||||
.icon(Icon::new(IconName::Search))
|
||||
.label("Find")
|
||||
.on_click(|_, cx| {
|
||||
cx.open_modal(move |modal, _| modal.title("Find").child("TODO"));
|
||||
}),
|
||||
),
|
||||
)
|
||||
.child(self.inbox.clone())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
pub mod chat;
|
||||
pub mod contact;
|
||||
pub mod inbox;
|
||||
pub mod left_dock;
|
||||
pub mod welcome;
|
||||
|
||||
Reference in New Issue
Block a user