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
+5 -1
View File
@@ -1,5 +1,6 @@
use ely_domain::{
BookmarkId, DomainError, DownloadId, PluginId, ProfileId, SpaceId, SplitId, TabId,
BookmarkId, DomainError, DownloadId, PluginId, ProfileId, ReadingListId, SpaceId, SplitId,
TabId,
};
use thiserror::Error;
@@ -26,6 +27,9 @@ pub enum CoreError {
#[error("download not found: {id}")]
DownloadNotFound { id: DownloadId },
#[error("reading list entry not found: {id}")]
ReadingListEntryNotFound { id: ReadingListId },
#[error("download target path is unavailable: {id}")]
DownloadTargetPathUnavailable { id: DownloadId },
@@ -1,6 +1,6 @@
use std::time::SystemTime;
use ely_domain::{ReadingListEntry, ReadingListId, UrlText};
use ely_domain::{ReadingListEntry, ReadingListId, ReadingProgress, UrlText};
use crate::CoreError;
@@ -27,6 +27,15 @@ impl BrowserCore {
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> {
let normalized_query = query.trim().to_lowercase();
if normalized_query.is_empty() {
@@ -48,6 +57,16 @@ impl BrowserCore {
.cloned()
.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 {
+30 -1
View File
@@ -1,7 +1,9 @@
use std::error::Error;
use ely_browser_core::{BrowserCore, InitialBrowserConfig};
use ely_domain::{CommandIntent, CommandScope, ProfileKind, ReadingProgress, UrlText};
use ely_domain::{
CommandIntent, CommandScope, ProfileKind, ReadingListId, ReadingProgress, UrlText,
};
#[test]
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(())
}
#[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]
fn reading_list_scoped_search_opens_matching_entry() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;