Skip to content

Commit

Permalink
PLANET-6198 Improve code after PR review
Browse files Browse the repository at this point in the history
Simplify and/or rewrite some parts of the code
  • Loading branch information
mleray committed Aug 2, 2021
1 parent c7f0593 commit 0fed36c
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions assets/src/blocks/SocialMedia/SocialMediaEditorScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ export const SocialMediaEditor = ({
}

const updateEmbed = async (url, provider) => {
if (!url || provider === 'facebook') {
if (!url) {
setAttributes({ embed_code: '' });
return;
}

let embedCode;
try {
if (provider === 'twitter') {
Expand All @@ -135,17 +136,15 @@ export const SocialMediaEditor = ({
};

useEffect(() => {
ALLOWED_OEMBED_PROVIDERS.forEach(provider => {
if (social_media_url.includes(provider)) {
checkProviderScript(provider);
// For Facebook we don't need the embed HTML code since we use an iframe
if (provider !== 'facebook') {
updateEmbed(social_media_url, provider);
}
} else {
setAttributes({ embed_code: '' });
}
});
const provider = ALLOWED_OEMBED_PROVIDERS.find(allowedProvider => social_media_url.includes(allowedProvider));

// For Facebook we don't need the embed HTML code since we use an iframe
if (!provider || provider === 'facebook') {
setAttributes({ embed_code: '' });
return;
}

updateEmbed(social_media_url, provider);
}, [social_media_url]);

const embed_type_help = __('Select oEmbed for the following types of social media<br>- Twitter: tweet, profile, list, collection, likes, moment<br>- Facebook: post, activity, photo, video, media, question, note<br>- Instagram: image', 'planet4-blocks-backend');
Expand Down

0 comments on commit 0fed36c

Please sign in to comment.