update repo list
This commit is contained in:
@@ -60,6 +60,7 @@ impl BackendEvent {
|
|||||||
pub struct Backend {
|
pub struct Backend {
|
||||||
inner: NostrBackend,
|
inner: NostrBackend,
|
||||||
current_user: Option<PublicKey>,
|
current_user: Option<PublicKey>,
|
||||||
|
connected: bool,
|
||||||
tasks: Vec<Task<Result<(), Error>>>,
|
tasks: Vec<Task<Result<(), Error>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,6 +107,7 @@ impl Backend {
|
|||||||
let mut this = Self {
|
let mut this = Self {
|
||||||
inner,
|
inner,
|
||||||
current_user: None,
|
current_user: None,
|
||||||
|
connected: false,
|
||||||
tasks: vec![pump],
|
tasks: vec![pump],
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -132,7 +134,11 @@ impl Backend {
|
|||||||
self.tasks.push(cx.spawn(async move |this, cx| {
|
self.tasks.push(cx.spawn(async move |this, cx| {
|
||||||
match task.await {
|
match task.await {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
this.update(cx, |_this, cx| cx.emit(BackendEvent::Connected))?;
|
this.update(cx, |this, cx| {
|
||||||
|
this.connected = true;
|
||||||
|
cx.emit(BackendEvent::Connected);
|
||||||
|
cx.notify();
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
this.update(cx, |_this, cx| cx.emit(BackendEvent::error(e.to_string())))?;
|
this.update(cx, |_this, cx| cx.emit(BackendEvent::error(e.to_string())))?;
|
||||||
@@ -371,6 +377,11 @@ impl Backend {
|
|||||||
self.current_user
|
self.current_user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether the relay bootstrap has completed.
|
||||||
|
pub fn is_connected(&self) -> bool {
|
||||||
|
self.connected
|
||||||
|
}
|
||||||
|
|
||||||
/// Update the signer (any type implementing the async signer traits,
|
/// Update the signer (any type implementing the async signer traits,
|
||||||
/// e.g. `Keys`, `NostrConnect`, a browser extension proxy).
|
/// e.g. `Keys`, `NostrConnect`, a browser extension proxy).
|
||||||
pub fn set_signer<T>(&mut self, new_signer: T, cx: &mut Context<Self>)
|
pub fn set_signer<T>(&mut self, new_signer: T, cx: &mut Context<Self>)
|
||||||
@@ -418,7 +429,11 @@ impl Backend {
|
|||||||
self.tasks.push(cx.spawn(async move |this, cx| {
|
self.tasks.push(cx.spawn(async move |this, cx| {
|
||||||
match task.await {
|
match task.await {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
this.update(cx, |_this, cx| cx.emit(BackendEvent::Connected))?;
|
this.update(cx, |this, cx| {
|
||||||
|
this.connected = true;
|
||||||
|
cx.emit(BackendEvent::Connected);
|
||||||
|
cx.notify();
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
this.update(cx, |_this, cx| cx.emit(BackendEvent::error(e.to_string())))?;
|
this.update(cx, |_this, cx| cx.emit(BackendEvent::error(e.to_string())))?;
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ pub struct RepoListStore {
|
|||||||
impl RepoListStore {
|
impl RepoListStore {
|
||||||
/// Create a store. If `author` is `None`, all announcements are listed.
|
/// Create a store. If `author` is `None`, all announcements are listed.
|
||||||
pub fn new(author: Option<PublicKey>, cx: &mut Context<Self>) -> Self {
|
pub fn new(author: Option<PublicKey>, cx: &mut Context<Self>) -> Self {
|
||||||
let subscription = cx.subscribe(&Backend::global(cx), |this, _backend, event, cx| {
|
let backend = Backend::global(cx);
|
||||||
|
let subscription = cx.subscribe(&backend, |this, _backend, event, cx| {
|
||||||
let relevant = match event {
|
let relevant = match event {
|
||||||
BackendEvent::NostrUpdate(update) => {
|
BackendEvent::NostrUpdate(update) => {
|
||||||
update.kind == Kind::GitRepoAnnouncement
|
update.kind == Kind::GitRepoAnnouncement
|
||||||
@@ -60,9 +61,10 @@ impl RepoListStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn subscribe_remote(&mut self, cx: &mut Context<Self>) {
|
fn subscribe_remote(&mut self, cx: &mut Context<Self>) {
|
||||||
|
let backend = Backend::global(cx);
|
||||||
let author = self.author;
|
let author = self.author;
|
||||||
|
|
||||||
Backend::global(cx).update(cx, |backend, cx| {
|
backend.update(cx, |backend, cx| {
|
||||||
let filter = match author {
|
let filter = match author {
|
||||||
Some(a) => filters::announcements_by(a),
|
Some(a) => filters::announcements_by(a),
|
||||||
None => filters::all_announcements(500),
|
None => filters::all_announcements(500),
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
use gpui::prelude::*;
|
use gpui::prelude::*;
|
||||||
use gpui::{Context, Entity, Render, SharedString, Subscription, Window, div, px};
|
use gpui::{
|
||||||
use gpui_component::scroll::ScrollableElement;
|
AnyElement, App, Context, Entity, Render, SharedString, Subscription, Window, div, px,
|
||||||
|
uniform_list,
|
||||||
|
};
|
||||||
use gpui_component::{ActiveTheme, StyledExt};
|
use gpui_component::{ActiveTheme, StyledExt};
|
||||||
use signed_core::Announcement;
|
use signed_core::Announcement;
|
||||||
use signed_state::{ProfileStore, RepoListStore};
|
use signed_state::{ProfileStore, RepoListStore};
|
||||||
|
|
||||||
/// Browse all announced repositories.
|
/// Browse all announced repositories (works anonymously).
|
||||||
pub struct RepoListView {
|
pub struct RepoListView {
|
||||||
store: Entity<RepoListStore>,
|
store: Entity<RepoListStore>,
|
||||||
_subscription: Subscription,
|
_subscription: Subscription,
|
||||||
@@ -21,44 +23,58 @@ impl RepoListView {
|
|||||||
_subscription: subscription,
|
_subscription: subscription,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn render_card(&self, announcement: &Announcement, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render_card(announcement: &Announcement, cx: &mut App) -> AnyElement {
|
||||||
let name = announcement
|
let name = announcement
|
||||||
.name
|
.name
|
||||||
.clone()
|
.clone()
|
||||||
.unwrap_or_else(|| announcement.id.clone());
|
.unwrap_or_else(|| announcement.id.clone());
|
||||||
|
|
||||||
let owner = ProfileStore::global(cx)
|
let owner = ProfileStore::global(cx)
|
||||||
.update(cx, |store, cx| store.get(announcement.owner, cx))
|
.update(cx, |store, cx| store.get(announcement.owner, cx))
|
||||||
.name();
|
.name();
|
||||||
|
|
||||||
div()
|
let description = announcement.description.clone().unwrap_or_default();
|
||||||
.v_flex()
|
|
||||||
.gap_1()
|
div()
|
||||||
.px_4()
|
.v_flex()
|
||||||
.py_3()
|
.h(px(60.))
|
||||||
.border_b(px(1.))
|
.justify_center()
|
||||||
.border_color(cx.theme().border)
|
.gap_1()
|
||||||
.child(
|
.px_4()
|
||||||
div()
|
.border_b(px(1.))
|
||||||
.h_flex()
|
.border_color(cx.theme().border)
|
||||||
.gap_2()
|
.child(
|
||||||
.items_center()
|
div()
|
||||||
.child(div().text_sm().font_semibold().child(name))
|
.h_flex()
|
||||||
.child(
|
.gap_2()
|
||||||
div()
|
.items_center()
|
||||||
.text_xs()
|
.child(
|
||||||
.text_color(cx.theme().muted_foreground)
|
div()
|
||||||
.child(owner),
|
.text_sm()
|
||||||
),
|
.font_semibold()
|
||||||
)
|
.whitespace_nowrap()
|
||||||
.children(announcement.description.as_ref().map(|description| {
|
.text_ellipsis()
|
||||||
div()
|
.child(name),
|
||||||
.text_xs()
|
)
|
||||||
.text_color(cx.theme().muted_foreground)
|
.child(
|
||||||
.child(description.clone())
|
div()
|
||||||
}))
|
.text_xs()
|
||||||
}
|
.text_color(cx.theme().muted_foreground)
|
||||||
|
.whitespace_nowrap()
|
||||||
|
.child(owner),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_xs()
|
||||||
|
.text_color(cx.theme().muted_foreground)
|
||||||
|
.whitespace_nowrap()
|
||||||
|
.text_ellipsis()
|
||||||
|
.child(description),
|
||||||
|
)
|
||||||
|
.into_any_element()
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Render for RepoListView {
|
impl Render for RepoListView {
|
||||||
@@ -66,22 +82,28 @@ impl Render for RepoListView {
|
|||||||
let announcements = self.store.read(cx).announcements.clone();
|
let announcements = self.store.read(cx).announcements.clone();
|
||||||
let count = announcements.len();
|
let count = announcements.len();
|
||||||
|
|
||||||
let mut list = div().v_flex().flex_1().overflow_y_scrollbar();
|
let body = if announcements.is_empty() {
|
||||||
|
div()
|
||||||
if announcements.is_empty() {
|
.size_full()
|
||||||
list = list.child(
|
.v_flex()
|
||||||
div().size_full().items_center().justify_center().child(
|
.items_center()
|
||||||
|
.justify_center()
|
||||||
|
.child(
|
||||||
div()
|
div()
|
||||||
.text_sm()
|
.text_sm()
|
||||||
.text_color(cx.theme().muted_foreground)
|
.text_color(cx.theme().muted_foreground)
|
||||||
.child("No repositories found. Waiting for relays..."),
|
.child("No repositories found. Waiting for relays..."),
|
||||||
),
|
)
|
||||||
);
|
.into_any_element()
|
||||||
} else {
|
} else {
|
||||||
for announcement in &announcements {
|
uniform_list("repo-list", count, move |range, _window, cx| {
|
||||||
list = list.child(self.render_card(announcement, cx));
|
range
|
||||||
}
|
.map(|index| render_card(&announcements[index], cx))
|
||||||
}
|
.collect()
|
||||||
|
})
|
||||||
|
.size_full()
|
||||||
|
.into_any_element()
|
||||||
|
};
|
||||||
|
|
||||||
div()
|
div()
|
||||||
.v_flex()
|
.v_flex()
|
||||||
@@ -100,6 +122,6 @@ impl Render for RepoListView {
|
|||||||
.child(SharedString::from(format!(" ({count})"))),
|
.child(SharedString::from(format!(" ({count})"))),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.child(list)
|
.child(body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,12 @@ pub struct Workspace {
|
|||||||
|
|
||||||
impl Workspace {
|
impl Workspace {
|
||||||
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
|
let backend = Backend::global(cx);
|
||||||
let repo_list = cx.new(|cx| RepoListView::new(window, cx));
|
let repo_list = cx.new(|cx| RepoListView::new(window, cx));
|
||||||
|
|
||||||
let subscription = cx.subscribe(&Backend::global(cx), |this, _backend, event, cx| {
|
let connected = backend.read(cx).is_connected();
|
||||||
|
|
||||||
|
let subscription = cx.subscribe(&backend, |this, _backend, event, cx| {
|
||||||
match event {
|
match event {
|
||||||
BackendEvent::Connected => this.status = "Connected".into(),
|
BackendEvent::Connected => this.status = "Connected".into(),
|
||||||
BackendEvent::Error(error) => this.status = error.clone().into(),
|
BackendEvent::Error(error) => this.status = error.clone().into(),
|
||||||
@@ -27,7 +30,11 @@ impl Workspace {
|
|||||||
|
|
||||||
Self {
|
Self {
|
||||||
active_screen: repo_list.into(),
|
active_screen: repo_list.into(),
|
||||||
status: SharedString::from("Connecting..."),
|
status: if connected {
|
||||||
|
"Connected".into()
|
||||||
|
} else {
|
||||||
|
"Connecting...".into()
|
||||||
|
},
|
||||||
_subscription: subscription,
|
_subscription: subscription,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user