Skip to content

Commit

Permalink
refactor(plugin-flow-builder): DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
Iru89 committed Oct 3, 2024
1 parent 4398df1 commit eaebe04
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,22 @@ export function useWebviewContents<T extends MapContentsType>({
return

Check warning on line 37 in packages/botonic-plugin-flow-builder/src/webview/use-webview-contents.ts

View check run for this annotation

Codecov / codecov/patch

packages/botonic-plugin-flow-builder/src/webview/use-webview-contents.ts#L36-L37

Added lines #L36 - L37 were not covered by tests
}

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]

Check warning on line 41 in packages/botonic-plugin-flow-builder/src/webview/use-webview-contents.ts

View check run for this annotation

Codecov / codecov/patch

packages/botonic-plugin-flow-builder/src/webview/use-webview-contents.ts#L40-L41

Added lines #L40 - L41 were not covered by tests

if (locales.includes(currentLocale)) {
setCurrentLocale(currentLocale)
return

Check warning on line 45 in packages/botonic-plugin-flow-builder/src/webview/use-webview-contents.ts

View check run for this annotation

Codecov / codecov/patch

packages/botonic-plugin-flow-builder/src/webview/use-webview-contents.ts#L44-L45

Added lines #L44 - L45 were not covered by tests
}

const language = currentLocale.split('-')[0]
if (textContents[0].content.text.some(text => text.locale === language)) {
if (locales.includes(language)) {
setCurrentLocale(language)
return

Check warning on line 50 in packages/botonic-plugin-flow-builder/src/webview/use-webview-contents.ts

View check run for this annotation

Codecov / codecov/patch

packages/botonic-plugin-flow-builder/src/webview/use-webview-contents.ts#L49-L50

Added lines #L49 - L50 were not covered by tests
}

console.error(

Check warning on line 53 in packages/botonic-plugin-flow-builder/src/webview/use-webview-contents.ts

View check run for this annotation

Codecov / codecov/patch

packages/botonic-plugin-flow-builder/src/webview/use-webview-contents.ts#L53

Added line #L53 was not covered by tests
`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 => {
Expand Down

0 comments on commit eaebe04

Please sign in to comment.