add unfiled notes

This commit is contained in:
Yuri Karamian
2026-03-17 21:45:51 +01:00
parent 79f16b454a
commit 9f595212dd
6 changed files with 65 additions and 4 deletions
+7
View File
@@ -112,6 +112,13 @@ pub fn get_notebooks(state: State<'_, AppState>) -> Result<Vec<NotebookEntry>, S
operations::scan_notebooks(vault_path)
}
#[tauri::command]
pub fn count_root_notes(state: State<'_, AppState>) -> Result<usize, String> {
let config = state.config.lock().map_err(|e| e.to_string())?;
let vault_path = config.active_vault.as_ref().ok_or("No active vault")?;
operations::count_root_notes(vault_path)
}
#[tauri::command]
pub fn create_notebook(
state: State<'_, AppState>,
+1
View File
@@ -98,6 +98,7 @@ pub fn run() {
commands::set_font_family,
commands::set_line_height,
commands::get_notebooks,
commands::count_root_notes,
commands::create_notebook,
commands::rename_notebook,
commands::delete_notebook,
+16
View File
@@ -167,6 +167,22 @@ fn is_hidden(path: &Path) -> bool {
.unwrap_or(false)
}
pub fn count_root_notes(vault_path: &str) -> Result<usize, String> {
let root = Path::new(vault_path);
if !root.exists() {
return Err("Vault path does not exist".to_string());
}
let count = fs::read_dir(root)
.map_err(|e| e.to_string())?
.filter_map(|e| e.ok())
.filter(|e| {
e.file_type().map(|ft| ft.is_file()).unwrap_or(false)
&& e.path().extension().and_then(|x| x.to_str()) == Some("md")
})
.count();
Ok(count)
}
pub fn scan_notes(vault_path: &str, notebook_path: Option<&str>) -> Result<Vec<NoteEntry>, String> {
let scan_path = notebook_path.unwrap_or(vault_path);
let root = Path::new(scan_path);