diff --git a/.changeset/loud-rockets-shake.md b/.changeset/loud-rockets-shake.md new file mode 100644 index 00000000..c5e73ad7 --- /dev/null +++ b/.changeset/loud-rockets-shake.md @@ -0,0 +1,5 @@ +--- +"wptelegram-widget": patch +--- + +Fixed the issue of single post widget author photo always shown diff --git a/plugins/wptelegram-widget/js/blocks/single-post/Edit.tsx b/plugins/wptelegram-widget/js/blocks/single-post/Edit.tsx index c9b43fb8..2a7f3cf4 100644 --- a/plugins/wptelegram-widget/js/blocks/single-post/Edit.tsx +++ b/plugins/wptelegram-widget/js/blocks/single-post/Edit.tsx @@ -17,7 +17,7 @@ export function Edit(props: BlockEditProps) { const [isEditingURL, setIsEditingURL] = useState(false); const [url, setUrl] = useState(props.attributes.url || ''); const [userpic, setUserpic] = useState( - props.attributes.userpic || true, + props.attributes.userpic ?? true, ); const [iframeHeight, setIframeHeight] = useState(0); @@ -63,17 +63,13 @@ export function Edit(props: BlockEditProps) { .replace('%userpic%', `${userpic}`); } - function toggleUserPic() { - setUserpic((prevValue) => { - const newValue = !prevValue; + function toggleUserPic(newValue: boolean) { + setIframeState('loading'); + let { iframe_src } = props.attributes; + iframe_src = addQueryArgs(iframe_src, { userpic: newValue }); + props.setAttributes({ userpic: newValue, iframe_src }); - setIframeState('loading'); - let { iframe_src } = props.attributes; - iframe_src = addQueryArgs(iframe_src, { userpic }); - props.setAttributes({ userpic: newValue, iframe_src }); - - return newValue; - }); + setUserpic(newValue); } function onChangeAlign(align: SinglePostAtts['alignment']) {