chore: enhance data source configuration and mock data handling
Docker images / backend-image (push) Successful in 39s
Docker images / frontend-image (push) Successful in 1m38s
Docker images / updater-image (push) Successful in 35s
Docker images / notify-webhook (push) Has been skipped

- Added support for mock data mode in the frontend by introducing a new environment variable in the Dockerfile and workflow configuration.
- Updated the settings page to conditionally display options based on the availability of mock data, improving user experience.
- Refactored data source logic to include a check for mock data availability, ensuring proper mode handling in the application.
This commit is contained in:
Denozordec
2026-05-12 15:38:27 +07:00
parent 4489dfb2d6
commit 1fefed2aa0
5 changed files with 48 additions and 23 deletions
+10 -3
View File
@@ -5,6 +5,7 @@ import {
configuredBackendUrl,
defaultDataSourceMode,
isBackendUrlLocked,
isMockDataSourceAvailable,
LOCAL_DEFAULT_BACKEND_URL,
resolveStoredBackendUrl,
} from "@/lib/backend-url"
@@ -19,6 +20,7 @@ interface DataSourceContextValue {
backendUrl: string
setBackendUrl: (url: string) => void
backendUrlLocked: boolean
mockModeAvailable: boolean
/** undefined = не проверялось, true = OK, false = недоступен */
backendStatus: boolean | undefined
checkBackend: () => Promise<void>
@@ -32,9 +34,12 @@ const LS_MODE = "routerlists:data-source"
const LS_BACKEND = "routerlists:backend-url"
function readStoredMode(): DataSourceMode {
if (!isMockDataSourceAvailable()) return "live"
if (typeof window === "undefined") return defaultDataSourceMode()
const stored = localStorage.getItem(LS_MODE) as DataSourceMode | null
return stored === "mock" || stored === "live" ? stored : defaultDataSourceMode()
if (stored === "live") return "live"
if (stored === "mock") return "mock"
return defaultDataSourceMode()
}
function readStoredBackendUrl(): string {
@@ -55,6 +60,7 @@ export function DataSourceProvider({ children }: { children: React.ReactNode })
)
const [backendStatus, setBackendStatus] = useState<boolean | undefined>(undefined)
const backendUrlLocked = isBackendUrlLocked()
const mockModeAvailable = isMockDataSourceAvailable()
useEffect(() => {
if (configuredBackendUrl().kind !== "same-origin") return
@@ -62,9 +68,10 @@ export function DataSourceProvider({ children }: { children: React.ReactNode })
}, [])
const setMode = useCallback((m: DataSourceMode) => {
if (!mockModeAvailable && m === "mock") return
setModeState(m)
localStorage.setItem(LS_MODE, m)
}, [])
}, [mockModeAvailable])
const setBackendUrl = useCallback((url: string) => {
if (backendUrlLocked) return
@@ -89,7 +96,7 @@ export function DataSourceProvider({ children }: { children: React.ReactNode })
return (
<DataSourceContext.Provider
value={{ mode, setMode, backendUrl, setBackendUrl, backendUrlLocked, backendStatus, checkBackend }}
value={{ mode, setMode, backendUrl, setBackendUrl, backendUrlLocked, mockModeAvailable, backendStatus, checkBackend }}
>
{children}
</DataSourceContext.Provider>