Skip to content

Commit 1f0a533

Browse files
committed
♻️ refactor: refactor to use new lobeChat api
1 parent 346f8f0 commit 1f0a533

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"not ie <= 10"
5353
],
5454
"dependencies": {
55-
"@lobehub/chat-plugin-sdk": "^1.18.0",
55+
"@lobehub/chat-plugin-sdk": "^1.22.0",
5656
"@lobehub/chat-plugins-gateway": "^1",
5757
"@lobehub/ui": "latest",
5858
"antd": "^5",

src/pages/iframe/index.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
fetchPluginMessage,
3-
postToFillPluginContent,
4-
useOnStandalonePluginInit,
5-
} from '@lobehub/chat-plugin-sdk/client';
1+
import { lobeChat } from '@lobehub/chat-plugin-sdk/client';
62
import { Button } from 'antd';
73
import { memo, useEffect, useState } from 'react';
84
import { Center } from 'react-layout-kit';
@@ -17,22 +13,24 @@ const Render = memo(() => {
1713

1814
// 初始化时从主应用同步状态
1915
useEffect(() => {
20-
fetchPluginMessage().then(setData);
16+
lobeChat.getPluginMessage().then(setData);
2117
}, []);
2218

2319
// 记录请求参数
2420
const [payload, setPayload] = useState<any>();
2521

26-
useOnStandalonePluginInit<ResponseData>((payload) => {
27-
if (payload.func === 'recommendClothes') {
28-
setPayload(payload.args);
29-
}
30-
});
22+
useEffect(() => {
23+
lobeChat.getPluginPayload().then((payload) => {
24+
if (payload.name === 'recommendClothes') {
25+
setPayload(payload.arguments);
26+
}
27+
});
28+
}, []);
3129

3230
const fetchData = async () => {
3331
const data = await fetchClothes(payload);
3432
setData(data);
35-
postToFillPluginContent(data);
33+
lobeChat.setPluginMessage(data);
3634
};
3735

3836
return data ? (

src/pages/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fetchPluginMessage } from '@lobehub/chat-plugin-sdk/client';
1+
import { lobeChat } from '@lobehub/chat-plugin-sdk/client';
22
import { memo, useEffect, useState } from 'react';
33

44
import Data from '@/components/Render';
@@ -8,7 +8,7 @@ const Render = memo(() => {
88
const [data, setData] = useState<ResponseData>();
99

1010
useEffect(() => {
11-
fetchPluginMessage().then((e: ResponseData) => {
11+
lobeChat.getPluginMessage().then((e: ResponseData) => {
1212
setData(e);
1313
});
1414
}, []);

0 commit comments

Comments
 (0)