mirror of
https://gitlab.com/ArkHost/HelixNotes.git
synced 2026-07-23 23:35:57 +02:00
add unfiled notes
This commit is contained in:
@@ -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>,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user