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

186 lines
9.7 KiB
Rust
Raw Normal View History

2026-04-29 12:24:44 +08:00
//! MNOTE 首页组件(Wolai 风格)
2026-05-26 16:24:00 +08:00
use super::{
document::{DocumentPane, DocumentPaneViewModel},
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>,
/// 导航页主体 HTML(可选)
#[prop(optional)]
navigation_html: String,
/// 是否显示管理员授权入口
#[prop(optional)]
show_admin_access_policy: bool,
2026-05-29 11:13:05 +08:00
/// 是否启用树实时流
#[prop(optional, default = true)]
enable_tree_live: bool,
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 navigation_html = Some(navigation_html)
.map(|value| value.trim().to_string())
.filter(|value| !value.is_empty());
2026-04-29 14:36:24 +08:00
let workspace_id = workspace_id
.map(|value| value.trim().to_string())
.filter(|value| !value.is_empty());
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-05-20 10:43:38 +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()} show_admin_access_policy={show_admin_access_policy} enable_tree_live={enable_tree_live}>
2026-04-29 14:36:24 +08:00
{move || if has_active_page {
view! {
2026-04-29 16:23:49 +08:00
<main class="document-shell document-shell--workspace-entry" data-root-active-page-id={active_page_id.clone()} data-editor-host="leptos_tiptap_island">
2026-04-29 14:36:24 +08:00
<header class="document-shell-header">
2026-04-29 16:23:49 +08:00
<div class="document-page-icon" aria-hidden="true">"⌂"</div>
2026-04-29 14:36:24 +08:00
<h1>{active_page_title.clone()}</h1>
2026-04-29 16:23:49 +08:00
<div class="document-shell-meta" aria-label="页面元信息">
<span><span aria-hidden="true">"◌"</span>"个人空间"</span>
<span><span aria-hidden="true">"▣"</span>"工作区首页"</span>
</div>
2026-04-29 14:36:24 +08:00
</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 if let Some(navigation_html) = navigation_html.clone() {
view! {
<main
class="document-workspace mnote-navigation-page-workspace"
data-testid="mnote-document-workspace"
data-has-secondary-pane="false"
data-workspace-id={workspace_id.clone().unwrap_or_default()}
>
<section class="document-main-editor-group" data-testid="mnote-main-editor-tab-host" data-pane-role="primary">
<div class="mnote-main-tab-strip" data-mnote-main-tab-strip="true" data-pane-role="primary" role="tablist" aria-label="主编辑区标签页">
<button
type="button"
class="mnote-main-tab is-active"
data-mnote-main-tab="page"
data-mnote-tab-kind="page"
data-pane-role="primary"
data-workspace-id={workspace_id.clone().unwrap_or_default()}
role="tab"
aria-selected="true"
tabindex="0"
>
<span class="mnote-main-tab-badge" aria-hidden="true"></span>
<span class="mnote-main-tab-title">"主页"</span>
</button>
</div>
<div class="mnote-main-tab-panels">
<div
data-mnote-page-tab-panel="true"
data-pane-role="primary"
>
<div
class="mnote-navigation-page-host"
data-mnote-navigation-page-placeholder="true"
data-pane-role="primary"
>
<div inner_html={navigation_html}></div>
</div>
</div>
<section
class="mnote-resource-tab-host"
data-mnote-resource-tab-host="true"
data-pane-role="primary"
data-testid="mnote-resource-tab-host"
hidden=true
>
<div class="mnote-resource-tab-panel-root" data-mnote-resource-tab-panel-root="true" data-pane-role="primary"></div>
</section>
</div>
</section>
</main>
}.into_any()
2026-04-29 14:36:24 +08:00
} else {
2026-05-26 16:24:00 +08:00
let empty_primary_model = DocumentPaneViewModel {
pane_role: "primary",
title: "文件夹".to_string(),
document_id: String::new(),
workspace_id: workspace_id.clone().unwrap_or_default(),
page_wide_layout: false,
page_small_text: false,
page_layout_density: "normal".to_string(),
page_font: "default".to_string(),
page_show_heading_numbers: false,
has_page_subtree: false,
primary_legacy_ids: true,
visible: true,
hide_title_header: true,
};
2026-05-24 01:49:51 +08:00
view! {
<main
class="document-workspace mnote-workspace-empty-editor-host"
data-testid="mnote-document-workspace"
data-has-secondary-pane="false"
data-workspace-id={workspace_id.clone().unwrap_or_default()}
>
<section class="document-main-editor-group" data-testid="mnote-main-editor-tab-host" data-pane-role="primary">
<div class="mnote-main-tab-strip" data-mnote-main-tab-strip="true" data-pane-role="primary" role="tablist" aria-label="主编辑区标签页">
<button
type="button"
class="mnote-main-tab is-active"
data-mnote-main-tab="page"
data-mnote-tab-kind="page"
data-pane-role="primary"
data-workspace-id={workspace_id.clone().unwrap_or_default()}
role="tab"
aria-selected="true"
tabindex="0"
>
<span class="mnote-main-tab-badge" aria-hidden="true"></span>
<span class="mnote-main-tab-title">"文件夹"</span>
</button>
</div>
<div class="mnote-main-tab-panels">
<div data-mnote-page-tab-panel="true" data-pane-role="primary">
2026-05-26 16:24:00 +08:00
<DocumentPane model={empty_primary_model} />
2026-05-24 01:49:51 +08:00
</div>
<section
class="mnote-resource-tab-host"
data-mnote-resource-tab-host="true"
data-pane-role="primary"
data-testid="mnote-resource-tab-host"
hidden=true
>
<div class="mnote-resource-tab-panel-root" data-mnote-resource-tab-panel-root="true" data-pane-role="primary"></div>
</section>
</div>
</section>
</main>
}.into_any()
2026-04-29 14:36:24 +08:00
}}
2026-04-29 12:24:44 +08:00
</PageLayout>
}
}