mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 09:10:08 +00:00
complete bookmark toggle features
This commit is contained in:
parent
232f67b9cc
commit
c511b97d2d
@ -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)
|
||||
|
@ -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),
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user