feat(dashboard,diagnostic,elective): add widgets, layout, parent dashboard, role-config, services, elective components
dashboard: - Add comparison-badge, dashboard-notification-widget, dashboard-responsive-layout, dashboard-time-range-filter - Add parent-dashboard components directory - Add config, hooks, and services directories diagnostic: - Add role-config and services directory elective: - Add elective-course-detail, elective-stats-cards, parent-selection-view components - Add data-access-settings and data-access-stats
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
"use client"
|
||||
|
||||
import { createContext, useContext, type ReactNode } from "react"
|
||||
|
||||
import type { DiagnosticService } from "./diagnostic-service"
|
||||
|
||||
/**
|
||||
* v2-P1-4: 诊断模块服务 Context。
|
||||
*
|
||||
* 组件通过 useDiagnosticService() 获取服务实现,
|
||||
* 而非直接 import actions,实现依赖反转。
|
||||
*
|
||||
* 默认由 DefaultDiagnosticServiceProvider 注入真实实现(调用 Server Actions);
|
||||
* 测试时可注入 mock 实现以隔离组件测试。
|
||||
*/
|
||||
const DiagnosticServiceContext = createContext<DiagnosticService | null>(null)
|
||||
|
||||
interface DiagnosticServiceProviderProps {
|
||||
service: DiagnosticService
|
||||
children: ReactNode
|
||||
}
|
||||
|
||||
export function DiagnosticServiceProvider({
|
||||
service,
|
||||
children,
|
||||
}: DiagnosticServiceProviderProps): ReactNode {
|
||||
return (
|
||||
<DiagnosticServiceContext.Provider value={service}>
|
||||
{children}
|
||||
</DiagnosticServiceContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取诊断模块服务。
|
||||
* 必须在 DiagnosticServiceProvider 内部使用。
|
||||
*/
|
||||
export function useDiagnosticService(): DiagnosticService {
|
||||
const service = useContext(DiagnosticServiceContext)
|
||||
if (!service) {
|
||||
throw new Error(
|
||||
"useDiagnosticService must be used within a DiagnosticServiceProvider",
|
||||
)
|
||||
}
|
||||
return service
|
||||
}
|
||||
Reference in New Issue
Block a user