From 287affa34a187bf545789326eca4e69bf750d70e Mon Sep 17 00:00:00 2001 From: chenhang Date: Wed, 17 Jun 2026 14:13:42 +0800 Subject: [PATCH] refactor(app): move route screens out of components Exclude test and spec files from generated barrels so page imports do not load test modules at runtime. --- barrelsby.json | 7 +++++++ src/app/auth/{components => }/auth-screen.tsx | 8 +++---- src/app/auth/components/index.ts | 2 -- src/app/auth/page.tsx | 2 +- src/app/chat/{components => }/chat-screen.tsx | 18 +++++++++------- src/app/chat/components/index.ts | 1 - src/app/chat/page.tsx | 2 +- src/app/sidebar/components/index.ts | 1 - src/app/sidebar/page.tsx | 2 +- .../{components => }/sidebar-screen.tsx | 16 +++++++------- src/app/splash/components/index.ts | 1 - src/app/splash/page.tsx | 2 +- .../splash/{components => }/splash-screen.tsx | 14 +++++++------ src/app/subscription/components/index.ts | 1 - src/app/subscription/page.tsx | 2 +- .../{components => }/subscription-screen.tsx | 21 ++++++++++--------- 16 files changed, 53 insertions(+), 47 deletions(-) rename src/app/auth/{components => }/auth-screen.tsx (88%) rename src/app/chat/{components => }/chat-screen.tsx (93%) rename src/app/sidebar/{components => }/sidebar-screen.tsx (88%) rename src/app/splash/{components => }/splash-screen.tsx (94%) rename src/app/subscription/{components => }/subscription-screen.tsx (85%) diff --git a/barrelsby.json b/barrelsby.json index 5dc810c9..488172d2 100644 --- a/barrelsby.json +++ b/barrelsby.json @@ -1,4 +1,11 @@ { + "exclude": [ + "__tests__", + "\\.test\\.ts$", + "\\.test\\.tsx$", + "\\.spec\\.ts$", + "\\.spec\\.tsx$" + ], "directory": [ "./src/data/repositories", "./src/data/repositories/interfaces", diff --git a/src/app/auth/components/auth-screen.tsx b/src/app/auth/auth-screen.tsx similarity index 88% rename from src/app/auth/components/auth-screen.tsx rename to src/app/auth/auth-screen.tsx index 7ae6cdaf..f7620d1a 100644 --- a/src/app/auth/components/auth-screen.tsx +++ b/src/app/auth/auth-screen.tsx @@ -7,15 +7,13 @@ import { useEffect } from "react"; import { useRouter } from "next/navigation"; -import { MobileShell } from "@/app/_components/core/mobile-shell"; - +import { MobileShell } from "@/app/_components/core"; import { useAuthDispatch, useAuthState } from "@/stores/auth/auth-context"; import { useUserDispatch } from "@/stores/user/user-context"; import { ROUTES } from "@/router/routes"; -import styles from "./auth-screen.module.css"; -import { AuthBackground } from "./auth-background"; -import { AuthPanel } from "./auth-panel"; +import { AuthBackground, AuthPanel } from "./components"; +import styles from "./components/auth-screen.module.css"; export function AuthScreen() { const state = useAuthState(); diff --git a/src/app/auth/components/index.ts b/src/app/auth/components/index.ts index a041e698..275030b7 100644 --- a/src/app/auth/components/index.ts +++ b/src/app/auth/components/index.ts @@ -11,11 +11,9 @@ export * from "./auth-legal-text"; export * from "./auth-other-options-dialog"; export * from "./auth-panel"; export * from "./auth-primary-button"; -export * from "./auth-screen"; export * from "./auth-social-button"; export * from "./auth-social-buttons"; export * from "./auth-text-field"; export * from "./auth-validators"; export * from "./email-login-form"; export * from "./email-register-form"; -export * from "./__tests__/auth-validators.test"; diff --git a/src/app/auth/page.tsx b/src/app/auth/page.tsx index 58603a6e..a81af6ec 100644 --- a/src/app/auth/page.tsx +++ b/src/app/auth/page.tsx @@ -1,6 +1,6 @@ "use client"; -import { AuthScreen } from "@/app/auth/components/auth-screen"; +import { AuthScreen } from "@/app/auth/auth-screen"; export default function AuthPage() { return ; diff --git a/src/app/chat/components/chat-screen.tsx b/src/app/chat/chat-screen.tsx similarity index 93% rename from src/app/chat/components/chat-screen.tsx rename to src/app/chat/chat-screen.tsx index c2103c1a..eb3f0d8f 100644 --- a/src/app/chat/components/chat-screen.tsx +++ b/src/app/chat/chat-screen.tsx @@ -30,15 +30,17 @@ import type { LoginStatus } from "@/models/auth/login-status"; import { AuthStorage } from "@/data/storage/auth/auth_storage"; import { useChatDispatch, useChatState } from "@/stores/chat/chat-context"; -import { MobileShell } from "@/app/_components/core/mobile-shell"; +import { MobileShell } from "@/app/_components/core"; -import { BrowserHintOverlay } from "./browser-hint-overlay"; -import { ChatArea } from "./chat-area"; -import { ChatHeader } from "./chat-header"; -import { ChatInputBar } from "./chat-input-bar"; -import { ChatQuotaExhaustedBanner } from "./chat-quota-exhausted-banner"; -import { PwaInstallOverlay } from "./pwa-install-overlay"; -import styles from "./chat-screen.module.css"; +import { + BrowserHintOverlay, + ChatArea, + ChatHeader, + ChatInputBar, + ChatQuotaExhaustedBanner, + PwaInstallOverlay, +} from "./components"; +import styles from "./components/chat-screen.module.css"; /** diff --git a/src/app/chat/components/index.ts b/src/app/chat/components/index.ts index e11b2589..e5aaf4e6 100644 --- a/src/app/chat/components/index.ts +++ b/src/app/chat/components/index.ts @@ -9,7 +9,6 @@ export * from "./chat-header"; export * from "./chat-input-bar"; export * from "./chat-input-text-field"; export * from "./chat-quota-exhausted-banner"; -export * from "./chat-screen"; export * from "./chat-send-button"; export * from "./date-header"; export * from "./fullscreen-image-viewer"; diff --git a/src/app/chat/page.tsx b/src/app/chat/page.tsx index 88b704c5..01ac20cb 100644 --- a/src/app/chat/page.tsx +++ b/src/app/chat/page.tsx @@ -1,6 +1,6 @@ "use client"; -import { ChatScreen } from "@/app/chat/components/chat-screen"; +import { ChatScreen } from "@/app/chat/chat-screen"; export default function ChatPage() { return ; diff --git a/src/app/sidebar/components/index.ts b/src/app/sidebar/components/index.ts index e5291cc1..dbd0da47 100644 --- a/src/app/sidebar/components/index.ts +++ b/src/app/sidebar/components/index.ts @@ -3,7 +3,6 @@ */ export * from "./back-bar"; -export * from "./sidebar-screen"; export * from "./user-header"; export * from "./vip-benefits-card"; export * from "./voice-package-card"; diff --git a/src/app/sidebar/page.tsx b/src/app/sidebar/page.tsx index bf208d65..7ad4f0f6 100644 --- a/src/app/sidebar/page.tsx +++ b/src/app/sidebar/page.tsx @@ -1,6 +1,6 @@ "use client"; -import { SidebarScreen } from "@/app/sidebar/components/sidebar-screen"; +import { SidebarScreen } from "@/app/sidebar/sidebar-screen"; export default function SidebarPage() { return ; diff --git a/src/app/sidebar/components/sidebar-screen.tsx b/src/app/sidebar/sidebar-screen.tsx similarity index 88% rename from src/app/sidebar/components/sidebar-screen.tsx rename to src/app/sidebar/sidebar-screen.tsx index d47a97be..4b552507 100644 --- a/src/app/sidebar/components/sidebar-screen.tsx +++ b/src/app/sidebar/sidebar-screen.tsx @@ -3,18 +3,20 @@ import { useEffect } from "react"; import { useRouter } from "next/navigation"; -import { MobileShell } from "@/app/_components/core/mobile-shell"; -import { SettingsSection } from "@/app/_components/core/settings-section"; +import { MobileShell, SettingsSection } from "@/app/_components/core"; import { ROUTES } from "@/router/routes"; import { useAuthDispatch, useAuthState } from "@/stores/auth/auth-context"; import { useUserDispatch, useUserState } from "@/stores/user/user-context"; -import { BackBar } from "./back-bar"; -import { UserHeader, type SidebarUserState } from "./user-header"; -import { VipBenefitsCard } from "./vip-benefits-card"; -import { VoicePackageCard } from "./voice-package-card"; +import { + BackBar, + UserHeader, + type SidebarUserState, + VipBenefitsCard, + VoicePackageCard, +} from "./components"; -import styles from "./sidebar-screen.module.css"; +import styles from "./components/sidebar-screen.module.css"; const FALLBACK_USERNAME = "User name"; diff --git a/src/app/splash/components/index.ts b/src/app/splash/components/index.ts index f371dc28..3f2d2dff 100644 --- a/src/app/splash/components/index.ts +++ b/src/app/splash/components/index.ts @@ -8,4 +8,3 @@ export * from "./splash-content"; export * from "./splash-loading"; export * from "./splash-logo"; export * from "./splash-progress"; -export * from "./splash-screen"; diff --git a/src/app/splash/page.tsx b/src/app/splash/page.tsx index 38311546..90fdc60f 100644 --- a/src/app/splash/page.tsx +++ b/src/app/splash/page.tsx @@ -1,4 +1,4 @@ -import { SplashScreen } from "@/app/splash/components/splash-screen"; +import { SplashScreen } from "@/app/splash/splash-screen"; export default function SplashPage() { return ; diff --git a/src/app/splash/components/splash-screen.tsx b/src/app/splash/splash-screen.tsx similarity index 94% rename from src/app/splash/components/splash-screen.tsx rename to src/app/splash/splash-screen.tsx index d11edd9f..ac19cd2b 100644 --- a/src/app/splash/components/splash-screen.tsx +++ b/src/app/splash/splash-screen.tsx @@ -3,18 +3,20 @@ import { useEffect } from "react"; import { useRouter } from "next/navigation"; -import { MobileShell } from "@/app/_components/core/mobile-shell"; +import { MobileShell } from "@/app/_components/core"; import { useAuthDispatch, useAuthState } from "@/stores/auth/auth-context"; import { useUserDispatch } from "@/stores/user/user-context"; import { AuthStorage } from "@/data/storage/auth/auth_storage"; import { ROUTES } from "@/router/routes"; import { pwaUtil } from "@/utils/pwa"; -import { SplashBackground } from "./splash-background"; -import { SplashLogo } from "./splash-logo"; -import { SplashContent } from "./splash-content"; -import { SplashButton } from "./splash-button"; -import styles from "./splash-screen.module.css"; +import { + SplashBackground, + SplashButton, + SplashContent, + SplashLogo, +} from "./components"; +import styles from "./components/splash-screen.module.css"; // 尽量早地缓存 beforeinstallprompt,避免用户停留 splash 时浏览器事件已触发并丢失。 if (typeof window !== "undefined") { diff --git a/src/app/subscription/components/index.ts b/src/app/subscription/components/index.ts index cc0d758f..35e8d6c3 100644 --- a/src/app/subscription/components/index.ts +++ b/src/app/subscription/components/index.ts @@ -9,5 +9,4 @@ export * from "./subscription-checkout-button"; export * from "./subscription-cta-button"; export * from "./subscription-manage-button"; export * from "./subscription-plan-card"; -export * from "./subscription-screen"; export * from "./subscription-user-row"; diff --git a/src/app/subscription/page.tsx b/src/app/subscription/page.tsx index e600f7d5..f7a79541 100644 --- a/src/app/subscription/page.tsx +++ b/src/app/subscription/page.tsx @@ -1,6 +1,6 @@ "use client"; -import { SubscriptionScreen } from "@/app/subscription/components/subscription-screen"; +import { SubscriptionScreen } from "@/app/subscription/subscription-screen"; export default function SubscriptionPage() { return ; diff --git a/src/app/subscription/components/subscription-screen.tsx b/src/app/subscription/subscription-screen.tsx similarity index 85% rename from src/app/subscription/components/subscription-screen.tsx rename to src/app/subscription/subscription-screen.tsx index 1c81b9cd..e195d03e 100644 --- a/src/app/subscription/components/subscription-screen.tsx +++ b/src/app/subscription/subscription-screen.tsx @@ -16,8 +16,7 @@ */ import { useState } from "react"; -import { Checkbox } from "@/app/_components/core/checkbox"; -import { MobileShell } from "@/app/_components/core/mobile-shell"; +import { Checkbox, MobileShell } from "@/app/_components/core"; import { AppConstants } from "@/core/app_constants"; import { SUBSCRIPTION_PLANS, @@ -26,14 +25,16 @@ import { import { VIP_BENEFITS } from "@/data/constants/vip-benefits"; import { useUserState } from "@/stores/user/user-context"; -import { SubscriptionBackLink } from "./subscription-back-link"; -import { SubscriptionBanner } from "./subscription-banner"; -import { SubscriptionBenefitsCard } from "./subscription-benefits-card"; -import { SubscriptionCheckoutButton } from "./subscription-checkout-button"; -import { SubscriptionManageButton } from "./subscription-manage-button"; -import { SubscriptionPlanCard } from "./subscription-plan-card"; -import { SubscriptionUserRow } from "./subscription-user-row"; -import styles from "./subscription-screen.module.css"; +import { + SubscriptionBackLink, + SubscriptionBanner, + SubscriptionBenefitsCard, + SubscriptionCheckoutButton, + SubscriptionManageButton, + SubscriptionPlanCard, + SubscriptionUserRow, +} from "./components"; +import styles from "./components/subscription-screen.module.css"; const FALLBACK_USERNAME = "User name";