adding files to database works

This commit is contained in:
Iaphetes 2025-03-16 19:04:14 +01:00
parent dcfb500a5f
commit 852ab87b0b
4 changed files with 154 additions and 52 deletions

View file

@ -1,4 +1,5 @@
use crate::get_basepath;
use crate::{database::add_file, get_basepath};
use futures::future::{BoxFuture, FutureExt};
use html_tag::HtmlTag;
use shellexpand;
use std::{
@ -6,14 +7,20 @@ use std::{
path::Path,
};
#[tauri::command]
pub fn dir_tree_html(app_handle: tauri::AppHandle, filter: Vec<String>) -> String {
if let Some(basepath) = get_basepath(app_handle) {
add_dir_tree_node(&Path::new(&basepath), &filter).to_html()
pub async fn dir_tree_html(app_handle: tauri::AppHandle, filter: Vec<String>) -> String {
if let Some(basepath) = get_basepath(app_handle.clone()) {
add_dir_tree_node(&app_handle, &Path::new(&basepath), &filter)
.await
.to_html()
} else {
String::new()
}
}
fn add_dir_tree_node(path: &Path, filter: &Vec<String>) -> HtmlTag {
async fn add_dir_tree_node(
app_handle: &tauri::AppHandle,
path: &Path,
filter: &Vec<String>,
) -> HtmlTag {
let mut html = HtmlTag::new("div")
.with_class("filetree-node")
.with_id(&format!(
@ -46,10 +53,17 @@ fn add_dir_tree_node(path: &Path, filter: &Vec<String>) -> HtmlTag {
if let Ok(dir_entry) = dir_entry_res {
if let Ok(metadata) = fs::metadata(dir_entry.path()) {
if metadata.is_file() {
add_file(
app_handle,
path.to_string_lossy().as_ref(),
dir_entry.file_name().to_string_lossy().as_ref(),
)
.await;
html.add_child(div_from_dir_entry(&dir_entry))
} else if metadata.is_dir() {
html.add_child(
add_dir_tree_node(&dir_entry.path(), &filter)
Box::pin(add_dir_tree_node(app_handle, &dir_entry.path(), &filter))
.await
.with_attribute("style", "visibility: hidden; height: 0px;"), // .with_style("visibility", "hidden")
// .with_style("height", "0px"),
);