Skip to content

Commit

Permalink
refactor: return early if no progressData
Browse files Browse the repository at this point in the history
use localeOption (lang code) fallback for source or target names instead of empty string
  • Loading branch information
wackerow committed Mar 25, 2024
1 parent 27f9959 commit e5857aa
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/components/LanguagePicker/useLanguagePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,23 @@ export const useLanguagePicker = (
(dataItem!.words.approved / dataItem!.words.total) * 100
) || 0

if (progressData.length === 0) {
console.warn("Missing translation progress data; check GitHub action")
const isBrowserDefault = browserLocales.includes(localeOption)

const returnData: Partial<LocaleDisplayInfo> = {
localeOption,
sourceName: sourceName ?? localeOption,
targetName: targetName ?? localeOption,
englishName,
isBrowserDefault,
}

if (progressData.length < 1) {
console.warn(`Missing translation progress data; check GitHub action`)
return {
...returnData,
approvalProgress: 0,
wordsApproved: 0,
} as LocaleDisplayInfo
}

const totalWords = progressData[0].words.total
Expand All @@ -119,17 +134,11 @@ export const useLanguagePicker = (
? totalWords || 0
: dataItem?.words.approved || 0

const isBrowserDefault = browserLocales.includes(localeOption)

return {
localeOption,
...returnData,
approvalProgress,
sourceName: sourceName ?? "",
targetName: targetName ?? "",
englishName,
wordsApproved,
isBrowserDefault,
}
} as LocaleDisplayInfo
}

const displayNames: LocaleDisplayInfo[] =
Expand Down

0 comments on commit e5857aa

Please sign in to comment.