mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-05-19 20:20:16 +09:00
feat: load MCP preset data from server
This commit is contained in:
parent
07c63497dc
commit
4d63d73b2e
@ -17,6 +17,27 @@
|
|||||||
padding: 20px;
|
padding: 20px;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
|
||||||
|
.loading-container,
|
||||||
|
.empty-container {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
min-height: 200px;
|
||||||
|
width: 100%;
|
||||||
|
background-color: var(--white);
|
||||||
|
border: var(--border-in-light);
|
||||||
|
border-radius: 10px;
|
||||||
|
animation: slide-in ease 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-text,
|
||||||
|
.empty-text {
|
||||||
|
font-size: 14px;
|
||||||
|
color: var(--black);
|
||||||
|
opacity: 0.5;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
.mcp-market-filter {
|
.mcp-market-filter {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
|
@ -11,7 +11,6 @@ import GithubIcon from "../icons/github.svg";
|
|||||||
import { List, ListItem, Modal, showToast } from "./ui-lib";
|
import { List, ListItem, Modal, showToast } from "./ui-lib";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import presetServersJson from "../mcp/preset-server.json";
|
|
||||||
import {
|
import {
|
||||||
addMcpServer,
|
addMcpServer,
|
||||||
getClientStatus,
|
getClientStatus,
|
||||||
@ -32,8 +31,6 @@ import clsx from "clsx";
|
|||||||
import PlayIcon from "../icons/play.svg";
|
import PlayIcon from "../icons/play.svg";
|
||||||
import StopIcon from "../icons/pause.svg";
|
import StopIcon from "../icons/pause.svg";
|
||||||
|
|
||||||
const presetServers = presetServersJson as PresetServer[];
|
|
||||||
|
|
||||||
interface ConfigProperty {
|
interface ConfigProperty {
|
||||||
type: string;
|
type: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
@ -53,6 +50,28 @@ export function McpMarketPage() {
|
|||||||
const [clientStatuses, setClientStatuses] = useState<
|
const [clientStatuses, setClientStatuses] = useState<
|
||||||
Record<string, ServerStatusResponse>
|
Record<string, ServerStatusResponse>
|
||||||
>({});
|
>({});
|
||||||
|
const [loadingPresets, setLoadingPresets] = useState(true);
|
||||||
|
const [presetServers, setPresetServers] = useState<PresetServer[]>([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadPresetServers = async () => {
|
||||||
|
try {
|
||||||
|
setLoadingPresets(true);
|
||||||
|
const response = await fetch("https://nextchat.club/mcp/list");
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Failed to load preset servers");
|
||||||
|
}
|
||||||
|
const data = await response.json();
|
||||||
|
setPresetServers(data?.data ?? []);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to load preset servers:", error);
|
||||||
|
showToast("Failed to load preset servers");
|
||||||
|
} finally {
|
||||||
|
setLoadingPresets(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
loadPresetServers().then();
|
||||||
|
}, []);
|
||||||
|
|
||||||
// 检查服务器是否已添加
|
// 检查服务器是否已添加
|
||||||
const isServerAdded = (id: string) => {
|
const isServerAdded = (id: string) => {
|
||||||
@ -440,6 +459,24 @@ export function McpMarketPage() {
|
|||||||
|
|
||||||
// 渲染服务器列表
|
// 渲染服务器列表
|
||||||
const renderServerList = () => {
|
const renderServerList = () => {
|
||||||
|
if (loadingPresets) {
|
||||||
|
return (
|
||||||
|
<div className={styles["loading-container"]}>
|
||||||
|
<div className={styles["loading-text"]}>
|
||||||
|
Loading preset server list...
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Array.isArray(presetServers) || presetServers.length === 0) {
|
||||||
|
return (
|
||||||
|
<div className={styles["empty-container"]}>
|
||||||
|
<div className={styles["empty-text"]}>No servers available</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return presetServers
|
return presetServers
|
||||||
.filter((server) => {
|
.filter((server) => {
|
||||||
if (searchText.length === 0) return true;
|
if (searchText.length === 0) return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user