A games launcher for GOG, Amazon and Epic Games for Linux, Windows and macOS.
TypeScript amazon-primeelectronepic-games-launcherepic-games-storeepic-storegaminggoggog-galaxyheroic-games-launcherlinuxplay-gamesprotonsteamwine
import React from 'react'
import ToggleSwitch from 'frontend/components/UI/ToggleSwitch'
import SettingsCard from 'frontend/components/UI/SettingsCard'
import { useTranslation } from 'react-i18next'
import { DLCInfo } from 'common/types/legendary'
import { DlcMasterState, getDlcMasterState, toggleAllDlcs } from './installTabs'
interface Props {
DLCList: DLCInfo[]
dlcsToInstall: string[]
setDlcsToInstall: (dlcs: string[]) => void
}
const DLCDownloadListing: React.FC<Props> = ({
DLCList,
setDlcsToInstall,
dlcsToInstall
}) => {
const { t } = useTranslation()
if (!DLCList) {
return null
}
const allIds = DLCList.map(({ app_name }) => app_name)
const masterState: DlcMasterState = getDlcMasterState(dlcsToInstall, allIds)
const handleAllDlcs = () => {
setDlcsToInstall(toggleAllDlcs(masterState, allIds))
}
const handleDlcToggle = (appName: string) => {
const newDlcsToInstall = [...dlcsToInstall]
if (newDlcsToInstall.includes(appName)) {
newDlcsToInstall.splice(newDlcsToInstall.indexOf(appName), 1)
} else {
newDlcsToInstall.push(appName)
}
setDlcsToInstall(newDlcsToInstall)
}
return (
<SettingsCard title={t('install.dlc.title', 'Select to install')}>
<div className="InstallModal__dlcMaster">
<ToggleSwitch
htmlId="allDlcsSwitch"
value={masterState === 'all'}
indeterminate={masterState === 'partial'}
handleChange={handleAllDlcs}
title={t('dlc.installDlcs', 'Install all DLCs')}
description={t(
'install.dlc.selectAllDescription',
'Install every DLC available for this game.'
)}
/>
</div>
<div className="InstallModal__dlcsList">
{DLCList.map(({ title, app_name }) => (
<ToggleSwitch
key={app_name}
htmlId={`dlcSelector-${app_name}`}
value={dlcsToInstall.includes(app_name)}
title={title}
handleChange={() => handleDlcToggle(app_name)}
/>
))}
</div>
</SettingsCard>
)
}
export default DLCDownloadListing