fix: handle no results
This commit is contained in:
parent
d3c68a49d9
commit
2b936652dd
|
@ -16,6 +16,8 @@ pub use self::{
|
|||
selectors!(
|
||||
PAGINATION_TOTAL => ".parts__total";
|
||||
PAGINATION_PAGES => ".btn__pager__current";
|
||||
|
||||
NO_RESULTS => "p.parts__zero";
|
||||
);
|
||||
|
||||
crate fn parse_pagination(html: &Html) -> Result<Pagination> {
|
||||
|
@ -48,3 +50,10 @@ crate fn parse_pagination(html: &Html) -> Result<Pagination> {
|
|||
total_results,
|
||||
})
|
||||
}
|
||||
|
||||
crate fn parse_no_results<'a>(html: &Html) -> bool {
|
||||
html.select(&*NO_RESULTS)
|
||||
.next()
|
||||
.map(|x| x.text().collect::<String>() == "Your search yielded no results.")
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
|
|
@ -32,6 +32,13 @@ selectors!(
|
|||
pub fn parse(html: &str) -> Result<Paginated<CharacterSearchItem>> {
|
||||
let html = Html::parse_document(html);
|
||||
|
||||
if crate::logic::search::parse_no_results(&html) {
|
||||
return Ok(Paginated {
|
||||
pagination: Default::default(),
|
||||
results: Default::default(),
|
||||
});
|
||||
}
|
||||
|
||||
let pagination = crate::logic::search::parse_pagination(&html)?;
|
||||
|
||||
let results: Vec<CharacterSearchItem> = html
|
||||
|
|
|
@ -38,6 +38,13 @@ selectors!(
|
|||
pub fn parse(s: &str) -> Result<Paginated<FreeCompanySearchItem>> {
|
||||
let html = Html::parse_document(s);
|
||||
|
||||
if crate::logic::search::parse_no_results(&html) {
|
||||
return Ok(Paginated {
|
||||
pagination: Default::default(),
|
||||
results: Default::default(),
|
||||
});
|
||||
}
|
||||
|
||||
let pagination = crate::logic::search::parse_pagination(&html)?;
|
||||
|
||||
let results: Vec<FreeCompanySearchItem> = html
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
pub mod character;
|
||||
pub mod free_company;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct Pagination {
|
||||
pub current_page: u64,
|
||||
pub total_pages: u64,
|
||||
|
|
Loading…
Reference in New Issue