66 */
77
88import { getTranslationStatus , TranslationStatusInfo } from "@api/crowdin"
9- import { ElLoading , ElProgress , ProgressProps } from "element-plus"
10- import { defineComponent , onMounted , Ref , ref } from "vue"
9+ import { ElProgress , ProgressProps } from "element-plus"
10+ import { defineComponent } from "vue"
1111import localeMessages from "@i18n/message/common/locale"
1212import { t } from "@app/locale"
13+ import { useRequest } from "@app/hooks/useRequest"
1314
1415type SupportedLocale = timer . Locale | timer . TranslatingLocale
1516
@@ -39,6 +40,7 @@ const localeCrowdMap: { [locale in SupportedLocale]: string } = {
3940 vi : "vi" ,
4041 sk : "sk" ,
4142 mn : "mn" ,
43+ ar : "ar" ,
4244}
4345
4446const crowdLocaleMap : { [ locale : string ] : SupportedLocale } = { }
@@ -50,12 +52,14 @@ type ProgressInfo = {
5052 progress : number
5153}
5254
53- function convert2Info ( translationStatus : TranslationStatusInfo ) : ProgressInfo {
54- const { languageId, translationProgress } = translationStatus
55- return {
56- locale : crowdLocaleMap [ languageId ] || languageId ,
57- progress : translationProgress
58- }
55+ const convert2Info = ( { languageId, translationProgress } : TranslationStatusInfo ) : ProgressInfo => ( {
56+ locale : crowdLocaleMap [ languageId ] || languageId ,
57+ progress : translationProgress
58+ } satisfies ProgressInfo )
59+
60+ const compareLocale = ( { progress : pa , locale : la } : ProgressInfo , { progress : pb , locale : lb } : ProgressInfo ) : number => {
61+ const progressDiff = ( pb ?? 0 ) - ( pa ?? 0 )
62+ return progressDiff || la ?. localeCompare ?.( lb ) || 0
5963}
6064
6165function computeType ( progress : number ) : ProgressProps [ "status" ] {
@@ -70,27 +74,19 @@ function computeType(progress: number): ProgressProps["status"] {
7074
7175const CONTAINER_CLZ = 'progress-container'
7276
73- async function queryData ( listRef : Ref < ProgressInfo [ ] > ) {
74- const loading = ElLoading . service ( { target : `.${ CONTAINER_CLZ } ` , text : t ( msg => msg . helpUs . loading ) } )
77+ async function queryData ( ) : Promise < ProgressInfo [ ] > {
7578 const langList = await getTranslationStatus ( )
76- listRef . value = langList . map ( convert2Info )
77- . sort ( ( a , b ) => {
78- const progressDiff = b . progress - a . progress
79- if ( progressDiff === 0 ) {
80- return a . locale . localeCompare ( b . locale )
81- } else {
82- return progressDiff
83- }
84- } )
85- loading . close ( )
79+ return langList ?. map ?.( convert2Info ) ?. sort ( compareLocale )
8680}
8781
8882const _default = defineComponent ( ( ) => {
89- const list : Ref < ProgressInfo [ ] > = ref ( [ ] )
90- onMounted ( ( ) => queryData ( list ) )
83+ const { data : list } = useRequest (
84+ queryData ,
85+ { loadingTarget : `.${ CONTAINER_CLZ } ` , loadingText : t ( msg => msg . helpUs . loading ) } ,
86+ )
9187 return ( ) => (
9288 < div class = { CONTAINER_CLZ } >
93- { list . value . map ( ( { locale, progress } ) => (
89+ { list . value ? .map ?. ( ( { locale, progress } ) => (
9490 < ElProgress percentage = { progress } strokeWidth = { 22 } status = { computeType ( progress ) } >
9591 < span class = "progress-text" > { `${ progress } %` } </ span >
9692 < span class = "language-name" > { localeMessages [ locale ] ?. name || locale } </ span >
0 commit comments