Redesign for the v1 stable release #3
@@ -12,12 +12,12 @@ use ui::Root;
|
|||||||
use crate::actions::Quit;
|
use crate::actions::Quit;
|
||||||
|
|
||||||
mod actions;
|
mod actions;
|
||||||
mod chatspace;
|
|
||||||
mod login;
|
mod login;
|
||||||
mod new_identity;
|
mod new_identity;
|
||||||
mod sidebar;
|
mod sidebar;
|
||||||
mod user;
|
mod user;
|
||||||
mod views;
|
mod views;
|
||||||
|
mod workspace;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Initialize logging
|
// Initialize logging
|
||||||
@@ -111,7 +111,7 @@ fn main() {
|
|||||||
auto_update::init(cx);
|
auto_update::init(cx);
|
||||||
|
|
||||||
// Root Entity
|
// Root Entity
|
||||||
Root::new(chatspace::init(window, cx).into(), window, cx)
|
Root::new(workspace::init(window, cx).into(), window, cx)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.expect("Failed to open window. Please restart the application.");
|
.expect("Failed to open window. Please restart the application.");
|
||||||
|
|||||||
@@ -31,30 +31,30 @@ use crate::actions::{
|
|||||||
use crate::user::viewer;
|
use crate::user::viewer;
|
||||||
use crate::views::compose::compose_button;
|
use crate::views::compose::compose_button;
|
||||||
use crate::views::{preferences, setup_relay, welcome};
|
use crate::views::{preferences, setup_relay, welcome};
|
||||||
use crate::{login, sidebar, user};
|
use crate::{sidebar, user};
|
||||||
|
|
||||||
pub fn init(window: &mut Window, cx: &mut App) -> Entity<ChatSpace> {
|
pub fn init(window: &mut Window, cx: &mut App) -> Entity<Workspace> {
|
||||||
cx.new(|cx| ChatSpace::new(window, cx))
|
cx.new(|cx| Workspace::new(window, cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ChatSpace {
|
pub struct Workspace {
|
||||||
/// App's Title Bar
|
/// App's Title Bar
|
||||||
title_bar: Entity<TitleBar>,
|
title_bar: Entity<TitleBar>,
|
||||||
|
|
||||||
/// App's Dock Area
|
/// App's Dock Area
|
||||||
dock: Entity<DockArea>,
|
dock: Entity<DockArea>,
|
||||||
|
|
||||||
/// Determines if the chat space is ready to use
|
|
||||||
ready: bool,
|
|
||||||
|
|
||||||
/// Event subscriptions
|
/// Event subscriptions
|
||||||
_subscriptions: SmallVec<[Subscription; 3]>,
|
_subscriptions: SmallVec<[Subscription; 4]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChatSpace {
|
impl Workspace {
|
||||||
fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
let chat = ChatRegistry::global(cx);
|
let chat = ChatRegistry::global(cx);
|
||||||
|
let nostr = NostrRegistry::global(cx);
|
||||||
|
let identity = nostr.read(cx).identity();
|
||||||
|
|
||||||
let title_bar = cx.new(|_| TitleBar::new());
|
let title_bar = cx.new(|_| TitleBar::new());
|
||||||
let dock = cx.new(|cx| DockArea::new(window, cx));
|
let dock = cx.new(|cx| DockArea::new(window, cx));
|
||||||
|
|
||||||
@@ -67,6 +67,17 @@ impl ChatSpace {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
subscriptions.push(
|
||||||
|
// Observe the identity entity
|
||||||
|
cx.observe_in(&identity, window, move |this, state, window, cx| {
|
||||||
|
if state.read(cx).has_public_key() {
|
||||||
|
this.dock.update(cx, |this, cx| {
|
||||||
|
this.toggle_dock(DockPlacement::Left, window, cx);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
subscriptions.push(
|
subscriptions.push(
|
||||||
// Observe all events emitted by the chat registry
|
// Observe all events emitted by the chat registry
|
||||||
cx.subscribe_in(&chat, window, move |this, chat, ev, window, cx| {
|
cx.subscribe_in(&chat, window, move |this, chat, ev, window, cx| {
|
||||||
@@ -87,6 +98,7 @@ impl ChatSpace {
|
|||||||
this.dock.update(cx, |this, cx| {
|
this.dock.update(cx, |this, cx| {
|
||||||
// Force focus to the tab panel
|
// Force focus to the tab panel
|
||||||
this.focus_tab_panel(window, cx);
|
this.focus_tab_panel(window, cx);
|
||||||
|
|
||||||
// Dispatch the close panel action
|
// Dispatch the close panel action
|
||||||
cx.defer_in(window, |_, window, cx| {
|
cx.defer_in(window, |_, window, cx| {
|
||||||
window.dispatch_action(Box::new(ClosePanel), cx);
|
window.dispatch_action(Box::new(ClosePanel), cx);
|
||||||
@@ -118,7 +130,6 @@ impl ChatSpace {
|
|||||||
Self {
|
Self {
|
||||||
dock,
|
dock,
|
||||||
title_bar,
|
title_bar,
|
||||||
ready: false,
|
|
||||||
_subscriptions: subscriptions,
|
_subscriptions: subscriptions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,7 +158,7 @@ impl ChatSpace {
|
|||||||
|
|
||||||
// Update the dock layout
|
// Update the dock layout
|
||||||
self.dock.update(cx, |this, cx| {
|
self.dock.update(cx, |this, cx| {
|
||||||
this.set_left_dock(left, Some(px(DEFAULT_SIDEBAR_WIDTH)), true, window, cx);
|
this.set_left_dock(left, Some(px(DEFAULT_SIDEBAR_WIDTH)), false, window, cx);
|
||||||
this.set_center(center, window, cx);
|
this.set_center(center, window, cx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -483,7 +494,7 @@ impl ChatSpace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Render for ChatSpace {
|
impl Render for Workspace {
|
||||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
let modal_layer = Root::render_modal_layer(window, cx);
|
let modal_layer = Root::render_modal_layer(window, cx);
|
||||||
let notification_layer = Root::render_notification_layer(window, cx);
|
let notification_layer = Root::render_notification_layer(window, cx);
|
||||||
@@ -496,7 +507,7 @@ impl Render for ChatSpace {
|
|||||||
});
|
});
|
||||||
|
|
||||||
div()
|
div()
|
||||||
.id(SharedString::from("chatspace"))
|
.id(SharedString::from("workspace"))
|
||||||
.on_action(cx.listener(Self::on_settings))
|
.on_action(cx.listener(Self::on_settings))
|
||||||
.on_action(cx.listener(Self::on_profile))
|
.on_action(cx.listener(Self::on_profile))
|
||||||
.on_action(cx.listener(Self::on_relays))
|
.on_action(cx.listener(Self::on_relays))
|
||||||
Reference in New Issue
Block a user