-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add first backend implementation of storing strings.
- Loading branch information
1 parent
d9dee1a
commit d4a70fc
Showing
2 changed files
with
26 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,31 @@ | ||
use crate::state::cnl_state::CNLState; | ||
use std::{collections::HashMap, sync::Mutex}; | ||
use tauri::State; | ||
|
||
pub(crate) struct SearchStringStorage { | ||
pub(crate) store: Mutex<HashMap<String, String>>, | ||
} | ||
|
||
|
||
#[tauri::command] | ||
pub async fn get_stored_search_string( | ||
state: tauri::State<'_, CNLState>, | ||
pub fn get_stored_search_string( | ||
page: String, | ||
storage: State<SearchStringStorage> | ||
) -> Result<String, ()> { | ||
/* TODO return string from lookup table with key page. | ||
If present delete entry else return empty string. | ||
*/ | ||
Ok("".parse().unwrap()) | ||
let str = storage.store.lock().unwrap().remove(&page); | ||
if str.is_none() { | ||
Ok("".parse().unwrap()) | ||
} | ||
else { | ||
Ok("".parse().unwrap()) // TODO return string | ||
} | ||
} | ||
|
||
#[tauri::command] | ||
pub async fn store_search_string( | ||
state: tauri::State<'_, CNLState>, | ||
pub fn store_search_string( | ||
page: String, | ||
string: String | ||
string: String, | ||
storage: State<SearchStringStorage> | ||
) -> Result<(), ()> { | ||
// TODO save page: string in a lookup table | ||
storage.store.lock().unwrap().insert(page, string); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters