Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
973 changes: 408 additions & 565 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion hacker-news-gpui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ path = "src/main.rs"

[dependencies]
anyhow.workspace = true
async-compat = "0.2"
chrono.workspace = true
flexi_logger.workspace = true
futures = "0.3"
gpui = { git = "https://github.com/zed-industries/zed.git" }
gpui_platform = { git = "https://github.com/zed-industries/zed.git" }
gpui_tokio = { git = "https://github.com/zed-industries/zed.git" }
hacker-news-api.workspace = true
hacker-news-config.workspace = true
html-sanitizer.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion hacker-news-gpui/src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl Render for CommentView {
div()
.bg(theme.comment_border())
.flex()
.flex_grow()
.flex_grow(1.0)
.flex_row()
.rounded_tl_md()
.text_size(rems(0.75))
Expand Down
13 changes: 8 additions & 5 deletions hacker-news-gpui/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use gpui::{
App, AppContext, AsyncApp, Entity, Fill, Image, SharedString, StyleRefinement, Styled as _,
http_client::Url, solid_background,
};
use gpui_tokio::Tokio;
use log::error;
use std::{
borrow::Cow,
Expand Down Expand Up @@ -78,6 +79,7 @@ pub async fn comment_entities(
cx.emit(ContentEvent::Error(None));
});
let client = app.read_global(|client: &ApiClientState, _| client.0.clone());

let item_stream = client
.items(comment_ids)
.into_stream()
Expand All @@ -92,7 +94,10 @@ pub async fn comment_entities(
})
.collect::<Vec<_>>();

let comment_items = async_compat::Compat::new(item_stream).await;
let comment_items = Tokio::spawn(app, item_stream)
.await
.inspect_err(|err| error!("Failed to spawn task to fetch comments: {err}"))
.unwrap_or_default();

comment_items
.into_iter()
Expand Down Expand Up @@ -139,10 +144,8 @@ pub fn hover_element(theme: Theme) -> impl Fn(StyleRefinement) -> StyleRefinemen
}
}

pub fn save_config(
config: Config,
) -> async_compat::Compat<impl Future<Output = Result<(), anyhow::Error>>> {
async_compat::Compat::new(hacker_news_config::save_config(config, CONFIG_FILE))
pub fn save_config(config: Config) -> impl Future<Output = Result<(), anyhow::Error>> {
hacker_news_config::save_config(config, CONFIG_FILE)
}

pub fn update_url(app: &mut App, url: Option<SharedString>) {
Expand Down
3 changes: 2 additions & 1 deletion hacker-news-gpui/src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use gpui::{
App, AppContext, Entity, EventEmitter, FocusHandle, ListState, Pixels, ScrollHandle, Window,
prelude::*, px,
};
use gpui_tokio::JoinError;
use hacker_news_api::{ArticleType, Item};
use log::{error, info};
use std::{collections::HashMap, f32};
Expand All @@ -34,7 +35,7 @@ pub struct ContentView {
/// Subscription to server side events is online.
pub online: bool,
/// Handle to the background task that updates articles.
background_task: Option<gpui::Task<()>>,
background_task: Option<gpui::Task<Result<(), JoinError>>>,
/// Sender channel for pushing article updates from background to foreground.
article_sender: Option<channel::mpsc::Sender<Result<Vec<Item>, BackGroundError>>>,
/// The number of times we have refresh due to an http server side event.
Expand Down
10 changes: 5 additions & 5 deletions hacker-news-gpui/src/content/background.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Background tasks.
use super::{ContentEvent, ContentView};
use crate::{ApiClientState, ArticleSelection, article::ArticleView};
use async_compat::Compat;
use futures::{SinkExt, StreamExt, TryStreamExt as _, channel};
use gpui::{App, AppContext, Context, Entity};
use gpui_tokio::JoinError;
use hacker_news_api::{ArticleType, Item, subscribe_to_article_list};
use log::{error, info};
use std::collections::HashMap;
Expand Down Expand Up @@ -56,7 +56,7 @@ pub(super) enum BackGroundError {
pub(super) fn start_background_subscriptions(
app: &mut App,
entity_content: &Entity<ContentView>,
) -> gpui::Task<()> {
) -> gpui::Task<Result<(), JoinError>> {
let entity_content = entity_content.clone();
let (tx, mut rx) = channel::mpsc::channel::<Result<Vec<Item>, BackGroundError>>(10);

Expand Down Expand Up @@ -192,7 +192,7 @@ pub(super) fn start_background_subscriptions(
pub(super) fn start_background_article_list_subscription(
app: &mut App,
mut tx: channel::mpsc::Sender<Result<Vec<Item>, BackGroundError>>,
) -> gpui::Task<()> {
) -> gpui::Task<Result<(), JoinError>> {
let ArticleSelection {
viewing_article_type,
viewing_article_total,
Expand All @@ -202,7 +202,7 @@ pub(super) fn start_background_article_list_subscription(

let client = app.read_global(|client: &ApiClientState, _app| client.0.clone());

app.background_executor().spawn(Compat::new(async move {
gpui_tokio::Tokio::spawn(app, async move {
let (mut rx, handle) = subscribe_to_article_list(viewing_article_type);

while let Some(event) = rx.recv().await {
Expand Down Expand Up @@ -236,5 +236,5 @@ pub(super) fn start_background_article_list_subscription(
}

handle.abort();
}))
})
}
2 changes: 1 addition & 1 deletion hacker-news-gpui/src/content/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl ContentView {
.child(
div()
.flex()
.flex_grow()
.flex_grow(1.0)
.flex_row()
.text_size(rems(0.75))
.bg(theme.comment_border())
Expand Down
1 change: 1 addition & 0 deletions hacker-news-gpui/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ fn mk_button(label: SharedString) -> Stateful<Div> {
offset: point(px(2.0), px(2.0)),
blur_radius: px(2.0),
spread_radius: px(2.0),
inset: true,
}])
.id(label.clone())
.child(label)
Expand Down
2 changes: 2 additions & 0 deletions hacker-news-gpui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ fn main() -> anyhow::Result<()> {
let client = Arc::new(hacker_news_api::ApiClient::new()?);

application().run(move |app| {
gpui_tokio::init(app);

app.set_global(ApiClientState(client));
app.set_global(ArticleSelection {
viewing_article_type: ArticleType::Top,
Expand Down
Loading