mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-10 15:56:03 +00:00
Refactor and enhance UI components across the application
- Improved formatting and consistency in BotConfigPage, HomeSidebar, and Plugin components. - Removed unnecessary Spin component to prevent layout collapse in BotConfigPage. - Enhanced sidebar selection logic to reflect current URL path in HomeSidebar. - Updated layout styles for better responsiveness and visual appeal. - Implemented mock data fetching in PluginMarketComponent for improved testing and development. - Added pagination and search functionality in PluginMarketComponent. - Refactored PluginInstalledComponent to streamline plugin list rendering and modal handling. - Adjusted CSS styles for better alignment and spacing in various components. - Removed commented-out code in HttpClient for cleaner codebase. - Enhanced NotFound component layout for better user experience.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"use client";
|
||||
"use client"
|
||||
|
||||
import CreateCardComponent from "@/app/infra/basic-component/create-card-component/CreateCardComponent";
|
||||
import { PluginCardVO } from "@/app/home/plugins/plugin-installed/PluginCardVO";
|
||||
@@ -7,54 +7,221 @@ import PluginCardComponent from "@/app/home/plugins/plugin-installed/plugin-card
|
||||
import styles from "@/app/home/plugins/plugins.module.css";
|
||||
import { Modal, Input } from "antd";
|
||||
import { GithubOutlined } from "@ant-design/icons";
|
||||
import { httpClient } from "@/app/infra/http/HttpClient";
|
||||
|
||||
export default function PluginInstalledComponent() {
|
||||
const [pluginList, setPluginList] = useState<PluginCardVO[]>([]);
|
||||
const [modalOpen, setModalOpen] = useState(false);
|
||||
const [githubURL, setGithubURL] = useState("");
|
||||
const [pluginList, setPluginList] = useState<PluginCardVO[]>([])
|
||||
const [modalOpen, setModalOpen] = useState(false)
|
||||
const [githubURL, setGithubURL] = useState("")
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
initData();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
initData()
|
||||
}, [])
|
||||
|
||||
function initData() {
|
||||
getPluginList();
|
||||
getPluginList().then((value) => {
|
||||
setPluginList(value)
|
||||
})
|
||||
}
|
||||
|
||||
function getPluginList() {
|
||||
httpClient.getPlugins().then((value) => {
|
||||
setPluginList(
|
||||
value.plugins.map((plugin) => {
|
||||
return new PluginCardVO({
|
||||
author: plugin.author,
|
||||
description: plugin.description.zh_CN,
|
||||
handlerCount: 0,
|
||||
name: plugin.name,
|
||||
version: plugin.version,
|
||||
isInitialized: plugin.status === "initialized"
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
||||
async function getPluginList() {
|
||||
return [
|
||||
new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}),
|
||||
new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}),
|
||||
new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}),
|
||||
new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}),
|
||||
new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}),
|
||||
new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}),
|
||||
new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}),
|
||||
new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}),
|
||||
new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}),
|
||||
new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}),
|
||||
new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}),
|
||||
new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}),
|
||||
new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}),
|
||||
new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}),
|
||||
new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}),
|
||||
new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}),
|
||||
new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}),
|
||||
new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}),
|
||||
new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}),
|
||||
new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}),
|
||||
new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}),
|
||||
new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}), new PluginCardVO({
|
||||
description: "一般的描述",
|
||||
handlerCount: 0,
|
||||
name: "插件AAA",
|
||||
author: "/hana",
|
||||
version: "0.1",
|
||||
isInitialized: false
|
||||
}),
|
||||
|
||||
|
||||
]
|
||||
}
|
||||
|
||||
function handleModalConfirm() {
|
||||
installPlugin(githubURL);
|
||||
setModalOpen(false);
|
||||
installPlugin(githubURL)
|
||||
setModalOpen(false)
|
||||
}
|
||||
|
||||
function installPlugin(url: string) {
|
||||
httpClient
|
||||
.installPluginFromGithub(url)
|
||||
.then(() => {
|
||||
// 安装后重新拉取
|
||||
getPluginList();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("error when install plugin:", err);
|
||||
});
|
||||
// TODO 接安装Plugin的接口
|
||||
console.log("installPlugin: ", url)
|
||||
}
|
||||
return (
|
||||
<div className={`${styles.pluginListContainer}`}>
|
||||
@@ -63,8 +230,8 @@ export default function PluginInstalledComponent() {
|
||||
<div className={`${styles.modalTitle}`}>
|
||||
<GithubOutlined
|
||||
style={{
|
||||
fontSize: "30px",
|
||||
marginRight: "20px"
|
||||
fontSize: '30px',
|
||||
marginRight: '20px'
|
||||
}}
|
||||
type="setting"
|
||||
/>
|
||||
@@ -79,7 +246,9 @@ export default function PluginInstalledComponent() {
|
||||
destroyOnClose={true}
|
||||
>
|
||||
<div className={`${styles.modalBody}`}>
|
||||
<div>目前仅支持从 GitHub 安装</div>
|
||||
<div>
|
||||
目前仅支持从 GitHub 安装
|
||||
</div>
|
||||
<Input
|
||||
placeholder="请输入插件的Github链接"
|
||||
value={githubURL}
|
||||
@@ -87,21 +256,20 @@ export default function PluginInstalledComponent() {
|
||||
/>
|
||||
</div>
|
||||
</Modal>
|
||||
{pluginList.map((vo, index) => {
|
||||
return (
|
||||
<div key={index}>
|
||||
{
|
||||
pluginList.map((vo, index) => {
|
||||
return <div key={index}>
|
||||
<PluginCardComponent cardVO={vo} />
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
})
|
||||
}
|
||||
<CreateCardComponent
|
||||
width={360}
|
||||
height={140}
|
||||
plusSize={90}
|
||||
onClick={() => {
|
||||
setModalOpen(true);
|
||||
setModalOpen(true)
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,65 +1,47 @@
|
||||
import styles from "./pluginCard.module.css";
|
||||
import styles from "./pluginCard.module.css"
|
||||
import { PluginCardVO } from "@/app/home/plugins/plugin-installed/PluginCardVO";
|
||||
import { GithubOutlined, LinkOutlined, ToolOutlined } from "@ant-design/icons";
|
||||
import { Switch, Tag } from "antd";
|
||||
import { useState } from "react";
|
||||
import { httpClient } from "@/app/infra/http/HttpClient";
|
||||
import { GithubOutlined, LinkOutlined, ToolOutlined } from '@ant-design/icons';
|
||||
import { Tag } from 'antd'
|
||||
|
||||
export default function PluginCardComponent({
|
||||
cardVO
|
||||
cardVO
|
||||
}: {
|
||||
cardVO: PluginCardVO;
|
||||
cardVO: PluginCardVO
|
||||
}) {
|
||||
const [initialized, setInitialized] = useState(cardVO.isInitialized);
|
||||
const [switchEnable, setSwitchEnable] = useState(true);
|
||||
|
||||
function handleEnable() {
|
||||
setSwitchEnable(false);
|
||||
httpClient
|
||||
.togglePlugin(cardVO.author, cardVO.name, !initialized)
|
||||
.then(() => {
|
||||
setInitialized(!initialized);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("error: ", err);
|
||||
})
|
||||
.finally(() => {
|
||||
setSwitchEnable(true);
|
||||
});
|
||||
}
|
||||
return (
|
||||
<div className={`${styles.cardContainer}`}>
|
||||
{/* header */}
|
||||
<div className={`${styles.cardHeader}`}>
|
||||
{/* left author */}
|
||||
<div className={`${styles.fontGray}`}>{cardVO.author}</div>
|
||||
{/* right icon & version */}
|
||||
<div className={`${styles.iconVersionContainer}`}>
|
||||
<GithubOutlined style={{ fontSize: "26px" }} type="setting" />
|
||||
<Tag color="#108ee9">v{cardVO.version}</Tag>
|
||||
return (
|
||||
<div className={`${styles.cardContainer}`}>
|
||||
{/* header */}
|
||||
<div className={`${styles.cardHeader}`}>
|
||||
{/* left author */}
|
||||
<div className={`${styles.fontGray}`}>{cardVO.author}</div>
|
||||
{/* right icon & version */}
|
||||
<div className={`${styles.iconVersionContainer}`}>
|
||||
<GithubOutlined
|
||||
style={{ fontSize: '26px' }}
|
||||
type="setting"
|
||||
/>
|
||||
<Tag color="#108ee9">v{cardVO.version}</Tag>
|
||||
</div>
|
||||
</div>
|
||||
{/* content */}
|
||||
<div className={`${styles.cardContent}`}>
|
||||
<div className={`${styles.boldFont}`}>{cardVO.name}</div>
|
||||
<div className={`${styles.fontGray}`}>{cardVO.description}</div>
|
||||
</div>
|
||||
{/* footer */}
|
||||
<div className={`${styles.cardFooter}`}>
|
||||
<div className={`${styles.linkSettingContainer}`}>
|
||||
<div className={`${styles.link}`}>
|
||||
<LinkOutlined
|
||||
style={{ fontSize: '22px' }}
|
||||
/>
|
||||
<span>1</span>
|
||||
</div>
|
||||
<ToolOutlined
|
||||
style={{ fontSize: '22px' }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/* content */}
|
||||
<div className={`${styles.cardContent}`}>
|
||||
<div className={`${styles.boldFont}`}>{cardVO.name}</div>
|
||||
<div className={`${styles.fontGray}`}>{cardVO.description}</div>
|
||||
</div>
|
||||
{/* footer */}
|
||||
<div className={`${styles.cardFooter}`}>
|
||||
<div className={`${styles.linkSettingContainer}`}>
|
||||
<div className={`${styles.link}`}>
|
||||
<LinkOutlined style={{ fontSize: "22px" }} />
|
||||
<span>1</span>
|
||||
</div>
|
||||
<ToolOutlined style={{ fontSize: "22px" }} />
|
||||
</div>
|
||||
|
||||
<Switch
|
||||
value={initialized}
|
||||
onClick={handleEnable}
|
||||
disabled={!switchEnable}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
.cardContainer {
|
||||
width: 360px;
|
||||
width: 100%;
|
||||
/* 修改为 100% 以撑满整个网格单元 */
|
||||
height: 140px;
|
||||
box-sizing: border-box;
|
||||
background-color: #FFF;
|
||||
@@ -40,10 +41,6 @@
|
||||
.cardFooter {
|
||||
width: 90%;
|
||||
height: 30px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,4 +70,4 @@
|
||||
align-self: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user