Add reading list internal page
This commit is contained in:
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user