Skip to content

Commit ad4d8b5

Browse files
authored
[FIX] Wrong info on Download Manager (#1066)
* [FIX] Wrong info on Download Manager * chore: simplify date logic * fix: lint * fix: stuck size after download * ui: show download chart only when running and on downloading tab * chore: use variable * fix: qa comments * chore: add labels for empty queue and finished * fix: wrong size on downloaded item * feat: add clear button * ui: show clear button only on downloaded tab * i18n: updated keys --------- Co-authored-by: Flavio F Lima <flavioislima@users.noreply.github.com>
1 parent f39c2f2 commit ad4d8b5

File tree

7 files changed

+75
-73
lines changed

7 files changed

+75
-73
lines changed

public/locales/en/translation.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,11 @@
792792
"queue": {
793793
"label": {
794794
"canceled": "Canceled",
795-
"empty": "Nothing to download",
795+
"clear": "Clear List",
796+
"empty": {
797+
"finished": "Nothing downloaded",
798+
"queue": "Nothing to download"
799+
},
796800
"pause": "Pause download",
797801
"remove": "Remove from Downloads",
798802
"resume": "Resume download"

src/frontend/helpers/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ const getStoreName = (runner: Runner, other: string) => {
126126
return 'Epic Games'
127127
case 'gog':
128128
return 'GOG'
129+
case 'hyperplay':
130+
return 'HyperPlay'
129131
default:
130132
return other
131133
}

src/frontend/screens/DownloadManager/components/DownloadManagerItem/index.tsx

+16-13
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ type Props = {
3434
state?: DownloadManagerState
3535
}
3636

37-
const options: Intl.DateTimeFormatOptions = {
38-
hour: 'numeric',
39-
minute: 'numeric'
40-
}
41-
4237
function convertToTime(time: number) {
4338
const date = time ? new Date(time) : new Date()
44-
const hour = new Intl.DateTimeFormat(undefined, options).format(date)
45-
return { hour, fullDate: date.toLocaleString() }
39+
const fullDate = new Intl.DateTimeFormat(undefined, {
40+
year: 'numeric',
41+
month: 'numeric',
42+
day: 'numeric',
43+
hour: 'numeric',
44+
minute: 'numeric'
45+
}).format(date)
46+
return { fullDate }
4647
}
4748

4849
type InstallInfo =
@@ -85,7 +86,8 @@ const DownloadManagerItem = observer(({ element, current, state }: Props) => {
8586
path,
8687
gameInfo: DmGameInfo,
8788
size,
88-
platformToInstall
89+
platformToInstall,
90+
channelName
8991
} = params
9092

9193
const [gameInfo, setGameInfo] = useState(DmGameInfo)
@@ -99,11 +101,12 @@ const DownloadManagerItem = observer(({ element, current, state }: Props) => {
99101
const getNewInfo = async () => {
100102
const newInfo = (await getGameInfo(appName, runner)) as GameInfo
101103

102-
if (size?.includes('?') && !installInfo) {
104+
if (!installInfo) {
103105
const installInfo = await getInstallInfo(
104106
appName,
105107
runner,
106-
platformToInstall
108+
platformToInstall,
109+
channelName
107110
)
108111
setInstallInfo(installInfo)
109112
}
@@ -113,7 +116,7 @@ const DownloadManagerItem = observer(({ element, current, state }: Props) => {
113116
}
114117
}
115118
getNewInfo()
116-
}, [element])
119+
}, [element, current, state])
117120

118121
const {
119122
art_cover,
@@ -242,7 +245,7 @@ const DownloadManagerItem = observer(({ element, current, state }: Props) => {
242245
update: t2('download-manager.install-type.update', 'Update')
243246
}
244247

245-
const { hour, fullDate } = getTime()
248+
const { fullDate } = getTime()
246249

247250
return (
248251
<>
@@ -277,7 +280,7 @@ const DownloadManagerItem = observer(({ element, current, state }: Props) => {
277280
</span>
278281
</span>
279282
</td>
280-
<td title={fullDate}>{hour}</td>
283+
<td title={fullDate}>{fullDate}</td>
281284
<td>{translatedTypes[type]}</td>
282285
<td>{getStoreName(runner, t2('Other'))}</td>
283286
<td>

src/frontend/screens/DownloadManager/components/DownloadTable/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ export function DownloadTable({
2020
return (
2121
<table className={styles.dmItemList}>
2222
<DownloadManagerHeader time={time} />
23-
{elements.map((el, key) => (
23+
{elements.map((el) => (
2424
<DownloadManagerItem
25-
key={key}
25+
key={el.params.appName}
2626
element={el}
2727
current={!!isCurrent}
2828
state={state}

src/frontend/screens/DownloadManager/components/ProgressHeader/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export default function ProgressHeader(props: {
104104
</div>
105105
</div>
106106
</div>
107-
{showDownloadBar && (
107+
{showDownloadBar ? (
108108
<div className="downloadBar">
109109
<div className="downloadProgressStats">
110110
<p className="downloadStat" color="var(--text-default)">{`${
@@ -132,7 +132,7 @@ export default function ProgressHeader(props: {
132132
</div>
133133
</div>
134134
</div>
135-
)}
135+
) : null}
136136
</>
137137
)
138138
}
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,3 @@
1-
.dmItemList > .gameListHeader {
2-
padding: var(--space-md) 0;
3-
grid-template-columns: 2fr 1fr 1fr 1fr 10%;
4-
margin: 0 var(--space-sm-fixed);
5-
}
6-
7-
.downloadManager
8-
> .MuiTabs-root
9-
> .MuiTabs-scroller
10-
> .MuiTabs-flexContainer
11-
> .MuiTab-root {
12-
color: var(--text-default);
13-
}
14-
15-
.downloadManager
16-
> .MuiTabs-root
17-
> .MuiTabs-scroller
18-
> .MuiTabs-flexContainer
19-
> .Mui-selected {
20-
color: var(--accent);
21-
}
22-
23-
.downloadManager > .MuiTabs-root > .MuiTabs-scroller > .MuiTabs-indicator {
24-
background-color: var(--accent);
25-
}
26-
27-
.downloadManager {
28-
padding: 0;
29-
margin: 0;
30-
}
31-
32-
.downloadManagerCurrentSectionTitle {
33-
margin: 0px 0px 0px 0px;
34-
text-align: initial;
35-
padding-left: 30px;
36-
}
37-
38-
.downloadManagerQueuedSectionTitle {
39-
margin: 30px 0px 0px 0px;
40-
text-align: initial;
41-
}
42-
431
.tabsList {
442
margin: var(--space-2lg-fixed) 0px;
453
}
@@ -51,3 +9,13 @@
519
.title {
5210
text-align: left;
5311
}
12+
13+
.empty {
14+
text-align: center;
15+
margin-top: var(--space-2lg-fixed);
16+
}
17+
18+
.clearButton {
19+
position: absolute;
20+
right: var(--space-xl-fixed);
21+
}

src/frontend/screens/DownloadManager/index.tsx

+38-13
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
import React, { useEffect, useState } from 'react'
22
import { useTranslation } from 'react-i18next'
33
import { DMQueueElement, DownloadManagerState } from 'common/types'
4-
import { UpdateComponent } from 'frontend/components/UI'
54
import ProgressHeader from './components/ProgressHeader'
65
import { DMQueue } from 'frontend/types'
7-
import { Background, Tabs, getTabsClassNames } from '@hyperplay/ui'
6+
import { Background, Button, Tabs, getTabsClassNames } from '@hyperplay/ui'
87
import styles from './index.module.scss'
98
import { DownloadTable } from './components/DownloadTable'
9+
import { downloadManagerStore } from 'frontend/helpers/electronStores'
10+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
11+
import { faTrash } from '@fortawesome/free-solid-svg-icons'
1012

1113
export default React.memo(function DownloadManager(): JSX.Element | null {
1214
const { t } = useTranslation()
13-
const [refreshing, setRefreshing] = useState(false)
1415
const [state, setState] = useState<DownloadManagerState>('idle')
1516
const [queuedElements, setQueuedElements] = useState<DMQueueElement[]>([])
1617
const [currentElement, setCurrentElement] = useState<DMQueueElement>()
1718
const [finishedElem, setFinishedElem] = useState<DMQueueElement[]>()
19+
const [activeTab, setActiveTab] = useState<string | null>('downloading')
1820

1921
const appName = currentElement?.params?.appName ?? ''
2022

2123
useEffect(() => {
22-
setRefreshing(true)
2324
window.api.getDMQueueInformation().then(({ elements, state }: DMQueue) => {
2425
setCurrentElement(elements[0])
2526
setQueuedElements([...elements.slice(1)])
26-
setRefreshing(false)
2727
setState(state)
2828
})
2929

@@ -44,7 +44,7 @@ export default React.memo(function DownloadManager(): JSX.Element | null {
4444
return () => {
4545
removeHandleDMQueueInformation()
4646
}
47-
}, [])
47+
}, [finishedElem])
4848

4949
useEffect(() => {
5050
window.api.getDMQueueInformation().then(({ finished }: DMQueue) => {
@@ -57,10 +57,6 @@ export default React.memo(function DownloadManager(): JSX.Element | null {
5757
window.api.trackScreen('Download Manager')
5858
}, [])
5959

60-
if (refreshing) {
61-
return <UpdateComponent />
62-
}
63-
6460
const doneElements =
6561
(finishedElem?.length &&
6662
finishedElem.sort((a, b) => {
@@ -69,6 +65,13 @@ export default React.memo(function DownloadManager(): JSX.Element | null {
6965
})) ||
7066
[]
7167

68+
const handleClearList = () => {
69+
setFinishedElem([])
70+
downloadManagerStore.set('finished', [])
71+
}
72+
73+
const showClearListButton = activeTab === 'downloaded'
74+
7275
/*
7376
Other Keys:
7477
t('queue.label.empty', 'Nothing to download')
@@ -79,17 +82,29 @@ export default React.memo(function DownloadManager(): JSX.Element | null {
7982
return (
8083
<>
8184
<Background style={{ position: 'absolute' }}></Background>
82-
<div className="contentContainer">
85+
<div className={'contentContainer'}>
8386
<h3 className={styles.title}>
8487
{t('download-manager.title_dm', 'Download Manager')}
8588
</h3>
8689
<Tabs
87-
defaultValue="downloading"
90+
value={activeTab}
91+
onChange={setActiveTab}
8892
classNames={getTabsClassNames(
8993
{ list: styles.tabsList, panel: styles.tabsPanel },
9094
{ list: 'outline' }
9195
)}
9296
>
97+
{showClearListButton ? (
98+
<Button
99+
className={styles.clearButton}
100+
onClick={() => handleClearList()}
101+
type="tertiary"
102+
leftIcon={<FontAwesomeIcon icon={faTrash} />}
103+
size="small"
104+
>
105+
{t('queue.label.clear', 'Clear List')}
106+
</Button>
107+
) : null}
93108
<Tabs.List>
94109
<Tabs.Tab value="downloading">Downloading</Tabs.Tab>
95110
<Tabs.Tab value="queued">Queued</Tabs.Tab>
@@ -111,22 +126,32 @@ export default React.memo(function DownloadManager(): JSX.Element | null {
111126
/>
112127
</div>
113128
</div>
129+
<ProgressHeader state={state} appName={appName} />
114130
</Tabs.Panel>
115131

116132
<Tabs.Panel value="queued">
117133
<div className={styles.dmItemList}>
118134
<DownloadTable elements={queuedElements} time="queued" />
135+
{queuedElements.length === 0 && (
136+
<h5 className={styles.empty}>
137+
{t('queue.label.empty.queue', 'Nothing to download')}
138+
</h5>
139+
)}
119140
</div>
120141
</Tabs.Panel>
121142
<Tabs.Panel value="downloaded">
122143
<div className={styles.downloadManager}>
123144
<div className={styles.downloadList}>
124145
<DownloadTable elements={doneElements} time="finished" />
146+
{doneElements.length === 0 && (
147+
<h5 className={styles.empty}>
148+
{t('queue.label.empty.finished', 'Nothing downloaded')}
149+
</h5>
150+
)}
125151
</div>
126152
</div>
127153
</Tabs.Panel>
128154
</Tabs>
129-
<ProgressHeader state={state} appName={appName} />
130155
</div>
131156
</>
132157
)

0 commit comments

Comments
 (0)