search bar
This commit is contained in:
42
src/app.rs
42
src/app.rs
@@ -44,6 +44,7 @@ pub enum AppState {
|
||||
Login,
|
||||
Main,
|
||||
Editor,
|
||||
Search,
|
||||
}
|
||||
|
||||
// ─── Login form ───────────────────────────────────────────────────────────────
|
||||
@@ -172,6 +173,43 @@ impl EditorView {
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Search view ─────────────────────────────────────────────────────────────
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct SearchResultSpace {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct SearchResult {
|
||||
pub id: String,
|
||||
pub title: Option<String>,
|
||||
pub highlight: Option<String>,
|
||||
pub space: Option<SearchResultSpace>,
|
||||
}
|
||||
|
||||
pub struct SearchView {
|
||||
pub query: String,
|
||||
pub results: Vec<SearchResult>,
|
||||
pub selected: usize,
|
||||
pub loading: bool,
|
||||
pub error: Option<String>,
|
||||
pub opening_page: bool,
|
||||
}
|
||||
|
||||
impl SearchView {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
query: String::new(),
|
||||
results: vec![],
|
||||
selected: 0,
|
||||
loading: false,
|
||||
error: None,
|
||||
opening_page: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Root app ─────────────────────────────────────────────────────────────────
|
||||
|
||||
pub struct App {
|
||||
@@ -179,6 +217,7 @@ pub struct App {
|
||||
pub login: LoginForm,
|
||||
pub main: MainView,
|
||||
pub editor: EditorView,
|
||||
pub search: SearchView,
|
||||
pub base_url: String,
|
||||
pub token: String,
|
||||
}
|
||||
@@ -190,6 +229,7 @@ impl App {
|
||||
login: LoginForm::new(),
|
||||
main: MainView::new(),
|
||||
editor: EditorView::new(String::new(), String::new()),
|
||||
search: SearchView::new(),
|
||||
base_url: String::new(),
|
||||
token: String::new(),
|
||||
}
|
||||
@@ -206,6 +246,8 @@ pub enum AppMsg {
|
||||
PageContentLoaded { page_id: String, title: String, content: String },
|
||||
PageSaved,
|
||||
SaveError(String),
|
||||
SearchResults(Vec<SearchResult>),
|
||||
SearchError(String),
|
||||
ApiError(String),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user