diff --git a/app/(dashboard)/dashboard/page.tsx b/app/(dashboard)/dashboard/page.tsx index 270c100..f2a9fdc 100644 --- a/app/(dashboard)/dashboard/page.tsx +++ b/app/(dashboard)/dashboard/page.tsx @@ -5,7 +5,7 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { EmptyState } from "@/components/ui/empty-state" import { Progress } from "@/components/ui/progress" import { StatusBadge, type StatusBadgeProps } from "@/components/ui/status-badge" -import { listOrders, listPlayers, listServices, listShops } from "@/lib/api" +import { getShopIncomeStats, listOrders, listPlayers, listServices, listShops } from "@/lib/api" import { statusLabels } from "@/lib/constants" import type { Player, PlayerService, Shop } from "@/lib/types" import { useAuthStore } from "@/store/auth" @@ -40,6 +40,7 @@ export default function DashboardPage() { const [shop, setShop] = useState(null) const [services, setServices] = useState([]) const [orders, setOrders] = useState>>([]) + const [monthlyIncome, setMonthlyIncome] = useState("0") const recentOrders = orders.slice(0, 3) useEffect(() => { @@ -88,6 +89,29 @@ export default function DashboardPage() { } }, [orderRole]) + useEffect(() => { + if (!shop) { + setMonthlyIncome("0") + return + } + + let cancelled = false + + getShopIncomeStats(shop.id) + .then((stats) => { + if (cancelled) return + setMonthlyIncome(stats.monthlyIncome) + }) + .catch(() => { + if (cancelled) return + setMonthlyIncome("0") + }) + + return () => { + cancelled = true + } + }, [shop]) + const totalOrders = isOwner ? (shop?.totalOrders ?? 0) : (player?.totalOrders ?? 0) const rating = isOwner ? (shop?.rating ?? 0) : (player?.rating ?? 0) const playerCount = shop?.playerCount ?? 0 @@ -149,7 +173,7 @@ export default function DashboardPage() { )} -
{isOwner ? "——" : serviceCount}
+
{isOwner ? `¥${monthlyIncome}` : serviceCount}
diff --git a/app/(order)/chat/[id]/page.tsx b/app/(order)/chat/[id]/page.tsx index e1e4e39..0a8a206 100644 --- a/app/(order)/chat/[id]/page.tsx +++ b/app/(order)/chat/[id]/page.tsx @@ -27,15 +27,28 @@ export default function ChatDetailPage({ params }: { params: Promise<{ id: strin messages, error, createDM, + joinSession, leaveSession, sendTextMessage, sendImageMessage, } = useChatSocket() + const cacheKey = user?.id ? `chat:dm:${user.id}:${targetUserId}` : null + useEffect(() => { - if (!connected) return - createDM(targetUserId) - }, [connected, createDM, targetUserId]) + if (!connected || !cacheKey) return + const cached = window.localStorage.getItem(cacheKey) + if (cached) { + joinSession(cached) + } else { + createDM(targetUserId) + } + }, [connected, cacheKey, createDM, joinSession, targetUserId]) + + useEffect(() => { + if (!sessionId || !cacheKey) return + window.localStorage.setItem(cacheKey, sessionId) + }, [sessionId, cacheKey]) useEffect( () => () => { diff --git a/lib/types.ts b/lib/types.ts index 5d6b00d..577468b 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -168,7 +168,7 @@ export interface Post { content: string images: string[] tags: string[] - linkedOrderId?: number + linkedOrderId?: SnowflakeId pinned: boolean likeCount: number commentCount: number diff --git a/store/auth.ts b/store/auth.ts index f00e2ea..4b5ddd8 100644 --- a/store/auth.ts +++ b/store/auth.ts @@ -22,6 +22,7 @@ interface PersistedAuth { currentRole: UserRole verifiedRoles: UserRole[] verificationStatus: Partial> + notificationPrefs: NotificationPrefs themePreference: ThemePreference } @@ -50,6 +51,7 @@ function persistCurrent(state: AuthState) { currentRole: state.currentRole, verifiedRoles: state.verifiedRoles, verificationStatus: state.verificationStatus, + notificationPrefs: state.notificationPrefs, themePreference: state.themePreference, }) } @@ -95,13 +97,15 @@ export const useAuthStore = create((set, get) => ({ persistCurrent(get()) } }, - setNotificationPref: (type, enabled) => + setNotificationPref: (type, enabled) => { set((state) => ({ notificationPrefs: { ...state.notificationPrefs, [type]: enabled, }, - })), + })) + persistCurrent(get()) + }, setThemePreference: (theme) => { set({ themePreference: theme }) persistCurrent(get()) @@ -138,6 +142,7 @@ export const useAuthStore = create((set, get) => ({ currentRole: user.role, verifiedRoles: nextVerifiedRoles, verificationStatus: nextVerificationStatus, + notificationPrefs: state.notificationPrefs, themePreference: nextTheme, }) @@ -160,7 +165,7 @@ export const useAuthStore = create((set, get) => ({ verifiedRoles: ["consumer"], verificationStatus: { consumer: "approved" }, verificationReasons: {}, - notificationPrefs: defaultNotificationPrefs, + notificationPrefs: persisted?.notificationPrefs ?? defaultNotificationPrefs, themePreference: "system", user: null, })