refresh cache
This commit is contained in:
parent
fcf6aded19
commit
44cde5c6f9
1 changed files with 27 additions and 12 deletions
39
src/main.rs
39
src/main.rs
|
@ -92,18 +92,7 @@ impl eframe::App for MyApp {
|
|||
if buff.is_empty() {
|
||||
self.cache = None;
|
||||
} else {
|
||||
let mut tmp: Vec<(usize, Tweet)> = Vec::new();
|
||||
let mut i = 0;
|
||||
tweets.iter().for_each(|tweet| {
|
||||
let tmp_str = String::from(buff.clone());
|
||||
if tweet.full_text.to_lowercase().contains(&tmp_str.to_lowercase()) {
|
||||
tmp.push((i, tweet.clone()));
|
||||
}
|
||||
|
||||
i += 1;
|
||||
});
|
||||
|
||||
self.cache = Some(tmp);
|
||||
self.create_cache(buff.clone());
|
||||
}
|
||||
|
||||
self.search = Some(buff);
|
||||
|
@ -146,7 +135,9 @@ impl eframe::App for MyApp {
|
|||
});
|
||||
row.col(|ui| {
|
||||
if ui.button("Supprimer").clicked() {
|
||||
//self.cache.as_mut().unwrap().remove(i);
|
||||
self.remove_tweet(*index);
|
||||
self.update_cache();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -197,4 +188,28 @@ impl MyApp {
|
|||
tweets.remove(index);
|
||||
}
|
||||
}
|
||||
|
||||
fn update_cache(&mut self) {
|
||||
if let Some(s) = &self.search {
|
||||
self.cache = None;
|
||||
self.create_cache(s.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
fn create_cache(&mut self, buff: String) {
|
||||
if let Some(tweets) = &self.tweets {
|
||||
let mut tmp: Vec<(usize, Tweet)> = Vec::new();
|
||||
let mut i = 0;
|
||||
tweets.iter().for_each(|tweet| {
|
||||
let tmp_str = String::from(buff.clone());
|
||||
if tweet.full_text.to_lowercase().contains(&tmp_str.to_lowercase()) {
|
||||
tmp.push((i, tweet.clone()));
|
||||
}
|
||||
|
||||
i += 1;
|
||||
});
|
||||
|
||||
self.cache = Some(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue