From eaebe042c2dff72b943eca1d77c435639ac265a9 Mon Sep 17 00:00:00 2001 From: Oriol Raventos Date: Thu, 3 Oct 2024 10:15:59 +0200 Subject: [PATCH] refactor(plugin-flow-builder): DRY --- .../src/webview/use-webview-contents.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/botonic-plugin-flow-builder/src/webview/use-webview-contents.ts b/packages/botonic-plugin-flow-builder/src/webview/use-webview-contents.ts index 78f08be03..a303e9542 100644 --- a/packages/botonic-plugin-flow-builder/src/webview/use-webview-contents.ts +++ b/packages/botonic-plugin-flow-builder/src/webview/use-webview-contents.ts @@ -37,23 +37,22 @@ export function useWebviewContents({ return } - if ( - textContents[0].content.text.some(text => text.locale === currentLocale) - ) { + const locales = textContents[0].content.text.map(text => text.locale) + const language = currentLocale.split('-')[0] + + if (locales.includes(currentLocale)) { setCurrentLocale(currentLocale) return } - const language = currentLocale.split('-')[0] - if (textContents[0].content.text.some(text => text.locale === language)) { + if (locales.includes(language)) { setCurrentLocale(language) return } console.error( - `locale: ${currentLocale} cannot be resolved with: ${textContents?.[0].content.text.map(text => text.locale).join(', ')}` + `locale: ${currentLocale} cannot be resolved with: ${locales.join(', ')}` ) - return } const getTextContent = (contentID: string): string => {