Add reading list internal page

This commit is contained in:
2026-05-08 00:57:59 -04:00
parent e225fac222
commit b8d2b291b2
15 changed files with 486 additions and 4 deletions
@@ -17,6 +17,7 @@ fn internal_page_title(url: &str) -> Option<&'static str> {
match url {
"ely://new-tab" => Some("New Tab"),
"ely://bookmarks" => Some("Bookmarks"),
"ely://reading-list" => Some("Reading List"),
"ely://downloads" => Some("Downloads"),
"ely://history" => Some("History"),
"ely://archive" => Some("Archived Tabs"),
@@ -89,6 +90,10 @@ pub(crate) fn bookmarks_url() -> Result<UrlText, CoreError> {
internal_page_url("ely://bookmarks")
}
pub(crate) fn reading_list_url() -> Result<UrlText, CoreError> {
internal_page_url("ely://reading-list")
}
pub(crate) fn history_url() -> Result<UrlText, CoreError> {
internal_page_url("ely://history")
}
+7 -1
View File
@@ -2,7 +2,8 @@ use std::collections::BTreeMap;
use ely_domain::{
ArchivedTab, BookmarkEntry, BrowserTab, DomainError, DownloadEntry, DownloadPolicy,
HistoryEntry, Profile, ProfileId, ProfileKind, Space, SpaceId, SyncStatus, TabId, UrlText,
HistoryEntry, Profile, ProfileId, ProfileKind, ReadingListEntry, Space, SpaceId, SyncStatus,
TabId, UrlText,
};
use crate::CoreError;
@@ -13,6 +14,7 @@ mod downloads;
mod history;
mod plugins;
mod profiles;
mod reading_list;
mod sync;
mod tabs;
@@ -44,6 +46,7 @@ pub struct BrowserSnapshot {
pub pinned_tabs: Vec<BrowserTab>,
pub archived_tabs: Vec<ArchivedTab>,
pub bookmarks: Vec<BookmarkEntry>,
pub reading_list: Vec<ReadingListEntry>,
pub download_entries: Vec<DownloadEntry>,
pub history_entries: Vec<HistoryEntry>,
pub installed_plugins: Vec<InstalledPlugin>,
@@ -67,6 +70,7 @@ pub struct BrowserCore {
tabs: Vec<BrowserTab>,
archived_tabs: Vec<ArchivedTab>,
bookmarks: Vec<BookmarkEntry>,
reading_list: Vec<ReadingListEntry>,
download_entries: Vec<DownloadEntry>,
history_entries: Vec<HistoryEntry>,
installed_plugins: Vec<InstalledPlugin>,
@@ -112,6 +116,7 @@ impl BrowserCore {
tabs: vec![tab],
archived_tabs: Vec::new(),
bookmarks: Vec::new(),
reading_list: Vec::new(),
download_entries: Vec::new(),
history_entries: Vec::new(),
installed_plugins: Vec::new(),
@@ -194,6 +199,7 @@ impl BrowserCore {
pinned_tabs: self.pinned_tabs(),
archived_tabs: self.archived_tabs.clone(),
bookmarks: self.visible_bookmarks(),
reading_list: self.visible_reading_list(),
download_entries: self.visible_downloads(),
history_entries: self.visible_history(),
installed_plugins: self.installed_plugins.clone(),
+16 -2
View File
@@ -4,8 +4,8 @@ use crate::{
CoreError,
navigation::{
about_url, bookmarks_url, downloads_url, history_url, move_tab_space_name,
new_profile_name, new_space_name, search_url, settings_page_url, settings_url, space_icon,
switch_profile_name, sync_status_url,
new_profile_name, new_space_name, reading_list_url, search_url, settings_page_url,
settings_url, space_icon, switch_profile_name, sync_status_url,
},
};
@@ -57,6 +57,12 @@ impl BrowserCore {
self.command_query.clear();
}
}
CommandIntent::ScopedSearch { scope: CommandScope::ReadingList, query } => {
if let Some(url) = self.find_reading_list_match(query) {
self.open_tab(url);
self.command_query.clear();
}
}
CommandIntent::ScopedSearch { scope: CommandScope::Settings, query } => {
if let Some(url) = settings_page_url(query)? {
self.open_tab(url);
@@ -112,6 +118,10 @@ impl BrowserCore {
self.open_tab(bookmarks_url()?);
Ok(true)
}
"reading-list" | "open-reading-list" | "open reading list" => {
self.open_tab(reading_list_url()?);
Ok(true)
}
"history" | "open-history" | "open history" => {
self.open_tab(history_url()?);
Ok(true)
@@ -140,6 +150,10 @@ impl BrowserCore {
self.bookmark_active_tab()?;
Ok(true)
}
"save-reading-list" | "save reading list" | "read-later" | "read later" => {
self.save_active_tab_to_reading_list()?;
Ok(true)
}
"pin" | "pin-tab" | "toggle-pin" => {
self.toggle_active_tab_pinned()?;
Ok(true)
@@ -0,0 +1,57 @@
use std::time::SystemTime;
use ely_domain::{ReadingListEntry, ReadingListId, UrlText};
use crate::CoreError;
use super::BrowserCore;
impl BrowserCore {
pub fn save_active_tab_to_reading_list(&mut self) -> Result<ReadingListId, CoreError> {
let active_tab = self.active_tab()?.clone();
if let Some(entry) = self.reading_list.iter().find(|entry| {
entry.profile_id() == active_tab.profile_id() && entry.source_url() == active_tab.url()
}) {
return Ok(entry.id().clone());
}
let entry = ReadingListEntry::new(
active_tab.profile_id().clone(),
active_tab.space_id().clone(),
active_tab.title(),
active_tab.url().clone(),
SystemTime::now(),
)?;
let entry_id = entry.id().clone();
self.reading_list.push(entry);
Ok(entry_id)
}
pub(super) fn find_reading_list_match(&self, query: &str) -> Option<UrlText> {
let normalized_query = query.trim().to_lowercase();
if normalized_query.is_empty() {
return None;
}
self.reading_list
.iter()
.rev()
.filter(|entry| entry.profile_id() == &self.active_profile_id)
.find(|entry| reading_list_entry_matches_query(entry, &normalized_query))
.map(|entry| entry.source_url().clone())
}
pub(super) fn visible_reading_list(&self) -> Vec<ReadingListEntry> {
self.reading_list
.iter()
.filter(|entry| entry.profile_id() == &self.active_profile_id)
.cloned()
.collect()
}
}
fn reading_list_entry_matches_query(entry: &ReadingListEntry, normalized_query: &str) -> bool {
entry.title().to_lowercase().contains(normalized_query)
|| entry.source_url().as_str().to_lowercase().contains(normalized_query)
|| entry.display_url().to_lowercase().contains(normalized_query)
}
@@ -20,6 +20,11 @@ impl BrowserCore {
self.bookmarks.len(),
SyncObjectState::LocalOnly,
),
SyncObjectStatus::new(
SyncObjectKind::ReadingList,
self.reading_list.len(),
SyncObjectState::LocalOnly,
),
SyncObjectStatus::new(
SyncObjectKind::Profiles,
self.profiles.len(),
@@ -0,0 +1,108 @@
use std::error::Error;
use ely_browser_core::{BrowserCore, InitialBrowserConfig};
use ely_domain::{CommandIntent, CommandScope, ProfileKind, ReadingProgress, UrlText};
#[test]
fn save_active_tab_records_reading_list_context() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let tab_id = core.open_tab(UrlText::parse("https://example.com/long-read")?);
let active_profile_id = core.active_tab()?.profile_id().clone();
let active_space_id = core.active_tab()?.space_id().clone();
let entry_id = core.save_active_tab_to_reading_list()?;
let snapshot = core.snapshot()?;
let [entry] = snapshot.reading_list.as_slice() else {
return Err(
format!("expected 1 reading list entry, got {}", snapshot.reading_list.len()).into()
);
};
assert_eq!(snapshot.active_tab_id, tab_id);
assert_eq!(entry.id(), &entry_id);
assert_eq!(entry.profile_id(), &active_profile_id);
assert_eq!(entry.space_id(), &active_space_id);
assert_eq!(entry.title(), "example.com");
assert_eq!(entry.source_url().as_str(), "https://example.com/long-read");
assert_eq!(entry.progress(), &ReadingProgress::Unread);
Ok(())
}
#[test]
fn save_active_tab_reuses_existing_reading_list_entry() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
core.open_tab(UrlText::parse("https://example.com/long-read")?);
let first_id = core.save_active_tab_to_reading_list()?;
let second_id = core.save_active_tab_to_reading_list()?;
assert_eq!(first_id, second_id);
assert_eq!(core.snapshot()?.reading_list.len(), 1);
Ok(())
}
#[test]
fn reading_list_scoped_search_opens_matching_entry() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
core.open_tab(UrlText::parse("https://example.com/long-read")?);
core.save_active_tab_to_reading_list()?;
core.set_command_query("@reading-list long-read");
let intent = core.submit_command()?;
let snapshot = core.snapshot()?;
let active_tab = core.active_tab()?;
assert_eq!(
intent,
Some(CommandIntent::ScopedSearch {
scope: CommandScope::ReadingList,
query: "long-read".to_string()
})
);
assert_eq!(active_tab.url().as_str(), "https://example.com/long-read");
assert_eq!(snapshot.command_query, "");
Ok(())
}
#[test]
fn reading_list_stays_with_active_profile() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let default_profile_id = core.active_tab()?.profile_id().clone();
let personal_profile_id = core.create_profile("Personal", 0xf54e00, ProfileKind::Standard)?;
core.open_tab(UrlText::parse("https://example.com/personal")?);
core.save_active_tab_to_reading_list()?;
core.select_profile(&default_profile_id)?;
core.set_command_query("@reading-list personal");
let intent = core.submit_command()?;
let snapshot = core.snapshot()?;
assert_eq!(
intent,
Some(CommandIntent::ScopedSearch {
scope: CommandScope::ReadingList,
query: "personal".to_string()
})
);
assert_eq!(core.active_tab()?.profile_id(), &default_profile_id);
assert_ne!(core.active_tab()?.profile_id(), &personal_profile_id);
assert!(snapshot.reading_list.is_empty());
assert_eq!(snapshot.command_query, "@reading-list personal");
Ok(())
}
#[test]
fn open_reading_list_command_opens_reading_list_page() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
core.set_command_query(">open-reading-list");
let intent = core.submit_command()?;
let active_tab = core.active_tab()?;
assert_eq!(intent, Some(CommandIntent::Command("open-reading-list".to_string())));
assert_eq!(active_tab.title(), "Reading List");
assert_eq!(active_tab.url().as_str(), "ely://reading-list");
assert_eq!(core.snapshot()?.command_query, "");
Ok(())
}
+2
View File
@@ -9,6 +9,7 @@ fn default_sync_status_reflects_local_browser_state() -> Result<(), Box<dyn Erro
core.create_space("Research", "R", 0xf54e00)?;
core.open_tab(UrlText::parse("https://example.com/research")?);
core.bookmark_active_tab()?;
core.save_active_tab_to_reading_list()?;
let snapshot = core.snapshot()?;
let status = &snapshot.sync_status;
@@ -22,6 +23,7 @@ fn default_sync_status_reflects_local_browser_state() -> Result<(), Box<dyn Erro
SyncObjectStatus::new(SyncObjectKind::Spaces, 2, SyncObjectState::LocalOnly),
SyncObjectStatus::new(SyncObjectKind::Tabs, 3, SyncObjectState::LocalOnly),
SyncObjectStatus::new(SyncObjectKind::Bookmarks, 1, SyncObjectState::LocalOnly),
SyncObjectStatus::new(SyncObjectKind::ReadingList, 1, SyncObjectState::LocalOnly),
SyncObjectStatus::new(SyncObjectKind::Profiles, 1, SyncObjectState::LocalOnly),
SyncObjectStatus::new(SyncObjectKind::History, 1, SyncObjectState::PrivacyControlled),
SyncObjectStatus::new(SyncObjectKind::PluginSettings, 0, SyncObjectState::LocalOnly),