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

69 lines
3.1 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>,
/// 是否显示管理员授权入口
#[prop(optional)]
show_admin_access_policy: 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 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-05-20 10:43:38 +08:00
let enable_tree_live = false;
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 {
2026-05-21 23:53:39 +08:00
view! {}.into_any()
2026-04-29 14:36:24 +08:00
}}
2026-04-29 12:24:44 +08:00
</PageLayout>
}
}