Skip to content

Commit

Permalink
♻️ refactor: refactor to use new lobeChat api
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Nov 6, 2023
1 parent 346f8f0 commit 1f0a533
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"not ie <= 10"
],
"dependencies": {
"@lobehub/chat-plugin-sdk": "^1.18.0",
"@lobehub/chat-plugin-sdk": "^1.22.0",
"@lobehub/chat-plugins-gateway": "^1",
"@lobehub/ui": "latest",
"antd": "^5",
Expand Down
22 changes: 10 additions & 12 deletions src/pages/iframe/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
fetchPluginMessage,
postToFillPluginContent,
useOnStandalonePluginInit,
} from '@lobehub/chat-plugin-sdk/client';
import { lobeChat } from '@lobehub/chat-plugin-sdk/client';
import { Button } from 'antd';
import { memo, useEffect, useState } from 'react';
import { Center } from 'react-layout-kit';
Expand All @@ -17,22 +13,24 @@ const Render = memo(() => {

// 初始化时从主应用同步状态
useEffect(() => {
fetchPluginMessage().then(setData);
lobeChat.getPluginMessage().then(setData);
}, []);

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

useOnStandalonePluginInit<ResponseData>((payload) => {
if (payload.func === 'recommendClothes') {
setPayload(payload.args);
}
});
useEffect(() => {
lobeChat.getPluginPayload().then((payload) => {
if (payload.name === 'recommendClothes') {
setPayload(payload.arguments);
}
});
}, []);

const fetchData = async () => {
const data = await fetchClothes(payload);
setData(data);
postToFillPluginContent(data);
lobeChat.setPluginMessage(data);
};

return data ? (
Expand Down
4 changes: 2 additions & 2 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fetchPluginMessage } from '@lobehub/chat-plugin-sdk/client';
import { lobeChat } from '@lobehub/chat-plugin-sdk/client';
import { memo, useEffect, useState } from 'react';

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

useEffect(() => {
fetchPluginMessage().then((e: ResponseData) => {
lobeChat.getPluginMessage().then((e: ResponseData) => {
setData(e);
});
}, []);
Expand Down

0 comments on commit 1f0a533

Please sign in to comment.