Add reading list progress actions

This commit is contained in:
2026-05-08 06:23:21 -04:00
parent fc00840697
commit e13557814d
7 changed files with 152 additions and 16 deletions
@@ -1,12 +1,16 @@
use ely_browser_core::BrowserSnapshot; use ely_browser_core::BrowserSnapshot;
use ely_design_system::colors; use ely_design_system::colors;
use ely_domain::{ReadingListEntry, ReadingProgress}; use ely_domain::{ReadingListEntry, ReadingListId, ReadingProgress};
use gpui::prelude::FluentBuilder; use gpui::prelude::FluentBuilder;
use gpui::{ use gpui::{
AnyElement, Context, InteractiveElement, IntoElement, ParentElement, SharedString, AnyElement, Context, InteractiveElement, IntoElement, ParentElement, SharedString,
StatefulInteractiveElement, Styled, div, px, rgb, StatefulInteractiveElement, Styled, div, px, rgb,
}; };
use gpui_component::{IconName, StyledExt, scroll::ScrollableElement}; use gpui_component::{
IconName, Sizable, StyledExt,
button::{Button, ButtonVariants},
scroll::ScrollableElement,
};
use super::{ElyShell, render_canvas_surface}; use super::{ElyShell, render_canvas_surface};
@@ -58,19 +62,23 @@ impl ElyShell {
.reading_list .reading_list
.iter() .iter()
.rev() .rev()
.map(|entry| self.render_reading_list_row(snapshot, entry, cx)), .enumerate()
.map(|(index, entry)| self.render_reading_list_row(index, snapshot, entry, cx)),
) )
.into_any_element() .into_any_element()
} }
fn render_reading_list_row( fn render_reading_list_row(
&mut self, &mut self,
index: usize,
snapshot: &BrowserSnapshot, snapshot: &BrowserSnapshot,
entry: &ReadingListEntry, entry: &ReadingListEntry,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> AnyElement { ) -> AnyElement {
let url = entry.source_url().clone(); let url = entry.source_url().clone();
let space_name = reading_list_space_name(snapshot, entry); let space_name = reading_list_space_name(snapshot, entry);
let entry_id = entry.id().clone();
let progress = *entry.progress();
div() div()
.id(SharedString::from(format!("reading-{}", entry.id().as_str()))) .id(SharedString::from(format!("reading-{}", entry.id().as_str())))
@@ -81,18 +89,20 @@ impl ElyShell {
.items_center() .items_center()
.justify_between() .justify_between()
.gap_4() .gap_4()
.child(
div()
.id(SharedString::from(format!("reading-open-{}", entry.id().as_str())))
.min_w_0()
.flex_1()
.flex()
.items_center()
.gap_3()
.cursor_pointer() .cursor_pointer()
.hover(|style| style.bg(rgb(colors::CANVAS_SOFT))) .hover(|style| style.bg(rgb(colors::CANVAS_SOFT)))
.active(|style| style.opacity(0.82)) .active(|style| style.opacity(0.82))
.on_click(cx.listener(move |shell, _, window, cx| { .on_click(cx.listener(move |shell, _, window, cx| {
shell.open_url(url.clone(), window, cx); shell.open_url(url.clone(), window, cx);
})) }))
.child(
div()
.min_w_0()
.flex()
.items_center()
.gap_3()
.child(div().text_color(rgb(colors::MUTED_SOFT)).child(IconName::Inbox)) .child(div().text_color(rgb(colors::MUTED_SOFT)).child(IconName::Inbox))
.child( .child(
div() div()
@@ -132,6 +142,7 @@ impl ElyShell {
}) })
.child(progress_label(entry.progress())), .child(progress_label(entry.progress())),
) )
.child(render_progress_action(index, entry_id, progress, cx))
.into_any_element() .into_any_element()
} }
} }
@@ -172,9 +183,31 @@ fn reading_list_space_name(snapshot: &BrowserSnapshot, entry: &ReadingListEntry)
} }
fn progress_label(progress: &ReadingProgress) -> &'static str { fn progress_label(progress: &ReadingProgress) -> &'static str {
match progress { progress.label()
ReadingProgress::Unread => "Unread", }
}
fn render_progress_action(
index: usize,
entry_id: ReadingListId,
progress: ReadingProgress,
cx: &mut Context<ElyShell>,
) -> AnyElement {
let next_progress = progress.toggled();
let icon = match progress {
ReadingProgress::Unread => IconName::CircleCheck,
ReadingProgress::Finished => IconName::Undo2,
};
Button::new(("reading-progress", index))
.ghost()
.xsmall()
.icon(icon)
.label(progress.action_label())
.tooltip(progress.action_label())
.on_click(cx.listener(move |shell, _, _, cx| {
shell.set_reading_list_progress(&entry_id, next_progress, cx);
}))
.into_any_element()
} }
fn reading_list_count_label(count: usize) -> String { fn reading_list_count_label(count: usize) -> String {
+1
View File
@@ -3,6 +3,7 @@ mod downloads;
mod history; mod history;
mod internal_pages; mod internal_pages;
mod plugins; mod plugins;
mod reading_list;
mod render; mod render;
mod site_permissions; mod site_permissions;
mod splits; mod splits;
+19
View File
@@ -0,0 +1,19 @@
use ely_domain::{ReadingListId, ReadingProgress};
use gpui::Context;
use super::{ElyShell, ShellState};
impl ElyShell {
pub(super) fn set_reading_list_progress(
&mut self,
entry_id: &ReadingListId,
progress: ReadingProgress,
cx: &mut Context<Self>,
) {
if let ShellState::Ready(core) = &mut self.state
&& core.set_reading_list_progress(entry_id, progress).is_ok()
{
cx.notify();
}
}
}
+5 -1
View File
@@ -1,5 +1,6 @@
use ely_domain::{ use ely_domain::{
BookmarkId, DomainError, DownloadId, PluginId, ProfileId, SpaceId, SplitId, TabId, BookmarkId, DomainError, DownloadId, PluginId, ProfileId, ReadingListId, SpaceId, SplitId,
TabId,
}; };
use thiserror::Error; use thiserror::Error;
@@ -26,6 +27,9 @@ pub enum CoreError {
#[error("download not found: {id}")] #[error("download not found: {id}")]
DownloadNotFound { id: DownloadId }, DownloadNotFound { id: DownloadId },
#[error("reading list entry not found: {id}")]
ReadingListEntryNotFound { id: ReadingListId },
#[error("download target path is unavailable: {id}")] #[error("download target path is unavailable: {id}")]
DownloadTargetPathUnavailable { id: DownloadId }, DownloadTargetPathUnavailable { id: DownloadId },
@@ -1,6 +1,6 @@
use std::time::SystemTime; use std::time::SystemTime;
use ely_domain::{ReadingListEntry, ReadingListId, UrlText}; use ely_domain::{ReadingListEntry, ReadingListId, ReadingProgress, UrlText};
use crate::CoreError; use crate::CoreError;
@@ -27,6 +27,15 @@ impl BrowserCore {
Ok(entry_id) Ok(entry_id)
} }
pub fn set_reading_list_progress(
&mut self,
entry_id: &ReadingListId,
progress: ReadingProgress,
) -> Result<(), CoreError> {
self.reading_list_entry_mut(entry_id)?.set_progress(progress);
Ok(())
}
pub(super) fn find_reading_list_match(&self, query: &str) -> Option<UrlText> { pub(super) fn find_reading_list_match(&self, query: &str) -> Option<UrlText> {
let normalized_query = query.trim().to_lowercase(); let normalized_query = query.trim().to_lowercase();
if normalized_query.is_empty() { if normalized_query.is_empty() {
@@ -48,6 +57,16 @@ impl BrowserCore {
.cloned() .cloned()
.collect() .collect()
} }
fn reading_list_entry_mut(
&mut self,
entry_id: &ReadingListId,
) -> Result<&mut ReadingListEntry, CoreError> {
self.reading_list
.iter_mut()
.find(|entry| entry.id() == entry_id)
.ok_or_else(|| CoreError::ReadingListEntryNotFound { id: entry_id.clone() })
}
} }
fn reading_list_entry_matches_query(entry: &ReadingListEntry, normalized_query: &str) -> bool { fn reading_list_entry_matches_query(entry: &ReadingListEntry, normalized_query: &str) -> bool {
+30 -1
View File
@@ -1,7 +1,9 @@
use std::error::Error; use std::error::Error;
use ely_browser_core::{BrowserCore, InitialBrowserConfig}; use ely_browser_core::{BrowserCore, InitialBrowserConfig};
use ely_domain::{CommandIntent, CommandScope, ProfileKind, ReadingProgress, UrlText}; use ely_domain::{
CommandIntent, CommandScope, ProfileKind, ReadingListId, ReadingProgress, UrlText,
};
#[test] #[test]
fn save_active_tab_records_reading_list_context() -> Result<(), Box<dyn Error>> { fn save_active_tab_records_reading_list_context() -> Result<(), Box<dyn Error>> {
@@ -41,6 +43,33 @@ fn save_active_tab_reuses_existing_reading_list_entry() -> Result<(), Box<dyn Er
Ok(()) Ok(())
} }
#[test]
fn reading_list_progress_updates_entry() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
core.open_tab(UrlText::parse("https://example.com/long-read")?);
let entry_id = core.save_active_tab_to_reading_list()?;
core.set_reading_list_progress(&entry_id, ReadingProgress::Finished)?;
let snapshot = core.snapshot()?;
assert_eq!(snapshot.reading_list[0].id(), &entry_id);
assert_eq!(snapshot.reading_list[0].progress(), &ReadingProgress::Finished);
Ok(())
}
#[test]
fn missing_reading_list_progress_update_returns_error() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let missing_id = ReadingListId::new();
let Err(error) = core.set_reading_list_progress(&missing_id, ReadingProgress::Finished) else {
return Err("expected missing reading list entry error".into());
};
assert_eq!(error, ely_browser_core::CoreError::ReadingListEntryNotFound { id: missing_id });
Ok(())
}
#[test] #[test]
fn reading_list_scoped_search_opens_matching_entry() -> Result<(), Box<dyn Error>> { fn reading_list_scoped_search_opens_matching_entry() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?; let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
+32 -1
View File
@@ -2,9 +2,36 @@ use std::time::SystemTime;
use crate::{DomainError, ProfileId, ReadingListId, SpaceId, UrlText}; use crate::{DomainError, ProfileId, ReadingListId, SpaceId, UrlText};
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ReadingProgress { pub enum ReadingProgress {
Unread, Unread,
Finished,
}
impl ReadingProgress {
#[must_use]
pub fn label(self) -> &'static str {
match self {
Self::Unread => "Unread",
Self::Finished => "Read",
}
}
#[must_use]
pub fn action_label(self) -> &'static str {
match self {
Self::Unread => "Mark Read",
Self::Finished => "Mark Unread",
}
}
#[must_use]
pub fn toggled(self) -> Self {
match self {
Self::Unread => Self::Finished,
Self::Finished => Self::Unread,
}
}
} }
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]
@@ -74,6 +101,10 @@ impl ReadingListEntry {
&self.progress &self.progress
} }
pub fn set_progress(&mut self, progress: ReadingProgress) {
self.progress = progress;
}
#[must_use] #[must_use]
pub fn added_at(&self) -> SystemTime { pub fn added_at(&self) -> SystemTime {
self.added_at self.added_at