diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index dc1b9d44..d60a3846 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -93,7 +93,8 @@ impl Page { pub fn bookmark(&self) { self.profile .bookmark - .toggle(self.navigation.request().widget().gobject().text().as_str()) + .toggle(self.navigation.request().widget().gobject().text().as_str()); + self.update(); } /// Navigate home URL (parsed from current navigation entry) diff --git a/src/profile/bookmark.rs b/src/profile/bookmark.rs index ed103624..a7559540 100644 --- a/src/profile/bookmark.rs +++ b/src/profile/bookmark.rs @@ -49,7 +49,10 @@ impl Bookmark { let time = DateTime::now_local().unwrap(); if self.has_request(request, false) { - // @TODO + match self.database.delete(request) { + Ok(_) => self.memory.delete(request), + Err(_) => todo!(), + } } else { match self.database.add(time.clone(), request.into()) { Ok(_) => self.memory.set(request.into(), time), diff --git a/src/profile/bookmark/database.rs b/src/profile/bookmark/database.rs index ea3cd383..410ade25 100644 --- a/src/profile/bookmark/database.rs +++ b/src/profile/bookmark/database.rs @@ -51,6 +51,23 @@ impl Database { Err(_) => Err(()), // @TODO } } + + pub fn delete(&self, request: &str) -> Result<(), ()> { + // Begin new transaction + let mut writable = self.connection.write().unwrap(); + let tx = writable.transaction().unwrap(); + + // Delete records match request + for record in select(&tx, self.profile_id, Some(request)).unwrap() { + let _ = delete(&tx, record.id); + } + + // Done + match tx.commit() { + Ok(_) => Ok(()), + Err(_) => Err(()), + } // @TODO handle result + } } // Low-level DB API diff --git a/src/profile/bookmark/memory.rs b/src/profile/bookmark/memory.rs index 5758019b..a8f4f3c7 100644 --- a/src/profile/bookmark/memory.rs +++ b/src/profile/bookmark/memory.rs @@ -33,6 +33,17 @@ impl Memory { index.insert(request, time); } + /// Check request exist in memory index + pub fn delete(&self, request: &str) { + // Borrow index to update + let mut index = self.index.borrow_mut(); + + // Delete record (if exist) + if index.get(request).is_some() { + index.remove(request); + } + } + /// Check request exist in memory index pub fn is_exist(&self, request: &str) -> bool { self.index.borrow().get(request).is_some()