mirror of
https://github.com/langbot-app/LangBot.git
synced 2025-11-25 19:37:36 +08:00
feat: finish toggle plugin
This commit is contained in:
@@ -4,6 +4,7 @@ export interface IPluginCardVO {
|
|||||||
name: string,
|
name: string,
|
||||||
description: string,
|
description: string,
|
||||||
handlerCount: number,
|
handlerCount: number,
|
||||||
|
isInitialized: boolean,
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PluginCardVO implements IPluginCardVO {
|
export class PluginCardVO implements IPluginCardVO {
|
||||||
@@ -12,6 +13,7 @@ export class PluginCardVO implements IPluginCardVO {
|
|||||||
name: string;
|
name: string;
|
||||||
author: string;
|
author: string;
|
||||||
version: string;
|
version: string;
|
||||||
|
isInitialized: boolean;
|
||||||
|
|
||||||
constructor(prop: IPluginCardVO) {
|
constructor(prop: IPluginCardVO) {
|
||||||
this.description = prop.description
|
this.description = prop.description
|
||||||
@@ -19,6 +21,7 @@ export class PluginCardVO implements IPluginCardVO {
|
|||||||
this.name = prop.name
|
this.name = prop.name
|
||||||
this.author = prop.author
|
this.author = prop.author
|
||||||
this.version = prop.version
|
this.version = prop.version
|
||||||
|
this.isInitialized = prop.isInitialized
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import styles from "@/app/home/plugins/plugins.module.css";
|
|||||||
import {Modal, Input} from "antd";
|
import {Modal, Input} from "antd";
|
||||||
import {GithubOutlined} from "@ant-design/icons";
|
import {GithubOutlined} from "@ant-design/icons";
|
||||||
import {httpClient} from "@/app/infra/http/HttpClient";
|
import {httpClient} from "@/app/infra/http/HttpClient";
|
||||||
import * as http from "node:http";
|
|
||||||
|
|
||||||
export default function PluginInstalledComponent () {
|
export default function PluginInstalledComponent () {
|
||||||
const [pluginList, setPluginList] = useState<PluginCardVO[]>([])
|
const [pluginList, setPluginList] = useState<PluginCardVO[]>([])
|
||||||
@@ -32,7 +31,8 @@ export default function PluginInstalledComponent () {
|
|||||||
description: plugin.description.zh_CN,
|
description: plugin.description.zh_CN,
|
||||||
handlerCount: 0,
|
handlerCount: 0,
|
||||||
name: plugin.name,
|
name: plugin.name,
|
||||||
version: plugin.version
|
version: plugin.version,
|
||||||
|
isInitialized: plugin.status === "initialized",
|
||||||
})
|
})
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,13 +1,28 @@
|
|||||||
import styles from "./pluginCard.module.css"
|
import styles from "./pluginCard.module.css"
|
||||||
import {PluginCardVO} from "@/app/home/plugins/plugin-installed/PluginCardVO";
|
import {PluginCardVO} from "@/app/home/plugins/plugin-installed/PluginCardVO";
|
||||||
import {GithubOutlined, LinkOutlined, ToolOutlined} from '@ant-design/icons';
|
import {GithubOutlined, LinkOutlined, ToolOutlined} from '@ant-design/icons';
|
||||||
import {Tag} from 'antd'
|
import {Switch, Tag} from 'antd'
|
||||||
|
import {useState} from "react";
|
||||||
|
import {httpClient} from "@/app/infra/http/HttpClient";
|
||||||
|
|
||||||
export default function PluginCardComponent({
|
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(result => {
|
||||||
|
setInitialized(!initialized)
|
||||||
|
}).catch(err => {
|
||||||
|
console.log("error: ", err)
|
||||||
|
}).finally(() => {
|
||||||
|
setSwitchEnable(true)
|
||||||
|
})
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div className={`${styles.cardContainer}`}>
|
<div className={`${styles.cardContainer}`}>
|
||||||
{/* header */}
|
{/* header */}
|
||||||
@@ -41,6 +56,12 @@ export default function PluginCardComponent({
|
|||||||
style={{fontSize: '22px'}}
|
style={{fontSize: '22px'}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Switch
|
||||||
|
value={initialized}
|
||||||
|
onClick={handleEnable}
|
||||||
|
disabled={!switchEnable}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -40,6 +40,10 @@
|
|||||||
.cardFooter {
|
.cardFooter {
|
||||||
width: 90%;
|
width: 90%;
|
||||||
height: 30px;
|
height: 30px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ export interface MarketPlugin {
|
|||||||
artifacts_path: string
|
artifacts_path: string
|
||||||
stars: number
|
stars: number
|
||||||
downloads: number
|
downloads: number
|
||||||
status: "synced" | string // 可根据实际状态值扩展联合类型
|
status: "initialized" | "mounted" // 可根据实际状态值扩展联合类型
|
||||||
synced_at: string
|
synced_at: string
|
||||||
pushed_at: string // 最后一次代码推送时间
|
pushed_at: string // 最后一次代码推送时间
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -339,7 +339,7 @@ class HttpClient {
|
|||||||
name: string,
|
name: string,
|
||||||
target_enabled: boolean
|
target_enabled: boolean
|
||||||
): Promise<object> {
|
): Promise<object> {
|
||||||
return this.post(`/api/v1/plugins/${author}/${name}/toggle`, {
|
return this.put(`/api/v1/plugins/${author}/${name}/toggle`, {
|
||||||
target_enabled
|
target_enabled
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user