complete bookmark toggle features

This commit is contained in:
yggverse 2024-11-14 09:58:36 +02:00
parent 232f67b9cc
commit c511b97d2d
4 changed files with 34 additions and 2 deletions

View File

@ -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)

View File

@ -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),

View File

@ -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

View File

@ -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()