diff --git a/src/routes/search.rs b/src/routes/search.rs index 719663b78..a5ef0b2da 100644 --- a/src/routes/search.rs +++ b/src/routes/search.rs @@ -10,6 +10,7 @@ use diesel::prelude::*; use actix_web::client::Connector; use meilisearch_sdk::settings::Settings; use meilisearch_sdk::progress::SettingsUpdate; +use serde_json::from_str; #[derive(Serialize, Deserialize, Debug)] struct Attachment { @@ -44,6 +45,7 @@ struct CurseForgeMod { downloadCount: f32, categories: Vec, gameVersionLatestFiles: Vec, + dateCreated: String, dateModified: String, } @@ -59,6 +61,7 @@ struct SearchMod { page_url: String, icon_url: String, author_url: String, + date_created: String, date_modified: String, latest_version: String, empty: String, @@ -77,6 +80,7 @@ pub struct SearchRequest { q: Option, f: Option, v: Option, + o: Option, } #[post("search")] @@ -110,10 +114,11 @@ fn search(web::Query(info): web::Query) -> Vec { let mut search_query = "".to_string(); let mut filters = "".to_string(); + let mut offset = 0; match info.q { Some(q) => search_query = q, - None => search_query = "pdsaojdakdka".to_string() + None => search_query = "{}{}{}".to_string() } if let Some(f) = info.f { @@ -129,10 +134,14 @@ fn search(web::Query(info): web::Query) -> Vec { } } - let mut query = Query::new(&search_query).with_limit(10); + if let Some(o) = info.o { + offset = o.parse().unwrap(); + } + + let mut query = Query::new(&search_query).with_limit(10).with_offset(offset); if !filters.is_empty() { - query = Query::new(&search_query).with_limit(10).with_filters(&filters); + query = Query::new(&search_query).with_limit(10).with_filters(&filters).with_offset(offset); } client.get_index("mods").unwrap().search::(&query).unwrap().hits @@ -168,9 +177,10 @@ pub async fn index_mods(conn : PgConnection) { page_url: "".to_string(), icon_url: "".to_string(), author_url: "".to_string(), + date_created: "".to_string(), date_modified: "".to_string(), latest_version: "".to_string(), - empty: String::from("pdsaojdakdka") + empty: String::from("{}{}{}") }); } @@ -197,10 +207,6 @@ pub async fn index_mods(conn : PgConnection) { let mut mod_categories = vec![]; - if using_forge { - mod_categories.push(String::from("Forge")); - } - for category in curseforge_mod.categories { match &category.name[..] { "World Gen" => mod_categories.push(String::from("worldgen")), @@ -213,15 +219,16 @@ pub async fn index_mods(conn : PgConnection) { "Processing" => mod_categories.push(String::from("technology")), "Player Transport" => mod_categories.push(String::from("technology")), "Energy, Fluid, and Item Transport" => mod_categories.push(String::from("technology")), - "Farming" => mod_categories.push(String::from("technology")), + "Food" => mod_categories.push(String::from("food")), + "Farming" => mod_categories.push(String::from("food")), "Energy" => mod_categories.push(String::from("technology")), "Redstone" => mod_categories.push(String::from("technology")), "Genetics" => mod_categories.push(String::from("technology")), "Magic" => mod_categories.push(String::from("magic")), - "Storage" => mod_categories.push(String::from("technology")), + "Storage" => mod_categories.push(String::from("storage")), "API and Library" => mod_categories.push(String::from("library")), "Adventure and RPG" => mod_categories.push(String::from("adventure")), - "Map and Information" => mod_categories.push(String::from("adventure")), + "Map and Information" => mod_categories.push(String::from("utility")), "Cosmetic" => mod_categories.push(String::from("decoration")), "Addons" => mod_categories.push(String::from("misc")), "Thermal Expansion" => mod_categories.push(String::from("misc")), @@ -235,7 +242,7 @@ pub async fn index_mods(conn : PgConnection) { "Applied Energistics 2" => mod_categories.push(String::from("misc")), "CraftTweaker" => mod_categories.push(String::from("misc")), "Miscellaneous" => mod_categories.push(String::from("misc")), - "Armor, Tools, and Weapons" => mod_categories.push(String::from("technology")), + "Armor, Tools, and Weapons" => mod_categories.push(String::from("equipment")), "Server Utility" => mod_categories.push(String::from("utility")), "Fabric" => mod_categories.push(String::from("fabric")), _ => {} @@ -246,6 +253,10 @@ pub async fn index_mods(conn : PgConnection) { mod_categories.dedup(); mod_categories.truncate(3); + if using_forge { + mod_categories.push(String::from("forge")); + } + let mut mod_attachments = curseforge_mod.attachments; mod_attachments.retain(|x| x.isDefault); @@ -273,9 +284,10 @@ pub async fn index_mods(conn : PgConnection) { page_url: curseforge_mod.websiteUrl, icon_url: (mod_attachments[0].url).to_string(), author_url: (&curseforge_mod.authors[0].url).to_string(), + date_created: curseforge_mod.dateCreated.chars().take(10).collect(), date_modified: curseforge_mod.dateModified.chars().take(10).collect(), latest_version: latest_version, - empty: String::from("pdsaojdakdka") + empty: String::from("{}{}{}") }) } @@ -305,6 +317,7 @@ pub async fn index_mods(conn : PgConnection) { "page_url".to_string(), "icon_url".to_string(), "author_url".to_string(), + "date_created".to_string(), "date_modified".to_string(), "latest_version".to_string(), "empty".to_string(), diff --git a/static/css/search.css b/static/css/search.css index 05e1c2a4d..e675b5e88 100644 --- a/static/css/search.css +++ b/static/css/search.css @@ -299,4 +299,39 @@ .misc-badge { color: white; background-color: deepskyblue; +} + +.storage-badge { + color: wheat; + background-color: #e1a15a; +} + + +.food-badge { + color: white; + background-color: royalblue; +} + +.equipment-badge { + color: white; + background-color: black; +} + +.forge { + padding-top: 5px !important; +} + +.back-to-top { + position: fixed; + top: 80%; + left: 19%; + background-color: #0b75d8; + text-align: center; + padding: 20px; + display: none; +} + +.back-to-top img { + width: 50px; + height: 50px; } \ No newline at end of file diff --git a/static/images/icon/equipment.svg b/static/images/icon/equipment.svg new file mode 100644 index 000000000..50e2d08cf --- /dev/null +++ b/static/images/icon/equipment.svg @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/static/images/icon/food.svg b/static/images/icon/food.svg new file mode 100644 index 000000000..4a04a0ae1 --- /dev/null +++ b/static/images/icon/food.svg @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/static/images/icon/forge-alt.svg b/static/images/icon/forge-alt.svg new file mode 100644 index 000000000..6a15d2104 --- /dev/null +++ b/static/images/icon/forge-alt.svg @@ -0,0 +1,14 @@ + + + + + + + diff --git a/static/images/icon/forge.jpg b/static/images/icon/forge.jpg deleted file mode 100644 index 749dba107..000000000 Binary files a/static/images/icon/forge.jpg and /dev/null differ diff --git a/static/images/icon/forge.svg b/static/images/icon/forge.svg new file mode 100644 index 000000000..4f7f0495a --- /dev/null +++ b/static/images/icon/forge.svg @@ -0,0 +1,14 @@ + + + + + + + diff --git a/static/images/icon/storage.svg b/static/images/icon/storage.svg new file mode 100644 index 000000000..84c389807 --- /dev/null +++ b/static/images/icon/storage.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/static/images/icon/up.svg b/static/images/icon/up.svg new file mode 100644 index 000000000..f844e566f --- /dev/null +++ b/static/images/icon/up.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/static/js/search.js b/static/js/search.js index 1d97e1369..b83cdef60 100644 --- a/static/js/search.js +++ b/static/js/search.js @@ -9,6 +9,9 @@ let category_inputs = { "library": false, "worldgen": false, "cursed": false, + "storage": false, + "food": false, + "equipment": false, "misc": false, "forge": false, "fabric": false, @@ -93,7 +96,7 @@ function clearFilters() { } } - handleSearch(); + handleSearch(0); } function toggleVisibility(e) { @@ -124,7 +127,7 @@ function activateCategory(element) { document.getElementById(element.id + "-ghost").className = "category-ghost"; } - handleSearch(); + handleSearch(0); } function activateVersion(element) { @@ -138,16 +141,42 @@ function activateVersion(element) { element.style.boxShadow = "0 0"; } - handleSearch(); + handleSearch(0); } -function handleSearch() { +let body = document.documentElement; +let backToTop = document.getElementById("backToTop"); + +let currentlyLoadingExtra = false; +let currentOffset = 0; + +function loadExtra() { + console.log(body.scrollTop) + if (body.scrollTop > 400) { + backToTop.style.display = "block"; + } else { + backToTop.style.display = "none"; + } + + + if(!currentlyLoadingExtra) { + let scrollOffset = (body.scrollTop) / (body.scrollHeight - body.clientHeight); + + if(scrollOffset > 0.9) { + currentOffset += 10; + handleSearch(currentOffset); + currentlyLoadingExtra = true; + } + } +} + +function handleSearch(index) { let queryString = "search"; if(input.value.length > 0) { queryString += "?q=" + encodeURIComponent(input.value).replace(/%20/g,'+'); } else { - queryString += "?q=pdsaojdakdka" + queryString += "?q={}{}{}" } let filterString = ""; @@ -182,16 +211,30 @@ function handleSearch() { queryString += "&v=" + encodeURIComponent( "versions=" + versionString).replace(/%20/g,'+'); } + if(index === 0) + window.history.pushState('Search', 'Search', queryString); + else + queryString += "&o=" + index; + + console.log(queryString); + let xmlHttp = new XMLHttpRequest(); xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState === 4 && xmlHttp.status === 200) { - resultContainer.innerHTML = xmlHttp.responseText; + if(index === 0) { + resultContainer.innerHTML = xmlHttp.responseText; + + currentOffset = 0; + currentlyLoadingExtra = false; + } + else { + resultContainer.innerHTML += xmlHttp.responseText; + currentlyLoadingExtra = false; + } } } xmlHttp.open("POST", queryString, true); xmlHttp.send(null); - - window.history.pushState('Search', 'Search', queryString); } \ No newline at end of file diff --git a/templates/search.hbs b/templates/search.hbs index 3c2afd28e..f5747dfc6 100644 --- a/templates/search.hbs +++ b/templates/search.hbs @@ -12,7 +12,7 @@ Search - + + + up + +