chore: restructure and refine the ui (#199)
* update deps * clean up * add account crate * add person crate * add chat and chat ui crates * . * clean up the ui crate * . * .
This commit is contained in:
18
crates/account/Cargo.toml
Normal file
18
crates/account/Cargo.toml
Normal file
@@ -0,0 +1,18 @@
|
||||
[package]
|
||||
name = "account"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
publish.workspace = true
|
||||
|
||||
[dependencies]
|
||||
states = { path = "../states" }
|
||||
|
||||
gpui.workspace = true
|
||||
|
||||
nostr.workspace = true
|
||||
nostr-sdk.workspace = true
|
||||
|
||||
anyhow.workspace = true
|
||||
smallvec.workspace = true
|
||||
smol.workspace = true
|
||||
log.workspace = true
|
||||
54
crates/account/src/lib.rs
Normal file
54
crates/account/src/lib.rs
Normal file
@@ -0,0 +1,54 @@
|
||||
use gpui::{App, AppContext, Context, Entity, Global, Task};
|
||||
use nostr_sdk::prelude::*;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
|
||||
pub fn init(public_key: PublicKey, cx: &mut App) {
|
||||
Account::set_global(cx.new(|cx| Account::new(public_key, cx)), cx);
|
||||
}
|
||||
|
||||
struct GlobalAccount(Entity<Account>);
|
||||
|
||||
impl Global for GlobalAccount {}
|
||||
|
||||
pub struct Account {
|
||||
/// The public key of the account
|
||||
public_key: PublicKey,
|
||||
|
||||
/// Tasks for asynchronous operations
|
||||
_tasks: SmallVec<[Task<()>; 1]>,
|
||||
}
|
||||
|
||||
impl Account {
|
||||
/// Retrieve the global account state
|
||||
pub fn global(cx: &App) -> Entity<Self> {
|
||||
cx.global::<GlobalAccount>().0.clone()
|
||||
}
|
||||
|
||||
/// Check if the global account state exists
|
||||
pub fn has_global(cx: &App) -> bool {
|
||||
cx.has_global::<GlobalAccount>()
|
||||
}
|
||||
|
||||
/// Remove the global account state
|
||||
pub fn remove_global(cx: &mut App) {
|
||||
cx.remove_global::<GlobalAccount>();
|
||||
}
|
||||
|
||||
/// Set the global account instance
|
||||
pub(crate) fn set_global(state: Entity<Self>, cx: &mut App) {
|
||||
cx.set_global(GlobalAccount(state));
|
||||
}
|
||||
|
||||
/// Create a new account instance
|
||||
pub(crate) fn new(public_key: PublicKey, _cx: &mut Context<Self>) -> Self {
|
||||
Self {
|
||||
public_key,
|
||||
_tasks: smallvec![],
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the public key of the account
|
||||
pub fn public_key(&self) -> PublicKey {
|
||||
self.public_key
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user