wip: refactor
This commit is contained in:
112
Cargo.lock
generated
112
Cargo.lock
generated
@@ -158,7 +158,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_repr",
|
||||
"url",
|
||||
"zbus 5.1.1",
|
||||
"zbus 5.2.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -748,9 +748,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bstr"
|
||||
version = "1.11.0"
|
||||
version = "1.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a68f1f47cdf0ec8ee4b941b2eee2a80cb796db73118c0dd09ac63fbe405be22"
|
||||
checksum = "786a307d683a5bf92e6fd5fd69a7eb613751668d1d8d67d802846dfe367c62c8"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"serde",
|
||||
@@ -861,9 +861,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.3"
|
||||
version = "1.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "27f657647bcff5394bf56c7317665bbf790a137a50eaaa5c6bfbb9e27a518f2d"
|
||||
checksum = "9157bbaa6b165880c27a4293a474c91cdcf265cc68cc829bf10be0964a391caf"
|
||||
dependencies = [
|
||||
"jobserver",
|
||||
"libc",
|
||||
@@ -1040,7 +1040,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "collections"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/zed-industries/zed#8a85d6ef96cc9d38e1c0e7e420765cd4b31b6954"
|
||||
source = "git+https://github.com/zed-industries/zed#af50261ae240a2c44bc742f434be46032e47256e"
|
||||
dependencies = [
|
||||
"rustc-hash 1.1.0",
|
||||
]
|
||||
@@ -1268,9 +1268,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-deque"
|
||||
version = "0.8.5"
|
||||
version = "0.8.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d"
|
||||
checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51"
|
||||
dependencies = [
|
||||
"crossbeam-epoch",
|
||||
"crossbeam-utils",
|
||||
@@ -1287,18 +1287,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-queue"
|
||||
version = "0.3.11"
|
||||
version = "0.3.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35"
|
||||
checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115"
|
||||
dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.20"
|
||||
version = "0.8.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80"
|
||||
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
|
||||
|
||||
[[package]]
|
||||
name = "crunchy"
|
||||
@@ -1379,7 +1379,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "derive_refineable"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/zed-industries/zed#8a85d6ef96cc9d38e1c0e7e420765cd4b31b6954"
|
||||
source = "git+https://github.com/zed-industries/zed#af50261ae240a2c44bc742f434be46032e47256e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -2104,7 +2104,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "gpui"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/zed-industries/zed#8a85d6ef96cc9d38e1c0e7e420765cd4b31b6954"
|
||||
source = "git+https://github.com/zed-industries/zed#af50261ae240a2c44bc742f434be46032e47256e"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"as-raw-xcb-connection",
|
||||
@@ -2189,7 +2189,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "gpui_macros"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/zed-industries/zed#8a85d6ef96cc9d38e1c0e7e420765cd4b31b6954"
|
||||
source = "git+https://github.com/zed-industries/zed#af50261ae240a2c44bc742f434be46032e47256e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -2400,7 +2400,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "http_client"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/zed-industries/zed#8a85d6ef96cc9d38e1c0e7e420765cd4b31b6954"
|
||||
source = "git+https://github.com/zed-industries/zed#af50261ae240a2c44bc742f434be46032e47256e"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytes",
|
||||
@@ -3065,7 +3065,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "media"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/zed-industries/zed#8a85d6ef96cc9d38e1c0e7e420765cd4b31b6954"
|
||||
source = "git+https://github.com/zed-industries/zed#af50261ae240a2c44bc742f434be46032e47256e"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bindgen",
|
||||
@@ -3234,7 +3234,7 @@ checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8"
|
||||
[[package]]
|
||||
name = "nostr"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/rust-nostr/nostr#0d12a1d44eaa223d065d4136179296124d955765"
|
||||
source = "git+https://github.com/rust-nostr/nostr#c616b2f598ef65e8d7e2b6b0959aa28e9c5d9d41"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"async-trait",
|
||||
@@ -3265,7 +3265,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "nostr-database"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/rust-nostr/nostr#0d12a1d44eaa223d065d4136179296124d955765"
|
||||
source = "git+https://github.com/rust-nostr/nostr#c616b2f598ef65e8d7e2b6b0959aa28e9c5d9d41"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"flatbuffers",
|
||||
@@ -3276,7 +3276,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "nostr-lmdb"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/rust-nostr/nostr#0d12a1d44eaa223d065d4136179296124d955765"
|
||||
source = "git+https://github.com/rust-nostr/nostr#c616b2f598ef65e8d7e2b6b0959aa28e9c5d9d41"
|
||||
dependencies = [
|
||||
"async-utility",
|
||||
"heed",
|
||||
@@ -3288,7 +3288,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "nostr-relay-pool"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/rust-nostr/nostr#0d12a1d44eaa223d065d4136179296124d955765"
|
||||
source = "git+https://github.com/rust-nostr/nostr#c616b2f598ef65e8d7e2b6b0959aa28e9c5d9d41"
|
||||
dependencies = [
|
||||
"async-utility",
|
||||
"async-wsocket",
|
||||
@@ -3304,7 +3304,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "nostr-sdk"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/rust-nostr/nostr#0d12a1d44eaa223d065d4136179296124d955765"
|
||||
source = "git+https://github.com/rust-nostr/nostr#c616b2f598ef65e8d7e2b6b0959aa28e9c5d9d41"
|
||||
dependencies = [
|
||||
"async-utility",
|
||||
"lnurl-pay",
|
||||
@@ -3321,7 +3321,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "nostr-zapper"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/rust-nostr/nostr#0d12a1d44eaa223d065d4136179296124d955765"
|
||||
source = "git+https://github.com/rust-nostr/nostr#c616b2f598ef65e8d7e2b6b0959aa28e9c5d9d41"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"nostr",
|
||||
@@ -3916,7 +3916,7 @@ dependencies = [
|
||||
"rustc-hash 2.1.0",
|
||||
"rustls",
|
||||
"socket2 0.5.8",
|
||||
"thiserror 2.0.6",
|
||||
"thiserror 2.0.7",
|
||||
"tokio",
|
||||
"tracing",
|
||||
]
|
||||
@@ -3935,7 +3935,7 @@ dependencies = [
|
||||
"rustls",
|
||||
"rustls-pki-types",
|
||||
"slab",
|
||||
"thiserror 2.0.6",
|
||||
"thiserror 2.0.7",
|
||||
"tinyvec",
|
||||
"tracing",
|
||||
"web-time",
|
||||
@@ -4090,9 +4090,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "read-fonts"
|
||||
version = "0.22.5"
|
||||
version = "0.22.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a04b892cb6f91951f144c33321843790c8574c825aafdb16d815fd7183b5229"
|
||||
checksum = "69aacb76b5c29acfb7f90155d39759a29496aebb49395830e928a9703d2eec2f"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"font-types",
|
||||
@@ -4100,9 +4100,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.5.7"
|
||||
version = "0.5.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f"
|
||||
checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
]
|
||||
@@ -4121,7 +4121,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "refineable"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/zed-industries/zed#8a85d6ef96cc9d38e1c0e7e420765cd4b31b6954"
|
||||
source = "git+https://github.com/zed-industries/zed#af50261ae240a2c44bc742f434be46032e47256e"
|
||||
dependencies = [
|
||||
"derive_refineable",
|
||||
]
|
||||
@@ -4248,7 +4248,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "reqwest_client"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/zed-industries/zed#8a85d6ef96cc9d38e1c0e7e420765cd4b31b6954"
|
||||
source = "git+https://github.com/zed-industries/zed#af50261ae240a2c44bc742f434be46032e47256e"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytes",
|
||||
@@ -4396,9 +4396,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustls"
|
||||
version = "0.23.19"
|
||||
version = "0.23.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "934b404430bb06b3fae2cba809eb45a1ab1aecd64491213d7c3301b88393f8d1"
|
||||
checksum = "5065c3f250cbd332cd894be57c40fa52387247659b14a2d6041d121547903b1b"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"ring",
|
||||
@@ -4431,9 +4431,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustls-pki-types"
|
||||
version = "1.10.0"
|
||||
version = "1.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b"
|
||||
checksum = "d2bf47e6ff922db3825eb750c4e2ff784c6ff8fb9e13046ef6a1d1c5401b0b37"
|
||||
dependencies = [
|
||||
"web-time",
|
||||
]
|
||||
@@ -4662,7 +4662,7 @@ checksum = "c2fdfc24bc566f839a2da4c4295b82db7d25a24253867d5c64355abb5799bdbe"
|
||||
[[package]]
|
||||
name = "semantic_version"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/zed-industries/zed#8a85d6ef96cc9d38e1c0e7e420765cd4b31b6954"
|
||||
source = "git+https://github.com/zed-industries/zed#af50261ae240a2c44bc742f434be46032e47256e"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"serde",
|
||||
@@ -4670,24 +4670,24 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.23"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b"
|
||||
checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.215"
|
||||
version = "1.0.216"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f"
|
||||
checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.215"
|
||||
version = "1.0.216"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0"
|
||||
checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -4988,7 +4988,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
||||
[[package]]
|
||||
name = "sum_tree"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/zed-industries/zed#8a85d6ef96cc9d38e1c0e7e420765cd4b31b6954"
|
||||
source = "git+https://github.com/zed-industries/zed#af50261ae240a2c44bc742f434be46032e47256e"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"log",
|
||||
@@ -5263,11 +5263,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.6"
|
||||
version = "2.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fec2a1820ebd077e2b90c4df007bebf344cd394098a13c563957d0afc83ea47"
|
||||
checksum = "93605438cbd668185516ab499d589afb7ee1859ea3d5fc8f6b0755e1c7443767"
|
||||
dependencies = [
|
||||
"thiserror-impl 2.0.6",
|
||||
"thiserror-impl 2.0.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5283,9 +5283,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.6"
|
||||
version = "2.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d65750cab40f4ff1929fb1ba509e9914eb756131cef4210da8d5d700d26f6312"
|
||||
checksum = "e1d8749b4531af2117677a5fcd12b1348a3fe2b81e36e61ffeac5c4aa3273e36"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -5783,7 +5783,7 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
||||
[[package]]
|
||||
name = "util"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/zed-industries/zed#8a85d6ef96cc9d38e1c0e7e420765cd4b31b6954"
|
||||
source = "git+https://github.com/zed-industries/zed#af50261ae240a2c44bc742f434be46032e47256e"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-fs 1.6.0",
|
||||
@@ -6612,9 +6612,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zbus"
|
||||
version = "5.1.1"
|
||||
version = "5.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1162094dc63b1629fcc44150bcceeaa80798cd28bcbe7fa987b65a034c258608"
|
||||
checksum = "fb67eadba43784b6fb14857eba0d8fc518686d3ee537066eb6086dc318e2c8a1"
|
||||
dependencies = [
|
||||
"async-broadcast",
|
||||
"async-executor",
|
||||
@@ -6641,7 +6641,7 @@ dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
"winnow",
|
||||
"xdg-home",
|
||||
"zbus_macros 5.1.1",
|
||||
"zbus_macros 5.2.0",
|
||||
"zbus_names 4.1.0",
|
||||
"zvariant 5.1.0",
|
||||
]
|
||||
@@ -6661,9 +6661,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zbus_macros"
|
||||
version = "5.1.1"
|
||||
version = "5.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2cd2dcdce3e2727f7d74b7e33b5a89539b3cc31049562137faf7ae4eb86cd16d"
|
||||
checksum = "2c9d49ebc960ceb660f2abe40a5904da975de6986f2af0d7884b39eec6528c57"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
@@ -6804,9 +6804,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zune-jpeg"
|
||||
version = "0.4.13"
|
||||
version = "0.4.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "16099418600b4d8f028622f73ff6e3deaabdff330fb9a2a131dea781ee8b0768"
|
||||
checksum = "99a5bab8d7dedf81405c4bb1f2b83ea057643d9cb28778cea9eecddeedd2e028"
|
||||
dependencies = [
|
||||
"zune-core",
|
||||
]
|
||||
|
||||
@@ -17,7 +17,7 @@ use crate::states::account::AccountRegistry;
|
||||
#[derive(Clone, PartialEq, Eq, Deserialize)]
|
||||
pub struct AddPanel {
|
||||
pub title: Option<String>,
|
||||
pub receiver: PublicKey,
|
||||
pub from: PublicKey,
|
||||
}
|
||||
|
||||
impl_actions!(dock, [AddPanel]);
|
||||
@@ -98,7 +98,7 @@ impl AppView {
|
||||
}
|
||||
|
||||
fn on_action_add_panel(&mut self, action: &AddPanel, cx: &mut ViewContext<Self>) {
|
||||
let chat_panel = Arc::new(ChatPanel::new(action.receiver, cx));
|
||||
let chat_panel = Arc::new(ChatPanel::new(action.from, cx));
|
||||
|
||||
self.dock.update(cx, |dock_area, cx| {
|
||||
dock_area.add_panel(chat_panel, DockPlacement::Center, cx);
|
||||
|
||||
66
crates/app/src/views/dock/chat/messages.rs
Normal file
66
crates/app/src/views/dock/chat/messages.rs
Normal file
@@ -0,0 +1,66 @@
|
||||
use gpui::*;
|
||||
use nostr_sdk::prelude::*;
|
||||
|
||||
use crate::get_client;
|
||||
|
||||
pub struct Messages {
|
||||
messages: Model<Option<Events>>,
|
||||
}
|
||||
|
||||
impl Messages {
|
||||
pub fn new(from: PublicKey, cx: &mut ViewContext<'_, Self>) -> Self {
|
||||
let messages = cx.new_model(|_| None);
|
||||
let async_messages = messages.clone();
|
||||
|
||||
let mut async_cx = cx.to_async();
|
||||
|
||||
cx.foreground_executor()
|
||||
.spawn(async move {
|
||||
let client = get_client();
|
||||
let signer = client.signer().await.unwrap();
|
||||
let public_key = signer.get_public_key().await.unwrap();
|
||||
|
||||
let recv_filter = Filter::new()
|
||||
.kind(Kind::PrivateDirectMessage)
|
||||
.author(from)
|
||||
.pubkey(public_key);
|
||||
|
||||
let sender_filter = Filter::new()
|
||||
.kind(Kind::PrivateDirectMessage)
|
||||
.author(public_key)
|
||||
.pubkey(from);
|
||||
|
||||
let events = async_cx
|
||||
.background_executor()
|
||||
.spawn(async move {
|
||||
client
|
||||
.database()
|
||||
.query(vec![recv_filter, sender_filter])
|
||||
.await
|
||||
})
|
||||
.await;
|
||||
|
||||
if let Ok(events) = events {
|
||||
_ = async_cx.update_model(&async_messages, |a, b| {
|
||||
*a = Some(events);
|
||||
b.notify();
|
||||
});
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
||||
Self { messages }
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for Messages {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
let mut content = div().size_full().flex().flex_col().justify_end();
|
||||
|
||||
if let Some(messages) = self.messages.read(cx).as_ref() {
|
||||
content = content.children(messages.clone().into_iter().map(|m| div().child(m.content)))
|
||||
}
|
||||
|
||||
div().flex_1().child(content)
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,10 @@ use coop_ui::{
|
||||
Sizable,
|
||||
};
|
||||
use gpui::*;
|
||||
use messages::Messages;
|
||||
use nostr_sdk::*;
|
||||
|
||||
pub mod list;
|
||||
pub mod messages;
|
||||
|
||||
pub struct ChatPanel {
|
||||
// Panel
|
||||
@@ -18,13 +19,14 @@ pub struct ChatPanel {
|
||||
zoomable: bool,
|
||||
focus_handle: FocusHandle,
|
||||
// Chat Room
|
||||
receiver: PublicKey,
|
||||
messages: View<Messages>,
|
||||
input: View<TextInput>,
|
||||
}
|
||||
|
||||
impl ChatPanel {
|
||||
pub fn new(receiver: PublicKey, cx: &mut WindowContext) -> View<Self> {
|
||||
pub fn new(from: PublicKey, cx: &mut WindowContext) -> View<Self> {
|
||||
let input = cx.new_view(TextInput::new);
|
||||
let messages = cx.new_view(|cx| Messages::new(from, cx));
|
||||
|
||||
input.update(cx, |input, _cx| {
|
||||
input.set_placeholder("Message");
|
||||
@@ -35,7 +37,7 @@ impl ChatPanel {
|
||||
closeable: true,
|
||||
zoomable: true,
|
||||
focus_handle: cx.focus_handle(),
|
||||
receiver,
|
||||
messages,
|
||||
input,
|
||||
})
|
||||
}
|
||||
@@ -89,14 +91,7 @@ impl Render for ChatPanel {
|
||||
.size_full()
|
||||
.flex()
|
||||
.flex_col()
|
||||
.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.flex()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.child(self.receiver.to_hex()),
|
||||
)
|
||||
.child(self.messages.clone())
|
||||
.child(
|
||||
div()
|
||||
.flex_shrink_0()
|
||||
|
||||
@@ -130,7 +130,7 @@ impl RenderOnce for ChatItem {
|
||||
.on_click(move |_, cx| {
|
||||
cx.dispatch_action(Box::new(AddPanel {
|
||||
title: self.title.clone(),
|
||||
receiver: self.public_key,
|
||||
from: self.public_key,
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
Copyright 2024 Longbridge <https://longbridge.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
@@ -174,28 +189,3 @@ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
@@ -138,10 +138,18 @@ impl Dock {
|
||||
Self::subscribe_panel_events(dock_area.clone(), &panel, cx);
|
||||
|
||||
if !open {
|
||||
if let DockItem::Tabs { view, .. } = panel.clone() {
|
||||
view.update(cx, |panel, cx| {
|
||||
panel.set_collapsed(true, cx);
|
||||
});
|
||||
match panel.clone() {
|
||||
DockItem::Tabs { view, .. } => {
|
||||
view.update(cx, |panel, cx| {
|
||||
panel.set_collapsed(true, cx);
|
||||
});
|
||||
}
|
||||
DockItem::Split { items, .. } => {
|
||||
for item in items {
|
||||
item.set_collapsed(true, cx);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui::{
|
||||
div, prelude::FluentBuilder, px, rems, AnchorCorner, AppContext, DefiniteLength, DismissEvent,
|
||||
DragMoveEvent, Empty, Entity, EventEmitter, FocusHandle, FocusableView,
|
||||
@@ -7,7 +5,12 @@ use gpui::{
|
||||
SharedString, StatefulInteractiveElement, Styled, View, ViewContext, VisualContext as _,
|
||||
WeakView, WindowContext,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::{
|
||||
ClosePanel, DockArea, DockItemState, DockPlacement, Panel, PanelEvent, PanelStyle, PanelView,
|
||||
StackPanel, ToggleZoom,
|
||||
};
|
||||
use crate::{
|
||||
button::{Button, ButtonVariants as _},
|
||||
dock::DockItemInfo,
|
||||
@@ -18,11 +21,6 @@ use crate::{
|
||||
v_flex, AxisExt, IconName, Placement, Selectable, Sizable,
|
||||
};
|
||||
|
||||
use super::{
|
||||
ClosePanel, DockArea, DockItemState, DockPlacement, Panel, PanelEvent, PanelStyle, PanelView,
|
||||
StackPanel, ToggleZoom,
|
||||
};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct TabState {
|
||||
closeable: bool,
|
||||
@@ -173,6 +171,15 @@ impl TabPanel {
|
||||
|
||||
/// Add a panel to the end of the tabs
|
||||
pub fn add_panel(&mut self, panel: Arc<dyn PanelView>, cx: &mut ViewContext<Self>) {
|
||||
self.add_panel_with_active(panel, true, cx);
|
||||
}
|
||||
|
||||
fn add_panel_with_active(
|
||||
&mut self,
|
||||
panel: Arc<dyn PanelView>,
|
||||
active: bool,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
assert_ne!(
|
||||
panel.panel_name(cx),
|
||||
"StackPanel",
|
||||
@@ -189,7 +196,9 @@ impl TabPanel {
|
||||
|
||||
self.panels.push(panel);
|
||||
// set the active panel to the new panel
|
||||
self.set_active_ix(self.panels.len() - 1, cx);
|
||||
if active {
|
||||
self.set_active_ix(self.panels.len() - 1, cx);
|
||||
}
|
||||
cx.emit(PanelEvent::LayoutChanged);
|
||||
cx.notify();
|
||||
}
|
||||
@@ -543,6 +552,7 @@ impl TabPanel {
|
||||
)
|
||||
.children(self.panels.iter().enumerate().map(|(ix, panel)| {
|
||||
let mut active = ix == self.active_ix;
|
||||
let disabled = self.is_collapsed;
|
||||
|
||||
// Always not show active tab style, if the panel is collapsed
|
||||
if self.is_collapsed {
|
||||
@@ -552,31 +562,34 @@ impl TabPanel {
|
||||
Tab::new(("tab", ix), panel.title(cx))
|
||||
.py_2()
|
||||
.selected(active)
|
||||
.on_click(cx.listener(move |view, _, cx| {
|
||||
view.set_active_ix(ix, cx);
|
||||
}))
|
||||
.when(state.draggable, |this| {
|
||||
this.on_drag(
|
||||
DragPanel::new(panel.clone(), view.clone()),
|
||||
|drag, _, cx| {
|
||||
cx.stop_propagation();
|
||||
cx.new_view(|_| drag.clone())
|
||||
},
|
||||
)
|
||||
})
|
||||
.when(state.droppable, |this| {
|
||||
this.drag_over::<DragPanel>(|this, _, cx| {
|
||||
this.rounded_l_none()
|
||||
.border_l_2()
|
||||
.border_r_0()
|
||||
.border_color(cx.theme().drag_border)
|
||||
.disabled(disabled)
|
||||
.when(!disabled, |this| {
|
||||
this.on_click(cx.listener(move |view, _, cx| {
|
||||
view.set_active_ix(ix, cx);
|
||||
}))
|
||||
.when(state.draggable, |this| {
|
||||
this.on_drag(
|
||||
DragPanel::new(panel.clone(), view.clone()),
|
||||
|drag, _, cx| {
|
||||
cx.stop_propagation();
|
||||
cx.new_view(|_| drag.clone())
|
||||
},
|
||||
)
|
||||
})
|
||||
.when(state.droppable, |this| {
|
||||
this.drag_over::<DragPanel>(|this, _, cx| {
|
||||
this.rounded_l_none()
|
||||
.border_l_2()
|
||||
.border_r_0()
|
||||
.border_color(cx.theme().drag_border)
|
||||
})
|
||||
.on_drop(cx.listener(
|
||||
move |this, drag: &DragPanel, cx| {
|
||||
this.will_split_placement = None;
|
||||
this.on_drop(drag, Some(ix), true, cx)
|
||||
},
|
||||
))
|
||||
})
|
||||
.on_drop(cx.listener(
|
||||
move |this, drag: &DragPanel, cx| {
|
||||
this.will_split_placement = None;
|
||||
this.on_drop(drag, Some(ix), cx)
|
||||
},
|
||||
))
|
||||
})
|
||||
}))
|
||||
.child(
|
||||
@@ -597,7 +610,7 @@ impl TabPanel {
|
||||
None
|
||||
};
|
||||
|
||||
this.on_drop(drag, ix, cx)
|
||||
this.on_drop(drag, ix, false, cx)
|
||||
}))
|
||||
}),
|
||||
)
|
||||
@@ -620,6 +633,10 @@ impl TabPanel {
|
||||
}
|
||||
|
||||
fn render_active_panel(&self, state: TabState, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
if self.is_collapsed {
|
||||
return Empty {}.into_any_element();
|
||||
}
|
||||
|
||||
self.active_panel()
|
||||
.map(|panel| {
|
||||
div()
|
||||
@@ -658,7 +675,7 @@ impl TabPanel {
|
||||
})
|
||||
.group_drag_over::<DragPanel>("", |this| this.visible())
|
||||
.on_drop(cx.listener(|this, drag: &DragPanel, cx| {
|
||||
this.on_drop(drag, None, cx)
|
||||
this.on_drop(drag, None, true, cx)
|
||||
})),
|
||||
)
|
||||
})
|
||||
@@ -688,17 +705,28 @@ impl TabPanel {
|
||||
cx.notify()
|
||||
}
|
||||
|
||||
fn on_drop(&mut self, drag: &DragPanel, ix: Option<usize>, cx: &mut ViewContext<Self>) {
|
||||
/// Handle the drop event when dragging a panel
|
||||
///
|
||||
/// - `active` - When true, the panel will be active after the drop
|
||||
fn on_drop(
|
||||
&mut self,
|
||||
drag: &DragPanel,
|
||||
ix: Option<usize>,
|
||||
active: bool,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
let panel = drag.panel.clone();
|
||||
let is_same_tab = drag.tab_panel == *cx.view();
|
||||
|
||||
// If target is same tab, and it is only one panel, do nothing.
|
||||
if is_same_tab && ix.is_none() {
|
||||
#[allow(clippy::if_same_then_else)]
|
||||
if self.will_split_placement.is_none() {
|
||||
return;
|
||||
} else if self.panels.len() == 1 {
|
||||
return;
|
||||
} else {
|
||||
#[allow(clippy::collapsible_else_if)]
|
||||
if self.panels.len() == 1 {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -721,7 +749,7 @@ impl TabPanel {
|
||||
} else if let Some(ix) = ix {
|
||||
self.insert_panel_at(panel, ix, cx)
|
||||
} else {
|
||||
self.add_panel(panel, cx)
|
||||
self.add_panel_with_active(panel, active, cx)
|
||||
}
|
||||
|
||||
self.remove_self_if_empty(cx);
|
||||
|
||||
@@ -81,7 +81,7 @@ pub trait DropdownDelegate: Sized {
|
||||
}
|
||||
|
||||
fn perform_search(&mut self, _query: &str, _cx: &mut ViewContext<Dropdown<Self>>) -> Task<()> {
|
||||
Task::Ready(Some(()))
|
||||
Task::ready(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,11 +178,9 @@ where
|
||||
}
|
||||
|
||||
fn perform_search(&mut self, query: &str, cx: &mut ViewContext<List<Self>>) -> Task<()> {
|
||||
self.dropdown
|
||||
.upgrade()
|
||||
.map_or(Task::Ready(None), |dropdown| {
|
||||
dropdown.update(cx, |_, cx| self.delegate.perform_search(query, cx))
|
||||
})
|
||||
self.dropdown.upgrade().map_or(Task::ready(()), |dropdown| {
|
||||
dropdown.update(cx, |_, cx| self.delegate.perform_search(query, cx))
|
||||
})
|
||||
}
|
||||
|
||||
fn set_selected_index(&mut self, ix: Option<usize>, _: &mut ViewContext<List<Self>>) {
|
||||
@@ -285,7 +283,7 @@ impl<T: DropdownItem + Clone> DropdownDelegate for SearchableVec<T> {
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
Task::Ready(Some(()))
|
||||
Task::ready(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,6 @@ pub mod skeleton;
|
||||
pub mod slider;
|
||||
pub mod switch;
|
||||
pub mod tab;
|
||||
pub mod table;
|
||||
pub mod theme;
|
||||
pub mod tooltip;
|
||||
|
||||
@@ -78,5 +77,4 @@ pub fn init(cx: &mut gpui::AppContext) {
|
||||
modal::init(cx);
|
||||
popover::init(cx);
|
||||
popup_menu::init(cx);
|
||||
table::init(cx);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ pub trait ListDelegate: Sized + 'static {
|
||||
/// When Query Input change, this method will be called.
|
||||
/// You can perform search here.
|
||||
fn perform_search(&mut self, query: &str, cx: &mut ViewContext<List<Self>>) -> Task<()> {
|
||||
Task::Ready(Some(()))
|
||||
Task::ready(())
|
||||
}
|
||||
|
||||
/// Return the number of items in the list.
|
||||
@@ -126,7 +126,7 @@ where
|
||||
enable_scrollbar: true,
|
||||
loading: false,
|
||||
size: Size::default(),
|
||||
_search_task: Task::Ready(None),
|
||||
_search_task: Task::ready(()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ impl Element for ScrollableMask {
|
||||
bounds,
|
||||
border_widths: Edges::all(px(1.0)),
|
||||
border_color: color,
|
||||
background: gpui::transparent_white(),
|
||||
background: gpui::transparent_white().into(),
|
||||
corner_radii: Corners::all(px(0.)),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -597,7 +597,7 @@ impl Element for Scrollbar {
|
||||
cx.paint_quad(PaintQuad {
|
||||
bounds,
|
||||
corner_radii: (0.).into(),
|
||||
background: gpui::transparent_black(),
|
||||
background: gpui::transparent_black().into(),
|
||||
border_widths: if is_vertical {
|
||||
Edges {
|
||||
top: px(0.),
|
||||
|
||||
@@ -42,6 +42,12 @@ impl Tab {
|
||||
self.suffix = Some(suffix.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Set disabled state to the tab
|
||||
pub fn disabled(mut self, disabled: bool) -> Self {
|
||||
self.disabled = disabled;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Selectable for Tab {
|
||||
@@ -72,9 +78,11 @@ impl Styled for Tab {
|
||||
impl RenderOnce for Tab {
|
||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||
let (text_color, bg_color) = match (self.selected, self.disabled) {
|
||||
(true, _) => (cx.theme().tab_active_foreground, cx.theme().tab_active),
|
||||
(false, true) => (cx.theme().tab_foreground.opacity(0.5), cx.theme().tab),
|
||||
(true, false) => (cx.theme().tab_active_foreground, cx.theme().tab_active),
|
||||
(false, false) => (cx.theme().muted_foreground, cx.theme().tab),
|
||||
// disabled
|
||||
(true, true) => (cx.theme().muted_foreground, cx.theme().tab_active),
|
||||
(false, true) => (cx.theme().muted_foreground, cx.theme().tab),
|
||||
};
|
||||
|
||||
self.base
|
||||
@@ -89,7 +97,6 @@ impl RenderOnce for Tab {
|
||||
.border_color(cx.theme().transparent)
|
||||
.when(self.selected, |this| this.border_color(cx.theme().border))
|
||||
.text_sm()
|
||||
.when(self.disabled, |this| this)
|
||||
.when_some(self.prefix, |this, prefix| {
|
||||
this.child(prefix).text_color(text_color)
|
||||
})
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user