Skip to content

Commit

Permalink
🐛 fix: fix a bug that weather plugin is not work correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Oct 31, 2023
1 parent 31f6d29 commit dbb65ff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
useOnPluginFillContent,
} from '../utils/listenToPlugin';
import {
sendMessageToPlugin,
sendMessageContentToPlugin,
sendPayloadToPlugin,
sendPluginSettingsToPlugin,
sendPluginStateToPlugin,
Expand Down Expand Up @@ -58,7 +58,7 @@ const IFrameRender = memo<IFrameRenderProps>(({ url, id, payload, width = 600, h
props.content = message.content || '';
}

sendMessageToPlugin(iframeWin, props);
sendMessageContentToPlugin(iframeWin, props);
}
}, []);

Expand Down
Original file line number Diff line number Diff line change
@@ -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 }, '*');
};

Expand Down

0 comments on commit dbb65ff

Please sign in to comment.