diff --git a/public/static/pagination.js b/public/static/pagination.js index 72ce320..92f9272 100644 --- a/public/static/pagination.js +++ b/public/static/pagination.js @@ -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--; } diff --git a/src/server/routes.rs b/src/server/routes.rs index 9234d8d..60d3007 100644 --- a/src/server/routes.rs +++ b/src/server/routes.rs @@ -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; @@ -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 ¶ms.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