From 67d0bd5cd04b3cb53499bc4003d1ac813d098f2c Mon Sep 17 00:00:00 2001 From: chenhang Date: Wed, 17 Jun 2026 17:27:18 +0800 Subject: [PATCH] refactor(hooks): remove unused PWA install and visibility hooks refactor(package): remove deprecated dev:proxy script fix(user): ensure user-auth-sync is exported in index --- package.json | 1 - src/hooks/index.ts | 2 -- src/hooks/use-pwa-install.ts | 47 ------------------------------------ src/hooks/use-visibility.ts | 42 -------------------------------- src/stores/user/index.ts | 1 + 5 files changed, 1 insertion(+), 92 deletions(-) delete mode 100644 src/hooks/use-pwa-install.ts delete mode 100644 src/hooks/use-visibility.ts diff --git a/package.json b/package.json index 78ebce55..4f1ff118 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,6 @@ "private": true, "scripts": { "dev": "next dev", - "dev:proxy": "HTTPS_PROXY=http://127.0.0.1:7891 next dev", "build": "next build", "start": "next start -p 9135", "build:start": "npm run build && npm run start", diff --git a/src/hooks/index.ts b/src/hooks/index.ts index b370edd8..4b61d1d6 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -4,5 +4,3 @@ export * from "./use-breakpoint"; export * from "./use-pull-to-refresh"; -export * from "./use-pwa-install"; -export * from "./use-visibility"; diff --git a/src/hooks/use-pwa-install.ts b/src/hooks/use-pwa-install.ts deleted file mode 100644 index e2a7f032..00000000 --- a/src/hooks/use-pwa-install.ts +++ /dev/null @@ -1,47 +0,0 @@ -"use client"; -/** - * PWA Install 提示 hook - * - * 原始 Dart: `pwa_install` 包的 BeforeInstallPrompt 事件封装 - * (`lib/ui/chat/widgets/pwa_install_overlay.dart` + `pwa_install_dialog.dart`)。 - * - * 浏览器 API:`beforeinstallprompt` 事件 → 用户触发 → 浏览器展示原生安装提示。 - * - * 用法: - * const { canInstall, promptInstall } = usePwaInstall(); - * if (canInstall) ; - */ -import { useEffect, useState } from "react"; - -interface BeforeInstallPromptEvent extends Event { - prompt(): Promise; - userChoice: Promise<{ outcome: "accepted" | "dismissed" }>; -} - -export function usePwaInstall(): { - canInstall: boolean; - promptInstall: () => Promise<"accepted" | "dismissed" | "unavailable">; -} { - const [deferred, setDeferred] = useState(null); - - useEffect(() => { - if (typeof window === "undefined") return; - const handler = (e: Event) => { - e.preventDefault(); - setDeferred(e as BeforeInstallPromptEvent); - }; - window.addEventListener("beforeinstallprompt", handler); - return () => window.removeEventListener("beforeinstallprompt", handler); - }, []); - - return { - canInstall: deferred !== null, - promptInstall: async () => { - if (!deferred) return "unavailable"; - await deferred.prompt(); - const choice = await deferred.userChoice; - setDeferred(null); - return choice.outcome; - }, - }; -} diff --git a/src/hooks/use-visibility.ts b/src/hooks/use-visibility.ts deleted file mode 100644 index 29d2b3cb..00000000 --- a/src/hooks/use-visibility.ts +++ /dev/null @@ -1,42 +0,0 @@ -"use client"; -/** - * 元素全可见性 hook - * - * 原始 Dart: `visibility_detector` 包的 `VisibilityDetector`(chat_screen 用法: - * onVisibilityChanged: (info) { if (info.visibleFraction == 1.0) ... })。 - * - * 用 IntersectionObserver,threshold=1.0 触发 `isIntersecting` 即视为「完全可见」。 - * 返回 `[isVisible, ref]`,与 Flutter `VisibilityDetector` 的语义对齐。 - * - * 用法: - * const [isVisible, ref] = useFullVisibility(); - * useEffect(() => { dispatch(isVisible ? Visible() : Invisible()); }, [isVisible]); - */ -import { useEffect, useRef, useState } from "react"; - -export function useFullVisibility( - threshold = 1.0, -): readonly [boolean, React.RefObject] { - const ref = useRef(null); - const [visible, setVisible] = useState(false); - - useEffect(() => { - const el = ref.current; - if (!el || typeof IntersectionObserver === "undefined") return; - - const observer = new IntersectionObserver( - (entries) => { - const entry = entries[0]; - if (!entry) return; - setVisible( - entry.isIntersecting && entry.intersectionRatio >= threshold, - ); - }, - { threshold: [threshold] }, - ); - observer.observe(el); - return () => observer.disconnect(); - }, [threshold]); - - return [visible, ref] as const; -} diff --git a/src/stores/user/index.ts b/src/stores/user/index.ts index b6c636b5..d4a710ac 100644 --- a/src/stores/user/index.ts +++ b/src/stores/user/index.ts @@ -2,6 +2,7 @@ * @file Automatically generated by barrelsby. */ +export * from "./user-auth-sync"; export * from "./user-context"; export * from "./user-events"; export * from "./user-machine.actors";