修复编译器警告并改进代码质量
This commit is contained in:
parent
24b04ee638
commit
c924b1e643
@ -1,8 +1,9 @@
|
|||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
|
#[allow(unused_mut)]
|
||||||
pub fn Footer() -> Element {
|
pub fn Footer() -> Element {
|
||||||
let visible = use_signal(|| false);
|
let mut visible = use_signal(|| false);
|
||||||
|
|
||||||
use_effect(move || {
|
use_effect(move || {
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
@ -10,18 +11,26 @@ pub fn Footer() -> Element {
|
|||||||
if let Some(window) = web_sys::window() {
|
if let Some(window) = web_sys::window() {
|
||||||
let closure = wasm_bindgen::prelude::Closure::wrap(Box::new(move || {
|
let closure = wasm_bindgen::prelude::Closure::wrap(Box::new(move || {
|
||||||
if let Some(w) = web_sys::window() {
|
if let Some(w) = web_sys::window() {
|
||||||
let threshold = w.inner_height().ok()
|
let threshold = w
|
||||||
|
.inner_height()
|
||||||
|
.ok()
|
||||||
.and_then(|h| h.as_f64())
|
.and_then(|h| h.as_f64())
|
||||||
.unwrap_or(0.0);
|
.unwrap_or(0.0);
|
||||||
let scroll_y = w.scroll_y().unwrap_or(0.0);
|
let scroll_y = w.scroll_y().unwrap_or(0.0);
|
||||||
let new_visible = scroll_y > threshold;
|
let new_visible = scroll_y > threshold;
|
||||||
visible.set(new_visible);
|
visible.set(new_visible);
|
||||||
}
|
}
|
||||||
}) as Box<dyn FnMut()>);
|
})
|
||||||
|
as Box<dyn FnMut()>);
|
||||||
|
|
||||||
let _ = window.add_event_listener_with_callback("scroll", wasm_bindgen::JsCast::unchecked_ref(closure.as_ref()));
|
let _ = window.add_event_listener_with_callback(
|
||||||
|
"scroll",
|
||||||
|
wasm_bindgen::JsCast::unchecked_ref(closure.as_ref()),
|
||||||
|
);
|
||||||
|
|
||||||
let threshold = window.inner_height().ok()
|
let threshold = window
|
||||||
|
.inner_height()
|
||||||
|
.ok()
|
||||||
.and_then(|h| h.as_f64())
|
.and_then(|h| h.as_f64())
|
||||||
.unwrap_or(0.0);
|
.unwrap_or(0.0);
|
||||||
let scroll_y = window.scroll_y().unwrap_or(0.0);
|
let scroll_y = window.scroll_y().unwrap_or(0.0);
|
||||||
@ -75,9 +84,9 @@ fn scroll_to_top() {
|
|||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
{
|
{
|
||||||
if let Some(window) = web_sys::window() {
|
if let Some(window) = web_sys::window() {
|
||||||
let mut options = web_sys::ScrollToOptions::new();
|
let options = web_sys::ScrollToOptions::new();
|
||||||
options.top(0.0);
|
options.set_top(0.0);
|
||||||
options.behavior(web_sys::ScrollBehavior::Smooth);
|
options.set_behavior(web_sys::ScrollBehavior::Smooth);
|
||||||
let _ = window.scroll_to_with_scroll_to_options(&options);
|
let _ = window.scroll_to_with_scroll_to_options(&options);
|
||||||
|
|
||||||
if let Ok(history) = window.history() {
|
if let Ok(history) = window.history() {
|
||||||
|
|||||||
@ -6,9 +6,10 @@ use wasm_bindgen::JsCast;
|
|||||||
use crate::components::write_skeleton::WriteSkeleton;
|
use crate::components::write_skeleton::WriteSkeleton;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
|
#[allow(unused_mut, unused_variables)]
|
||||||
pub fn Write() -> Element {
|
pub fn Write() -> Element {
|
||||||
let mut title = use_signal(|| "".to_string());
|
let mut title = use_signal(|| "".to_string());
|
||||||
let content = use_signal(|| "".to_string());
|
let mut content = use_signal(|| "".to_string());
|
||||||
let mut loading = use_signal(|| true);
|
let mut loading = use_signal(|| true);
|
||||||
|
|
||||||
// 初始化 Tiptap 编辑器
|
// 初始化 Tiptap 编辑器
|
||||||
@ -105,11 +106,6 @@ pub fn Write() -> Element {
|
|||||||
})()
|
})()
|
||||||
"#).ok().and_then(|v| v.as_string()).unwrap_or_default();
|
"#).ok().and_then(|v| v.as_string()).unwrap_or_default();
|
||||||
content.set(md.clone());
|
content.set(md.clone());
|
||||||
println!("保存文章: title={}, content_len={}", title(), md.len());
|
|
||||||
}
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
{
|
|
||||||
println!("保存文章: title={}, content_len={}", title(), content().len());
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"保存草稿"
|
"保存草稿"
|
||||||
|
|||||||
@ -14,11 +14,11 @@ pub async fn run_cleanup() {
|
|||||||
.execute("DELETE FROM sessions WHERE expires_at < NOW()", &[])
|
.execute("DELETE FROM sessions WHERE expires_at < NOW()", &[])
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
eprintln!("Session cleanup error: {}", e);
|
tracing::error!("Session cleanup error: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Failed to get DB connection for cleanup: {}", e);
|
tracing::error!("Failed to get DB connection for cleanup: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user