wip: refactor
This commit is contained in:
@@ -9,9 +9,8 @@ use serde::Deserialize;
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::{
|
||||
account::Account,
|
||||
dock::{chat::ChatPanel, contact::ContactPanel, left_dock::LeftDock, welcome::WelcomePanel},
|
||||
onboarding::Onboarding,
|
||||
account::Account, chat::ChatPanel, contact::ContactPanel, onboarding::Onboarding,
|
||||
sidebar::Sidebar, welcome::WelcomePanel,
|
||||
};
|
||||
use crate::states::{account::AccountRegistry, chat::Room};
|
||||
|
||||
@@ -86,12 +85,12 @@ impl AppView {
|
||||
}
|
||||
|
||||
fn init_layout(dock_area: WeakView<DockArea>, cx: &mut WindowContext) {
|
||||
let left = DockItem::panel(Arc::new(LeftDock::new(cx)));
|
||||
let left = DockItem::panel(Arc::new(Sidebar::new(cx)));
|
||||
let center = Self::init_dock_items(&dock_area, cx);
|
||||
|
||||
_ = dock_area.update(cx, |view, cx| {
|
||||
view.set_version(DOCK_AREA.version, cx);
|
||||
view.set_left_dock(left, Some(px(260.)), true, cx);
|
||||
view.set_left_dock(left, Some(px(240.)), true, cx);
|
||||
view.set_center(center, cx);
|
||||
view.set_dock_collapsible(
|
||||
Edges {
|
||||
|
||||
@@ -45,6 +45,13 @@ impl RenderOnce for RoomMessage {
|
||||
.gap_3()
|
||||
.w_full()
|
||||
.p_2()
|
||||
.border_l_2()
|
||||
.border_color(cx.theme().background)
|
||||
.hover(|this| {
|
||||
this.bg(cx.theme().muted)
|
||||
.border_color(cx.theme().primary_active)
|
||||
.text_color(cx.theme().muted_foreground)
|
||||
})
|
||||
.child(div().flex_shrink_0().map(|this| {
|
||||
if let Some(metadata) = self.metadata.clone() {
|
||||
if let Some(picture) = metadata.picture {
|
||||
49
crates/app/src/views/contact/list.rs
Normal file
49
crates/app/src/views/contact/list.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use gpui::*;
|
||||
use nostr_sdk::prelude::*;
|
||||
use prelude::FluentBuilder;
|
||||
|
||||
use crate::get_client;
|
||||
|
||||
pub struct ContactList {
|
||||
contacts: Model<Option<Vec<Contact>>>,
|
||||
}
|
||||
|
||||
impl ContactList {
|
||||
pub fn new(cx: &mut ViewContext<'_, Self>) -> Self {
|
||||
let contacts = cx.new_model(|_| None);
|
||||
let async_contacts = contacts.clone();
|
||||
|
||||
let mut async_cx = cx.to_async();
|
||||
|
||||
cx.foreground_executor()
|
||||
.spawn({
|
||||
let client = get_client();
|
||||
|
||||
async move {
|
||||
if let Ok(contacts) = async_cx
|
||||
.background_executor()
|
||||
.spawn(async move { client.get_contact_list(Duration::from_secs(3)).await })
|
||||
.await
|
||||
{
|
||||
_ = async_cx.update_model(&async_contacts, |model, cx| {
|
||||
*model = Some(contacts);
|
||||
cx.notify();
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
||||
Self { contacts }
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for ContactList {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
div().when_some(self.contacts.read(cx).as_ref(), |this, contacts| {
|
||||
this.child("Total").child(contacts.len().to_string())
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,17 @@ use coop_ui::{
|
||||
popup_menu::PopupMenu,
|
||||
};
|
||||
use gpui::*;
|
||||
use list::ContactList;
|
||||
|
||||
mod list;
|
||||
|
||||
pub struct ContactPanel {
|
||||
name: SharedString,
|
||||
closeable: bool,
|
||||
zoomable: bool,
|
||||
focus_handle: FocusHandle,
|
||||
// Contacts
|
||||
list: View<ContactList>,
|
||||
}
|
||||
|
||||
impl ContactPanel {
|
||||
@@ -18,11 +23,14 @@ impl ContactPanel {
|
||||
}
|
||||
|
||||
fn view(cx: &mut ViewContext<Self>) -> Self {
|
||||
let list = cx.new_view(ContactList::new);
|
||||
|
||||
Self {
|
||||
name: "Contacts".into(),
|
||||
closeable: true,
|
||||
zoomable: true,
|
||||
focus_handle: cx.focus_handle(),
|
||||
list,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,6 +75,6 @@ impl FocusableView for ContactPanel {
|
||||
|
||||
impl Render for ContactPanel {
|
||||
fn render(&mut self, _cx: &mut gpui::ViewContext<Self>) -> impl IntoElement {
|
||||
div().size_full().child("TODO")
|
||||
div().size_full().child(self.list.clone())
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
pub mod chat;
|
||||
pub mod contact;
|
||||
pub mod inbox;
|
||||
pub mod left_dock;
|
||||
pub mod welcome;
|
||||
@@ -1,4 +1,9 @@
|
||||
pub mod account;
|
||||
pub mod app;
|
||||
pub mod dock;
|
||||
pub mod onboarding;
|
||||
|
||||
mod account;
|
||||
mod chat;
|
||||
mod contact;
|
||||
mod inbox;
|
||||
mod onboarding;
|
||||
mod sidebar;
|
||||
mod welcome;
|
||||
|
||||
@@ -7,11 +7,10 @@ use coop_ui::{
|
||||
};
|
||||
use gpui::*;
|
||||
|
||||
use super::inbox::Inbox;
|
||||
use crate::views::app::{AddPanel, PanelKind};
|
||||
|
||||
use super::inbox::Inbox;
|
||||
|
||||
pub struct LeftDock {
|
||||
pub struct Sidebar {
|
||||
// Panel
|
||||
name: SharedString,
|
||||
closeable: bool,
|
||||
@@ -22,7 +21,7 @@ pub struct LeftDock {
|
||||
view_id: EntityId,
|
||||
}
|
||||
|
||||
impl LeftDock {
|
||||
impl Sidebar {
|
||||
pub fn new(cx: &mut WindowContext) -> View<Self> {
|
||||
cx.new_view(Self::view)
|
||||
}
|
||||
@@ -41,9 +40,9 @@ impl LeftDock {
|
||||
}
|
||||
}
|
||||
|
||||
impl Panel for LeftDock {
|
||||
impl Panel for Sidebar {
|
||||
fn panel_id(&self) -> SharedString {
|
||||
"LeftDock".into()
|
||||
"Sidebar".into()
|
||||
}
|
||||
|
||||
fn title(&self, _cx: &WindowContext) -> AnyElement {
|
||||
@@ -71,15 +70,15 @@ impl Panel for LeftDock {
|
||||
}
|
||||
}
|
||||
|
||||
impl EventEmitter<PanelEvent> for LeftDock {}
|
||||
impl EventEmitter<PanelEvent> for Sidebar {}
|
||||
|
||||
impl FocusableView for LeftDock {
|
||||
impl FocusableView for Sidebar {
|
||||
fn focus_handle(&self, _: &AppContext) -> gpui::FocusHandle {
|
||||
self.focus_handle.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for LeftDock {
|
||||
impl Render for Sidebar {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
v_flex()
|
||||
.scrollable(self.view_id, ScrollbarAxis::Vertical)
|
||||
@@ -96,9 +95,9 @@ impl Render for LeftDock {
|
||||
.not_centered()
|
||||
.bold()
|
||||
.icon(Icon::new(IconName::Plus))
|
||||
.label("Compose")
|
||||
.label("New")
|
||||
.on_click(|_, cx| {
|
||||
cx.open_modal(move |modal, _| modal.title("Compose").child("TODO"));
|
||||
cx.open_modal(move |modal, _| modal.child("TODO"));
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
@@ -115,18 +114,6 @@ impl Render for LeftDock {
|
||||
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())
|
||||
@@ -458,8 +458,8 @@ impl RenderOnce for Button {
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.map(|this| match self.size {
|
||||
Size::XSmall => this.gap_1().text_xs(),
|
||||
Size::Small => this.gap_2().text_xs(),
|
||||
Size::XSmall => this.gap_0p5().text_xs(),
|
||||
Size::Small => this.gap_1().text_xs(),
|
||||
_ => this.gap_2().text_base(),
|
||||
})
|
||||
.when(!self.loading, |this| {
|
||||
|
||||
Reference in New Issue
Block a user