feat/0.2:add theme setting and about page setting and support use email and password login

This commit is contained in:
lethe committed 2025-07-24 10:28:42 +08:00
1 parent 58292b0e6e
commit ca2b732952
85 files changed
+5797 -816

No files matched your search

@@ -1,7 +1,12 @@
'use client';
"use client";
import React, { createContext, useContext, useState, ReactNode, useEffect } from 'react';
import { PlatformConfig, PlatformConfigResponse, GoogleAuthConfig } from '@/shared/types/system';
import React, { createContext, useContext, useState, ReactNode } from "react";
import {
PlatformConfig,
PlatformConfigResponse,
Theme,
LoginConfig,
} from "@/shared/types/system";
export const _DefaultPlatformConfig: PlatformConfig = {
name: "XPack",
logo: "/static/logo/logo.png",
@@ -9,34 +14,43 @@ export const _DefaultPlatformConfig: PlatformConfig = {
language: "en",
website_title: "Connect Your AI Agent to the Real World - XPack",
headline: "Connect Your AI Agent to the Real World",
subheadline: "Open‑source MCP marketplace — publish or consume APIs in minutes.",
subheadline:
"Open‑source MCP marketplace — publish or consume APIs in minutes.",
theme: Theme.DEFAULT,
};
interface PlatformConfigContextType {
platformConfig: PlatformConfig;
googleAuthConfig: GoogleAuthConfig | null;
loginConfig: LoginConfig | null;
updateClientConfig: (config: PlatformConfigResponse) => void;
}
const PlatformConfigContext = createContext<PlatformConfigContextType | undefined>(undefined);
const PlatformConfigContext = createContext<
PlatformConfigContextType | undefined
>(undefined);
interface PlatformConfigProviderProps {
children: ReactNode;
initConfig: PlatformConfigResponse;
initConfig?: PlatformConfigResponse;
}
export const PlatformConfigProvider: React.FC<PlatformConfigProviderProps> = ({
children,
initConfig,
}) => {
const [platformConfig, setPlatformConfig] = useState<PlatformConfig>(initConfig.platform || _DefaultPlatformConfig);
const [googleAuthConfig, setGoogleAuthConfig] = useState<GoogleAuthConfig | null>(initConfig.login?.google || null);
const [platformConfig, setPlatformConfig] = useState<PlatformConfig>(
initConfig?.platform || _DefaultPlatformConfig
);
const [loginConfig, setLoginConfig] = useState<LoginConfig | null>(
initConfig?.login || null
);
const updateClientConfig = (config: PlatformConfigResponse) => {
if (config.platform) setPlatformConfig(config.platform);
if (config.login?.google) setGoogleAuthConfig(config.login?.google);
if (config.login) setLoginConfig(config.login);
};
return (
<PlatformConfigContext.Provider value={{ platformConfig, googleAuthConfig, updateClientConfig }}>
<PlatformConfigContext.Provider
value={{ platformConfig, loginConfig, updateClientConfig }}
>
{children}
</PlatformConfigContext.Provider>
);
@@ -45,7 +59,9 @@ export const PlatformConfigProvider: React.FC<PlatformConfigProviderProps> = ({
export const usePlatformConfig = () => {
const context = useContext(PlatformConfigContext);
if (context === undefined) {
throw new Error('usePlatformConfig must be used within a PlatformConfigProvider');
throw new Error(
"usePlatformConfig must be used within a PlatformConfigProvider"
);
}
return context;
};
};