Skip to content

Commit

Permalink
fix: sidebar animation
Browse files Browse the repository at this point in the history
  • Loading branch information
DefectingCat committed Dec 26, 2024
1 parent d9bb561 commit 55f8147
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
1 change: 1 addition & 0 deletions venus-core/src/config/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ impl NodeType {
}

/// Core config root
/// https://www.v2fly.org/config/overview.html
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CoreConfig {
Expand Down
45 changes: 26 additions & 19 deletions venus-ui/src/components/sidebar.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::time::Duration;

use leptos::prelude::*;
use leptos_router::hooks::use_location;

Expand Down Expand Up @@ -51,28 +49,39 @@ fn SidebarContent(is_mobile: bool) -> impl IntoView {
let ui = use_global_ui();

let children = move |n: Navi| {
let ui = use_global_ui();
let opened = Memo::new(move |_| {
if is_mobile {
true
} else {
ui.sidebar_open.get()
}
});

view! {
<li class="mb-2">
<a href=n.path class="transition-all duration-300">
<a
href=n.path
class="transition-all duration-300"
class=("flex", move || is_mobile)
>
<button
class="btn btn-ghost overflow-hidden sm:w-full duration-300"
class=("btn-active", move || n.path == location.pathname.get())
class=("w-full", move || is_mobile)
>
<div
class="flex items-center justify-start"
class=("w-4/6", move || ui.sidebar_open.get())
class=("w-4", move || !ui.sidebar_open.get())
class=("w-4/6", move || opened.get())
class=("w-4", move || !opened.get())
>
<span
class=format!("{} min-w-[1rem] w-4 h-4", n.icon)
class=("mr-1", move || ui.sidebar_open.get())
class=("mr-1", move || opened.get())
></span>
<span
class="transition-all duration-300 overflow-hidden text-left leading-tight"
class=("w-5/6", move || ui.sidebar_open.get())
class=("w-0", move || !ui.sidebar_open.get())
class=("w-5/6", move || opened.get())
class=("w-0", move || !opened.get())
>
{n.name}
</span>
Expand All @@ -95,21 +104,19 @@ fn SidebarContent(is_mobile: bool) -> impl IntoView {
</div>

// nav
<div class="flex flex-col justify-between h-full felx-1">
<div class="flex flex-col my-4">
<div class="flex flex-col justify-between h-full felx-1 items-center">
<div class="flex flex-col my-4 w-full">
<ul class="my-4 bg-transparent rounded-box">
<For each=move || NAVI key=|n| n.path children=children />
</ul>
</div>

// toggle sidebar button
<div>
<span
class="icon-[solar--square-double-alt-arrow-left-bold-duotone] transition-all duration-300 hidden sm:block w-7 h-7"
class=("rotate-180", move || ui.sidebar_open.get())
on:click=move |_| ui.sidebar_open.set(!ui.sidebar_open.get())
></span>
</div>
<span
class="icon-[solar--square-double-alt-arrow-left-bold-duotone] transition-all duration-300 hidden sm:block w-7 h-7 cursor-pointer"
class=("rotate-180", move || ui.sidebar_open.get())
on:click=move |_| ui.sidebar_open.set(!ui.sidebar_open.get())
></span>
</div>
</>
}
Expand Down Expand Up @@ -154,7 +161,7 @@ pub fn SidebarMobile() -> impl IntoView {
aria-label="close sidebar"
class="drawer-overlay"
></label>
<ul class="menu bg-base-200 text-base-content min-h-full w-72 p-4">
<ul class="bg-base-200 text-base-content min-h-full w-72 p-4">
<SidebarContent is_mobile=true />
</ul>
</div>
Expand Down
4 changes: 1 addition & 3 deletions venus-ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use components::notifications::Notifications;
use consts::COLOR_MODE;
use gloo::storage::{LocalStorage, Storage};
use layout::Layout;
use leptos::{logging, prelude::*};
use leptos::prelude::*;
use leptos_meta::*;
use leptos_router::{components::*, path};
use leptos_use::{use_color_mode_with_options, UseColorModeOptions, UseColorModeReturn};
Expand Down Expand Up @@ -66,7 +66,6 @@ pub struct User {
impl User {
pub fn new() -> Self {
let user = LocalStorage::get::<User>("rua-user").unwrap_or_default();
logging::log!("user {:?}", user);
Self { ..user }
}
}
Expand Down Expand Up @@ -109,7 +108,6 @@ pub fn App() -> impl IntoView {
// ui 的全局状态
let global_ui = GlobalUI::new();
provide_context(global_ui);
logging::log!("token {:?}", global_ui.user.read().token.is_empty());

// Provides context that manages stylesheets, titles, meta tags, etc.
provide_meta_context();
Expand Down
1 change: 0 additions & 1 deletion venus-ui/src/pages/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ pub fn Login() -> impl IntoView {
match result {
Ok(response) => {
if let Some(data) = &response.data {
logging::log!("login response {:?}", data.access_token);
nts.update(|nts| {
nts.push(Notification::new(
NotificationKind::Success,
Expand Down

0 comments on commit 55f8147

Please sign in to comment.