();
let _ = use_infinite_scroll_with_options(
@@ -67,294 +68,220 @@ fn Home() -> impl IntoView {
res.and_then(move |_| {
set_all.update(|dat| dat.extend(res().unwrap().unwrap()));
});
- /*if !res.loading().get() {
- set_page.update(|page| *page += 1);
- } else if res().is_some() {
- set_all.update(|dat| dat.extend(res().unwrap().unwrap()));
- // println!("{:?}", all().len())
- }*/
},
- UseInfiniteScrollOptions::default().distance(10.0),
+ UseInfiniteScrollOptions::default().distance(512.),
);
view! {
-
-
().unwrap());
- }
+
+
+
+
- prop:value=size
- type="range"
- min="0.5"
- max="2"
- step="0.5"
- value="1"
- />
+
+
"Input is: " {search_string}
+
+
+
-
}
}
-use serde::{Deserialize, Serialize};
-
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
-pub struct PicStruct {
- key: String,
- width: i32,
- height: i32,
- url: String,
-}
-
-#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
-struct Wallpaper {
+pub struct Wallpaper {
file_name: String,
info: String,
date_added: String,
- height: u64,
- width: u64,
+ height: i32,
+ width: i32,
path: String,
thumbs: Vec
,
}
-
-#[derive(Debug, Serialize)]
-struct Name<'a> {
- first: &'a str,
- last: &'a str,
-}
-
-#[derive(Debug, Serialize)]
-struct Person<'a> {
- title: &'a str,
- name: Name<'a>,
- marketing: bool,
-}
-
-#[derive(Debug, Serialize)]
-struct Responsibility {
- marketing: bool,
-}
-
-#[derive(Debug, Deserialize)]
-struct Record {
- #[allow(dead_code)]
- id: i32,
-}
-
-use std::env;
-
-#[server(GetPics, "/api")]
-pub async fn get_pics2(page: i32, size: f64) -> Result, ServerFnError> {
- use image::GenericImageView;
- use imageinfo::ImageInfo;
- use std::fs;
- use std::path::PathBuf;
-
+#[server(GetPicsSearch, "/api")]
+pub async fn get_pics(search_string: String) -> Result, ServerFnError> {
let query = "
- SELECT * FROM wallpapers LIMIT 10;
+ DEFINE ANALYZER book_analyzer TOKENIZERS blank,class,punct FILTERS snowball(english);
+ DEFINE INDEX info_s ON wallpapers FIELDS info SEARCH ANALYZER book_analyzer BM25(1.2,0.75);
+ SELECT *
+ FROM wallpapers
+ WHERE info @0@ 'asdasd'
+ LIMIT 10;
";
-
let db = Surreal::new::("127.0.0.1:8000")
.await
.expect("Couldnt connect to db server");
+ println!("{search_string:#?}");
+ db.set("page", search_string)
+ .await
+ .expect("Couldnt set war");
// Select a specific namespace / database
db.use_ns("test")
.use_db("test")
.await
.expect("Couldnt find db");
- //let papers: Vec = db.select("wallpapers").await.expect("Err");
- //println!("{papers:#?}");
- let mut res = db.query(query).await?;
- let pap: Vec = res.take(0)?;
- println!("{pap:#?}");
+ let mut res = db.query(query).await.expect("Something");
+ let pap: Vec = res.take(0).expect("Something");
+ //println!("{pap:#?}");
- let mut pics = Vec::new();
+ Ok(pap)
+}
- let folder_path = "./public";
+#[server(GetPics, "/api")]
+pub async fn get_pics2(page: i32) -> Result, ServerFnError> {
+ let query = "
+ SELECT * FROM wallpapers LIMIT 20 START $page;
+ ";
- // Define the number of pictures per page
- let pics_per_page = 10;
+ let db = Surreal::new::("127.0.0.1:8000")
+ .await
+ .expect("Couldnt connect to db server");
+ println!("{page:#?}");
+ db.set("page", page * 20).await.expect("Couldnt set war");
+ // Select a specific namespace / database
+ db.use_ns("test")
+ .use_db("test")
+ .await
+ .expect("Couldnt find db");
- // Calculate the index to start from based on the page number
- let start_index = (page) * pics_per_page;
- let end_index = start_index + pics_per_page;
+ let mut res = db.query(query).await.expect("Something");
+ let pap: Vec = res.take(0).expect("Something");
+ //println!("{pap:#?}");
- // manage a vector with all the image paths
- let mut image_file_paths = Vec::::new();
- for entry in fs::read_dir(folder_path)? {
- let entry = entry?;
- let file_path = entry.path();
- let file_name_str = file_path.file_name().unwrap_or_default().to_str().unwrap();
- if size == 0.5 {
- //skip 1024 and 512
- if file_name_str.contains("512x512") || file_name_str.contains("1024x1024") {
- continue;
- }
- } else if size == 1.0 {
- if file_name_str.contains("256x256") || file_name_str.contains("1024x1024") {
- println!("sdfasdf");
- continue;
- }
- } else if size == 1.5 {
- if file_name_str.contains("256x256") || file_name_str.contains("512x512") {
- continue;
- }
- }
- image_file_paths.push(file_path.clone());
- }
-
- for (i, file_path) in image_file_paths.iter().enumerate() {
- if file_path.is_file() {
- if i < start_index as usize {
- continue;
- }
- let file = std::fs::File::open(file_path)?;
- let mut bufreader = std::io::BufReader::new(&file);
- let exifreader = exif::Reader::new();
- let exif = exifreader.read_from_container(&mut bufreader)?;
- for f in exif.fields() {
- println!(
- "{} {} {}",
- f.tag,
- f.ifd_num,
- f.display_value().with_unit(&exif)
- );
- }
- let file_name = file_path.file_name().unwrap_or_default();
- let file_name_str = file_name.to_str().unwrap();
- // Check if the file has a supported image extension
- if let Some(extension) = file_path.extension() {
- if let Some(extension_str) = extension.to_str() {
- if image::ImageFormat::from_extension(extension_str).is_some() {
- // Process the image
- let img = image::open(&file_path).expect("Failed to open image");
- let (x, y) = img.dimensions();
-
- pics.push(PicStruct {
- key: file_name_str.to_string(), // Could not be unique if two images were created at exactly
- // the same time
- width: x as i32,
- height: y as i32,
- url: file_name.to_string_lossy().into(),
- });
- if i + 1 >= end_index as usize {
- break;
- }
- }
- }
- }
- }
- }
-
- // Send different picture resolutions depending on selected size
- // sizes 256 512 1024
-
- // Iterate over the entries in the folder
- /*for (index, entry) in fs::read_dir(folder_path)
- .expect("Failed to read directory")
- .enumerate()
- {
- if let Ok(entry) = entry {
- if index < start_index as usize {
- // Skip pictures before the start index
- continue;
- }
-
- let file_path = entry.path();
- let file_name = file_path.file_name().unwrap_or_default();
- let file_name_str = file_name.to_str().unwrap();
- // Skip the wrong sizes
- if size == 0.5 {
- //skip 1024 and 512
- if file_name_str.contains("512x512") || file_name_str.contains("1024x1024") {
- continue;
- }
- } else if size == 1.0 {
- if file_name_str.contains("256x256") || file_name_str.contains("1024x1024") {
- continue;
- }
- } else if size == 1.5 {
- if file_name_str.contains("256x256") || file_name_str.contains("512x512") {
- continue;
- }
- }
-
- // Check if the entry is a file
- if file_path.is_file() {
- // Check if the file has a supported image extension
- if let Some(extension) = file_path.extension() {
- if let Some(extension_str) = extension.to_str() {
- if image::ImageFormat::from_extension(extension_str).is_some() {
- // Process the image
- let img = image::open(&file_path).expect("Failed to open image");
- let (x, y) = img.dimensions();
-
- pics.push(PicStruct {
- key: file_name_str.to_string(), // Could not be unique if two images were created at exactly
- // the same time
- width: x as i32,
- height: y as i32,
- url: file_name.to_string_lossy().into(),
- });
-
- // Break if we have reached the end index
- if index + 1 >= end_index as usize {
- break;
- }
- }
- }
- }
- }
- }
- }*/
- println!("{:#?}", pics);
-
- Ok(pics)
+ Ok(pap)
}
#[component]
-fn Info(show: ReadSignal, set_show: WriteSignal) -> impl IntoView {
+fn Info(show: ReadSignal, set_show: WriteSignal, wp: Wallpaper) -> impl IntoView {
view! {
-
-