Skip to content

Commit

Permalink
refactor search route and change default page to 0
Browse files Browse the repository at this point in the history
that thing was utterly insane, and i am not sorry for saying this
  • Loading branch information
PhantomMorrigan committed Jun 29, 2023
1 parent bb65e4e commit 1f90b4e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 35 deletions.
4 changes: 2 additions & 2 deletions public/static/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function navigate_backward() {
let page = parseInt(searchParams.get('page'));

if (isNaN(page)) {
page = 1;
} else if (page > 1) {
page = 0;
} else if (page > 0) {
page--;
}

Expand Down
42 changes: 9 additions & 33 deletions src/server/routes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! This module provides the functionality to handle different routes of the `websurfx`
//! meta search engine website and provide approriate response to each route/page
//! meta search engine website and provide appropriate response to each route/page
//! when requested.
use std::fs::read_to_string;
Expand Down Expand Up @@ -82,40 +82,16 @@ pub async fn search(
.insert_header(("location", "/"))
.finish())
} else {
let page_url: String; // Declare the page_url variable without initializing it

// ...

let page = match params.page {
Some(page_number) => {
if page_number <= 1 {
page_url = format!(
"http://{}:{}/search?q={}&page={}",
config.binding_ip_addr, config.port, query, 1
);
1
} else {
page_url = format!(
"http://{}:{}/search?q={}&page={}",
config.binding_ip_addr, config.port, query, page_number
);

page_number
}
}
None => {
page_url = format!(
"http://{}:{}{}&page={}",
config.binding_ip_addr,
config.port,
req.uri(),
1
);

1
}
let page = match &params.page {
Some(page) => *page,
None => 0,
};

let page_url = format!(
"http://{}:{}/search?q={}&page={}",
config.binding_ip_addr, config.port, query, page
);

// fetch the cached results json.
let cached_results_json = redis_cache.cached_results_json(&page_url);
// check if fetched results was indeed fetched or it was an error and if so
Expand Down

0 comments on commit 1f90b4e

Please sign in to comment.