Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 32 additions & 31 deletions app/[locale]/download/components/DownloadWebgalTerre.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import Button from '@/components/Button/Button'
import useWebgalTerreAssets from '@/hooks/useWebgalTerreAssets'
import Link from 'next/link'
import {RiGithubFill, RiMicrosoftFill, RiAppleFill, RiUbuntuFill} from 'react-icons/ri'
import { RiGithubFill, RiMicrosoftFill, RiAppleFill, RiUbuntuFill, RiAndroidFill } from 'react-icons/ri'
import styles from '../Download.module.css'
import {useLocale, useTranslations} from 'next-intl'
import {i18n} from '@/i18n'
import { useLocale, useTranslations } from 'next-intl'
import { i18n } from '@/i18n'

const DownloadWebgalTerre = () => {

Expand All @@ -28,20 +28,21 @@ const DownloadWebgalTerre = () => {
: null

const platformMap = [
{platform: 'windows', icon: <RiMicrosoftFill/>, label: t('downloadWindows')},
{platform: 'windowsSetup', icon: <RiMicrosoftFill/>, label: t('downloadWindowsSetup')},
{platform: 'windowsArm64', icon: <RiMicrosoftFill/>, label: t('downloadWindowsArm64')},
{platform: 'windowsArm64Setup', icon: <RiMicrosoftFill/>, label: t('downloadWindowsArm64Setup')},
{platform: 'macos', icon: <RiAppleFill/>, label: t('downloadMacos')},
{platform: 'linux', icon: <RiUbuntuFill/>, label: t('downloadLinux')},
{platform: 'linuxArm64', icon: <RiUbuntuFill/>, label: t('downloadLinuxArm64')},
{ platform: 'windows', icon: <RiMicrosoftFill />, label: t('downloadWindows') },
{ platform: 'windowsSetup', icon: <RiMicrosoftFill />, label: t('downloadWindowsSetup') },
{ platform: 'windowsArm64', icon: <RiMicrosoftFill />, label: t('downloadWindowsArm64') },
{ platform: 'windowsArm64Setup', icon: <RiMicrosoftFill />, label: t('downloadWindowsArm64Setup') },
{ platform: 'macos', icon: <RiAppleFill />, label: t('downloadMacos') },
{ platform: 'linux', icon: <RiUbuntuFill />, label: t('downloadLinux') },
{ platform: 'linuxArm64', icon: <RiUbuntuFill />, label: t('downloadLinuxArm64') },
{ platform: 'android', icon: <RiAndroidFill />, label: t('downloadAndroid') }
]

const downloadUrls = webgalTerreAssets?.downloadUrl
.map((item) => {
const test = platformMap.find(platform => item.platform === platform.platform)
if (test)
return {url: item.url, ...test}
return { url: item.url, ...test }
})
Comment on lines 41 to 46

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation using .map() can result in an array containing undefined values, which are then implicitly handled later when rendering. This can be made more robust and readable. Additionally, the variable name test is not descriptive.

A better approach is to use .flatMap(). This will map and filter in a single step, resulting in a clean array without any undefined values. It also provides an opportunity to use a more descriptive variable name like matchingPlatform.

This is more concise and clearly expresses the intent of creating a new array with only the matching, transformed items.

  const downloadUrls = webgalTerreAssets?.downloadUrl
    .flatMap((item) => {
      const matchingPlatform = platformMap.find(platform => item.platform === platform.platform)
      return matchingPlatform ? [{ url: item.url, ...matchingPlatform }] : []
    })


const isZh = locale === 'zh-cn'
Expand All @@ -63,44 +64,44 @@ const DownloadWebgalTerre = () => {
<p><strong>{t('releaseNote')}:</strong> {!(releaseNote) && t('fetching')}</p>
{
releaseNote &&
< div dangerouslySetInnerHTML={{__html: releaseNote}} className={styles['release-note']}/>
< div dangerouslySetInnerHTML={{ __html: releaseNote }} className={styles['release-note']} />
}
</div>
</div>
<div className={styles['card-button-gourp']}>
<Button terre>
<Link href={webgalTerreUrl} target={'_blank'}><RiGithubFill/>{t('gitHubReleases')}</Link>
<Link href={webgalTerreUrl} target={'_blank'}><RiGithubFill />{t('gitHubReleases')}</Link>
</Button>
{
downloadUrls &&
downloadUrls.map((item) =>
item?.url &&
<Button terre key={item.platform}>
<Link href={item.url} target='_top'>{item.icon}{item.label}</Link>
</Button>
<Button terre key={item.platform}>
<Link href={item.url} target='_top'>{item.icon}{item.label}</Link>
</Button>
)
}

</div>
{
isZh && downloadUrls && <div className={styles.cndownload}>
{/*<details className='space-y-4'>*/}
<div className='text-terre select-none'>
{t('otherDownloadLinkInfo')}
</div>
<div className={styles['card-button-gourp']}>
{
downloadUrls &&
downloadUrls.map((item) =>
item?.url &&
<Button terre key={item.platform}>
<Link href={ghproxyStr + item.url} target='_top'>{item.icon}{item.label}</Link>
</Button>
)
}
</div>
{/*</details>*/}
<div className='text-terre select-none'>
{t('otherDownloadLinkInfo')}
</div>
<div className={styles['card-button-gourp']}>
{
downloadUrls &&
downloadUrls.map((item) =>
item?.url &&
<Button terre key={item.platform}>
<Link href={ghproxyStr + item.url} target='_top'>{item.icon}{item.label}</Link>
</Button>
)
}
</div>
{/*</details>*/}
</div>
}
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion hooks/useWebgalTerreAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const useWebgalTerreAssets = (webgalTerreApiUrl: string) => {
{ platform: 'macos', url: findAssetsUrl(data.assets, 'mac.*.zip') },
{ platform: 'linux', url: findAssetsUrl(data.assets, 'Linux.*.zip') },
{ platform: 'linuxArm64', url: findAssetsUrl(data.assets, 'Linux_Arm64.*.zip') },
{ platform: 'android', url: findAssetsUrl(data.assets, 'Android.*.apk') }
]

}
))
} catch (error) {
Expand Down
5 changes: 3 additions & 2 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
},
"multiplatform": {
"title": "Multi Platform",
"line0": "WebGAL Terre support Windows / macOS / Linux",
"line0": "WebGAL Terre support Windows / macOS / Linux / android",
"line1": "Export game support Web / Windows / macOS / Linux / android"
}
},
Expand All @@ -95,6 +95,7 @@
"downloadMacos": "Download macOS zip",
"downloadLinux": "Download Linux zip",
"downloadLinuxArm64": "Download Linux Arm64 zip",
"downloadAndroid": "Download Android apk",
"otherDownloadLink": "Other Download Link",
"otherDownloadLinkInfo": "If the above download address is slow, please try using the following download address",
"systemRequirements": {
Expand Down Expand Up @@ -145,4 +146,4 @@
"bilibili": "Bilibili",
"links": "Links"
}
}
}
5 changes: 3 additions & 2 deletions locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
},
"multiplatform": {
"title": "マルチプラットフォームのサポート",
"line0": "WebGAL Terre が Windows / macOS / Linux での開発をサポート",
"line0": "WebGAL Terre が Windows / macOS / Linux / android での開発をサポート",
"line1": "開発したゲームは Web / Windows / macOS / Linux / Android でプレイできる"
}
},
Expand All @@ -95,6 +95,7 @@
"downloadMacos": "macOS zip をダウンロード",
"downloadLinux": "Linux zip をダウンロード",
"downloadLinuxArm64": "Linux Arm64 zip をダウンロード",
"downloadAndroid": "Android apk をダウンロード",
"otherDownloadLink": "その他のダウンロードリンク",
"otherDownloadLinkInfo": "上記のダウンロードリンクが遅い場合は、以下のダウンロードリンクをお試しください",
"systemRequirements": {
Expand Down Expand Up @@ -145,4 +146,4 @@
"bilibili": "Bilibili",
"links": "フレンドリーリンク"
}
}
}
5 changes: 3 additions & 2 deletions locales/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
},
"multiplatform": {
"title": "多平台支持",
"line0": "WebGAL Terre 支持 Windows / macOS / Linux",
"line0": "WebGAL Terre 支持 Windows / macOS / Linux / android",
"line1": "导出游戏支持 Web / Windows / macOS / Linux / android"
}
},
Expand All @@ -95,6 +95,7 @@
"downloadMacos": "下载 macOS 压缩包",
"downloadLinux": "下载 Linux 压缩包",
"downloadLinuxArm64": "下载 Linux Arm64 压缩包",
"downloadAndroid": "下载 Android apk",
"otherDownloadLink": "其它下载地址",
"otherDownloadLinkInfo": "如果上面的下载地址下载速度比较慢,请尝试使用以下下载地址",
"systemRequirements": {
Expand Down Expand Up @@ -145,4 +146,4 @@
"bilibili": "哔哩哔哩",
"links": "友情链接"
}
}
}