🐛 fix: fix a bug that weather plugin is not work correctly

This commit is contained in:
arvinxx
2023-10-31 23:41:24 +08:00
parent 31f6d29d9b
commit dbb65ff6c2
3 changed files with 14 additions and 5 deletions

View File

@@ -3,7 +3,8 @@ import { Skeleton } from 'antd';
import { memo, useRef, useState } from 'react';
import { useOnPluginReadyForInteraction } from '../../utils/iframeOnReady';
import { sendMessageToPlugin } from '../../utils/postMessage';
import { useOnPluginFetchMessage } from '../../utils/listenToPlugin';
import { sendMessageContentToPlugin } from '../../utils/postMessage';
interface IFrameRenderProps extends PluginRenderProps {
height?: number;
@@ -20,7 +21,15 @@ const IFrameRender = memo<IFrameRenderProps>(({ url, width = 800, height = 300,
const iframeWin = iframeRef.current?.contentWindow;
if (iframeWin) {
sendMessageToPlugin(iframeWin, props);
sendMessageContentToPlugin(iframeWin, props);
}
}, [props]);
// when get iframe fetch message send message content
useOnPluginFetchMessage(() => {
const iframeWin = iframeRef.current?.contentWindow;
if (iframeWin) {
sendMessageContentToPlugin(iframeWin, props);
}
}, [props]);

View File

@@ -16,7 +16,7 @@ import {
useOnPluginFillContent,
} from '../utils/listenToPlugin';
import {
sendMessageToPlugin,
sendMessageContentToPlugin,
sendPayloadToPlugin,
sendPluginSettingsToPlugin,
sendPluginStateToPlugin,
@@ -58,7 +58,7 @@ const IFrameRender = memo<IFrameRenderProps>(({ url, id, payload, width = 600, h
props.content = message.content || '';
}
sendMessageToPlugin(iframeWin, props);
sendMessageContentToPlugin(iframeWin, props);
}
}, []);

View File

@@ -1,6 +1,6 @@
import { PluginChannel } from '@lobehub/chat-plugin-sdk/client';
export const sendMessageToPlugin = (window: Window, props: any) => {
export const sendMessageContentToPlugin = (window: Window, props: any) => {
window.postMessage({ props, type: PluginChannel.renderPlugin }, '*');
};