wip: refactor
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
use coop_ui::block::Block;
|
||||
use gpui::*;
|
||||
|
||||
pub struct ChatBlock {
|
||||
focus_handle: FocusHandle,
|
||||
}
|
||||
|
||||
impl ChatBlock {
|
||||
pub fn view(cx: &mut WindowContext) -> View<Self> {
|
||||
cx.new_view(Self::new)
|
||||
}
|
||||
|
||||
fn new(cx: &mut ViewContext<Self>) -> Self {
|
||||
Self {
|
||||
focus_handle: cx.focus_handle(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Block for ChatBlock {
|
||||
fn title() -> &'static str {
|
||||
"Chat"
|
||||
}
|
||||
|
||||
fn new_view(cx: &mut WindowContext) -> View<impl FocusableView> {
|
||||
Self::view(cx)
|
||||
}
|
||||
|
||||
fn zoomable() -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
impl FocusableView for ChatBlock {
|
||||
fn focus_handle(&self, _: &gpui::AppContext) -> gpui::FocusHandle {
|
||||
self.focus_handle.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for ChatBlock {
|
||||
fn render(&mut self, _cx: &mut gpui::ViewContext<Self>) -> impl IntoElement {
|
||||
div()
|
||||
.size_full()
|
||||
.flex()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.child("Test")
|
||||
}
|
||||
}
|
||||
87
crates/app/src/views/dock/chat/mod.rs
Normal file
87
crates/app/src/views/dock/chat/mod.rs
Normal file
@@ -0,0 +1,87 @@
|
||||
use components::{
|
||||
button::Button,
|
||||
dock::{DockItemState, Panel, PanelEvent, TitleStyle},
|
||||
popup_menu::PopupMenu,
|
||||
theme::{ActiveTheme, Colorize},
|
||||
StyledExt,
|
||||
};
|
||||
use gpui::*;
|
||||
use nostr_sdk::*;
|
||||
|
||||
pub struct ChatPanel {
|
||||
// Panel
|
||||
name: SharedString,
|
||||
closeable: bool,
|
||||
zoomable: bool,
|
||||
focus_handle: FocusHandle,
|
||||
// Chat Room
|
||||
receiver: PublicKey,
|
||||
}
|
||||
|
||||
impl ChatPanel {
|
||||
pub fn new(receiver: PublicKey, cx: &mut WindowContext) -> View<Self> {
|
||||
cx.new_view(|cx| Self {
|
||||
name: "Chat".into(),
|
||||
closeable: true,
|
||||
zoomable: true,
|
||||
focus_handle: cx.focus_handle(),
|
||||
receiver,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Panel for ChatPanel {
|
||||
fn panel_name(&self) -> &'static str {
|
||||
"ChatPanel"
|
||||
}
|
||||
|
||||
fn title(&self, _cx: &WindowContext) -> AnyElement {
|
||||
self.name.clone().into_any_element()
|
||||
}
|
||||
|
||||
fn title_style(&self, _cx: &WindowContext) -> Option<TitleStyle> {
|
||||
None
|
||||
}
|
||||
|
||||
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) -> DockItemState {
|
||||
DockItemState::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl EventEmitter<PanelEvent> for ChatPanel {}
|
||||
|
||||
impl FocusableView for ChatPanel {
|
||||
fn focus_handle(&self, _: &AppContext) -> gpui::FocusHandle {
|
||||
self.focus_handle.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for ChatPanel {
|
||||
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> impl IntoElement {
|
||||
div()
|
||||
.size_full()
|
||||
.flex()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.child(self.receiver.to_hex())
|
||||
.text_color(cx.theme().muted.darken(0.1))
|
||||
.font_black()
|
||||
.text_sm()
|
||||
}
|
||||
}
|
||||
@@ -1,47 +1,82 @@
|
||||
use components::{scroll::ScrollbarAxis, StyledExt};
|
||||
use coop_ui::block::Block;
|
||||
use components::{
|
||||
button::Button,
|
||||
dock::{DockItemState, Panel, PanelEvent, TitleStyle},
|
||||
popup_menu::PopupMenu,
|
||||
scroll::ScrollbarAxis,
|
||||
StyledExt,
|
||||
};
|
||||
use gpui::*;
|
||||
|
||||
use super::inbox::Inbox;
|
||||
|
||||
pub struct LeftDock {
|
||||
inbox: View<Inbox>,
|
||||
// Panel
|
||||
name: SharedString,
|
||||
closeable: bool,
|
||||
zoomable: bool,
|
||||
focus_handle: FocusHandle,
|
||||
// Dock
|
||||
inbox: View<Inbox>,
|
||||
view_id: EntityId,
|
||||
}
|
||||
|
||||
impl LeftDock {
|
||||
pub fn view(cx: &mut WindowContext) -> View<Self> {
|
||||
cx.new_view(Self::new)
|
||||
pub fn new(cx: &mut WindowContext) -> View<Self> {
|
||||
cx.new_view(Self::view)
|
||||
}
|
||||
|
||||
fn new(cx: &mut ViewContext<Self>) -> Self {
|
||||
fn view(cx: &mut ViewContext<Self>) -> Self {
|
||||
let inbox = cx.new_view(Inbox::new);
|
||||
|
||||
Self {
|
||||
inbox,
|
||||
name: "Left Dock".into(),
|
||||
closeable: true,
|
||||
zoomable: true,
|
||||
focus_handle: cx.focus_handle(),
|
||||
view_id: cx.view().entity_id(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Block for LeftDock {
|
||||
fn title() -> &'static str {
|
||||
"Left Dock"
|
||||
impl Panel for LeftDock {
|
||||
fn panel_name(&self) -> &'static str {
|
||||
"ChatPanel"
|
||||
}
|
||||
|
||||
fn new_view(cx: &mut WindowContext) -> View<impl FocusableView> {
|
||||
Self::view(cx)
|
||||
fn title(&self, _cx: &WindowContext) -> AnyElement {
|
||||
self.name.clone().into_any_element()
|
||||
}
|
||||
|
||||
fn zoomable() -> bool {
|
||||
false
|
||||
fn title_style(&self, _cx: &WindowContext) -> Option<TitleStyle> {
|
||||
None
|
||||
}
|
||||
|
||||
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) -> DockItemState {
|
||||
DockItemState::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl EventEmitter<PanelEvent> for LeftDock {}
|
||||
|
||||
impl FocusableView for LeftDock {
|
||||
fn focus_handle(&self, _: &gpui::AppContext) -> gpui::FocusHandle {
|
||||
fn focus_handle(&self, _: &AppContext) -> gpui::FocusHandle {
|
||||
self.focus_handle.clone()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,47 +1,77 @@
|
||||
use components::{
|
||||
button::Button,
|
||||
dock::{DockItemState, Panel, PanelEvent, TitleStyle},
|
||||
popup_menu::PopupMenu,
|
||||
theme::{ActiveTheme, Colorize},
|
||||
StyledExt,
|
||||
};
|
||||
use coop_ui::block::Block;
|
||||
use gpui::*;
|
||||
|
||||
pub struct WelcomeBlock {
|
||||
pub struct WelcomePanel {
|
||||
name: SharedString,
|
||||
closeable: bool,
|
||||
zoomable: bool,
|
||||
focus_handle: FocusHandle,
|
||||
}
|
||||
|
||||
impl WelcomeBlock {
|
||||
pub fn view(cx: &mut WindowContext) -> View<Self> {
|
||||
cx.new_view(Self::new)
|
||||
impl WelcomePanel {
|
||||
pub fn new(cx: &mut WindowContext) -> View<Self> {
|
||||
cx.new_view(Self::view)
|
||||
}
|
||||
|
||||
fn new(cx: &mut ViewContext<Self>) -> Self {
|
||||
fn view(cx: &mut ViewContext<Self>) -> Self {
|
||||
Self {
|
||||
name: "Welcome".into(),
|
||||
closeable: true,
|
||||
zoomable: true,
|
||||
focus_handle: cx.focus_handle(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Block for WelcomeBlock {
|
||||
fn title() -> &'static str {
|
||||
"Welcome"
|
||||
impl Panel for WelcomePanel {
|
||||
fn panel_name(&self) -> &'static str {
|
||||
"WelcomePanel"
|
||||
}
|
||||
|
||||
fn new_view(cx: &mut WindowContext) -> View<impl FocusableView> {
|
||||
Self::view(cx)
|
||||
fn title(&self, _cx: &WindowContext) -> AnyElement {
|
||||
self.name.clone().into_any_element()
|
||||
}
|
||||
|
||||
fn zoomable() -> bool {
|
||||
false
|
||||
fn title_style(&self, _cx: &WindowContext) -> Option<TitleStyle> {
|
||||
None
|
||||
}
|
||||
|
||||
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) -> DockItemState {
|
||||
DockItemState::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl FocusableView for WelcomeBlock {
|
||||
fn focus_handle(&self, _: &gpui::AppContext) -> gpui::FocusHandle {
|
||||
impl EventEmitter<PanelEvent> for WelcomePanel {}
|
||||
|
||||
impl FocusableView for WelcomePanel {
|
||||
fn focus_handle(&self, _: &AppContext) -> gpui::FocusHandle {
|
||||
self.focus_handle.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for WelcomeBlock {
|
||||
impl Render for WelcomePanel {
|
||||
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> impl IntoElement {
|
||||
div()
|
||||
.size_full()
|
||||
|
||||
Reference in New Issue
Block a user