Add reading list removal
This commit is contained in:
@@ -143,6 +143,7 @@ impl ElyShell {
|
||||
.child(progress_label(entry.progress())),
|
||||
)
|
||||
.child(render_progress_action(index, entry_id, progress, cx))
|
||||
.child(render_remove_action(index, entry.id().clone(), cx))
|
||||
.into_any_element()
|
||||
}
|
||||
}
|
||||
@@ -210,6 +211,23 @@ fn render_progress_action(
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
fn render_remove_action(
|
||||
index: usize,
|
||||
entry_id: ReadingListId,
|
||||
cx: &mut Context<ElyShell>,
|
||||
) -> AnyElement {
|
||||
Button::new(("remove-reading-list", index))
|
||||
.danger()
|
||||
.xsmall()
|
||||
.icon(IconName::Delete)
|
||||
.label("Remove")
|
||||
.tooltip("Remove From Reading List")
|
||||
.on_click(cx.listener(move |shell, _, _, cx| {
|
||||
shell.remove_reading_list_entry(&entry_id, cx);
|
||||
}))
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
fn reading_list_count_label(count: usize) -> String {
|
||||
match count {
|
||||
1 => "1 item".to_string(),
|
||||
|
||||
@@ -16,4 +16,16 @@ impl ElyShell {
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn remove_reading_list_entry(
|
||||
&mut self,
|
||||
entry_id: &ReadingListId,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
if let ShellState::Ready(core) = &mut self.state
|
||||
&& core.remove_reading_list_entry(entry_id).is_ok()
|
||||
{
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,12 @@ impl BrowserCore {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn remove_reading_list_entry(&mut self, entry_id: &ReadingListId) -> Result<(), CoreError> {
|
||||
let index = self.reading_list_entry_index(entry_id)?;
|
||||
self.reading_list.remove(index);
|
||||
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() {
|
||||
@@ -62,9 +68,14 @@ impl BrowserCore {
|
||||
&mut self,
|
||||
entry_id: &ReadingListId,
|
||||
) -> Result<&mut ReadingListEntry, CoreError> {
|
||||
let index = self.reading_list_entry_index(entry_id)?;
|
||||
Ok(&mut self.reading_list[index])
|
||||
}
|
||||
|
||||
fn reading_list_entry_index(&self, entry_id: &ReadingListId) -> Result<usize, CoreError> {
|
||||
self.reading_list
|
||||
.iter_mut()
|
||||
.find(|entry| entry.id() == entry_id)
|
||||
.iter()
|
||||
.position(|entry| entry.id() == entry_id)
|
||||
.ok_or_else(|| CoreError::ReadingListEntryNotFound { id: entry_id.clone() })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,32 @@ fn missing_reading_list_progress_update_returns_error() -> Result<(), Box<dyn Er
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_reading_list_entry_removes_saved_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.remove_reading_list_entry(&entry_id)?;
|
||||
let snapshot = core.snapshot()?;
|
||||
|
||||
assert!(snapshot.reading_list.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_reading_list_remove_returns_error() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let missing_id = ReadingListId::new();
|
||||
|
||||
let Err(error) = core.remove_reading_list_entry(&missing_id) 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()?)?;
|
||||
|
||||
Reference in New Issue
Block a user