Files
mnote/rust/crates/mnote-web/src/ssr/pages/home.rs
T

73 lines
3.2 KiB
Rust
Raw Normal View History

2026-04-29 12:24:44 +08:00
//! MNOTE 首页组件(Wolai 风格)
use super::layout::PageLayout;
2026-04-29 14:36:24 +08:00
use leptos::prelude::*;
2026-04-29 12:24:44 +08:00
/// MNOTE 首页。
#[component]
pub fn HomePage(
/// 侧栏页面树 HTML(可选)
#[prop(optional)]
sidebar_tree_html: Option<String>,
/// 工作区名称(可选)
#[prop(optional)]
workspace_name: Option<String>,
2026-04-29 14:36:24 +08:00
/// 工作区 id(可选)
#[prop(optional)]
workspace_id: Option<String>,
2026-04-29 12:24:44 +08:00
/// workspace shell 侧栏 sections HTML(可选)
#[prop(optional)]
workspace_sidebar_html: Option<String>,
2026-04-29 14:36:24 +08:00
/// 当前选中的页面 id(可选)
#[prop(optional)]
active_page_id: Option<String>,
/// 当前选中的页面标题(可选)
#[prop(optional)]
active_page_title: Option<String>,
2026-04-29 12:24:44 +08:00
) -> impl IntoView {
2026-04-29 14:36:24 +08:00
let active_page_id = active_page_id.unwrap_or_default();
let active_page_title = active_page_title
.map(|value| value.trim().to_string())
.filter(|value| !value.is_empty())
.unwrap_or_else(|| "个人".to_string());
let has_active_page = !active_page_id.trim().is_empty();
let workspace_id = workspace_id
.map(|value| value.trim().to_string())
.filter(|value| !value.is_empty());
let workspace_id_value = workspace_id.clone().unwrap_or_default();
let active_href = workspace_id
.as_deref()
.map(|workspace_id| format!("/documents/{active_page_id}?workspaceId={workspace_id}"))
.unwrap_or_else(|| format!("/documents/{active_page_id}"));
2026-04-29 12:24:44 +08:00
view! {
2026-04-29 14:36:24 +08:00
<PageLayout current_nav="home" sidebar_tree_html={sidebar_tree_html.unwrap_or_default()} workspace_name={workspace_name.unwrap_or_default()} workspace_sidebar_html={workspace_sidebar_html.unwrap_or_default()} topbar_title={active_page_title.clone()}>
{move || if has_active_page {
view! {
<main class="document-shell" data-root-active-page-id={active_page_id.clone()} data-editor-host="leptos_tiptap_island">
<header class="document-shell-header">
<h1>{active_page_title.clone()}</h1>
</header>
<section class="mnote-workspace-active-state" data-testid="mnote-workspace-active-page-state">
<a class="mnote-workspace-active-link" href={active_href.clone()}>"打开当前页面"</a>
</section>
</main>
}.into_any()
} else {
view! {
<section class="mnote-workspace-empty-state" data-testid="mnote-workspace-empty-state">
<h1>"暂无页面"</h1>
<p>"当前工作区还没有可显示的页面。"</p>
<button
type="button"
class="mnote-empty-create-page"
data-testid="mnote-empty-create-page"
data-mnote-action="create-page"
data-workspace-id={workspace_id_value.clone()}
>"新建页面"</button>
</section>
}.into_any()
}}
2026-04-29 12:24:44 +08:00
</PageLayout>
}
}