Skip to content

Commit 87316e8

Browse files
author
Alberto Iannaccone
committed
refactor ide updater dialog: move buttons outside the dialog content
1 parent 73d46c2 commit 87316e8

File tree

3 files changed

+208
-184
lines changed

3 files changed

+208
-184
lines changed

Diff for: arduino-ide-extension/src/browser/dialogs/ide-updater/ide-updater-component.tsx

+22-90
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { WindowService } from '@theia/core/lib/browser/window/window-service';
21
import { nls } from '@theia/core/lib/common';
32
import { shell } from 'electron';
43
import * as React from '@theia/core/shared/react';
@@ -7,36 +6,32 @@ import ReactMarkdown from 'react-markdown';
76
import { ProgressInfo, UpdateInfo } from '../../../common/protocol/ide-updater';
87
import ProgressBar from '../../components/ProgressBar';
98

10-
export type IDEUpdaterComponentProps = {
11-
updateInfo: UpdateInfo;
12-
windowService: WindowService;
9+
export type UpdateProgress = {
10+
progressInfo?: ProgressInfo | undefined;
1311
downloadFinished?: boolean;
1412
downloadStarted?: boolean;
15-
progress?: ProgressInfo;
1613
error?: Error;
17-
onDownload: () => void;
18-
onClose: () => void;
19-
onSkipVersion: () => void;
20-
onCloseAndInstall: () => void;
14+
};
15+
16+
export type IDEUpdaterComponentProps = {
17+
updateInfo: UpdateInfo;
18+
updateProgress: UpdateProgress;
2119
};
2220

2321
export const IDEUpdaterComponent = ({
24-
updateInfo: { version, releaseNotes },
25-
downloadStarted = false,
26-
downloadFinished = false,
27-
windowService,
28-
progress,
29-
error,
30-
onDownload,
31-
onClose,
32-
onSkipVersion,
33-
onCloseAndInstall,
22+
updateInfo,
23+
updateProgress: {
24+
downloadStarted = false,
25+
downloadFinished = false,
26+
progressInfo,
27+
error,
28+
},
3429
}: IDEUpdaterComponentProps): React.ReactElement => {
35-
const changelogDivRef = React.useRef() as React.MutableRefObject<
36-
HTMLDivElement
37-
>;
30+
const { version, releaseNotes } = updateInfo;
31+
const changelogDivRef =
32+
React.useRef() as React.MutableRefObject<HTMLDivElement>;
3833
React.useEffect(() => {
39-
if (!!releaseNotes) {
34+
if (!!releaseNotes && changelogDivRef.current) {
4035
let changelog: string;
4136
if (typeof releaseNotes === 'string') changelog = releaseNotes;
4237
else
@@ -58,12 +53,7 @@ export const IDEUpdaterComponent = ({
5853
changelogDivRef.current
5954
);
6055
}
61-
}, [releaseNotes]);
62-
const closeButton = (
63-
<button onClick={onClose} type="button" className="theia-button secondary">
64-
{nls.localize('arduino/ide-updater/notNowButton', 'Not now')}
65-
</button>
66-
);
56+
}, [updateInfo]);
6757

6858
const DownloadCompleted: () => React.ReactElement = () => (
6959
<div className="ide-updater-dialog--downloaded">
@@ -80,19 +70,6 @@ export const IDEUpdaterComponent = ({
8070
'Close the software and install the update on your machine.'
8171
)}
8272
</div>
83-
<div className="buttons-container">
84-
{closeButton}
85-
<button
86-
onClick={onCloseAndInstall}
87-
type="button"
88-
className="theia-button close-and-install"
89-
>
90-
{nls.localize(
91-
'arduino/ide-updater/closeAndInstallButton',
92-
'Close and Install'
93-
)}
94-
</button>
95-
</div>
9673
</div>
9774
);
9875

@@ -104,7 +81,7 @@ export const IDEUpdaterComponent = ({
10481
'Downloading the latest version of the Arduino IDE.'
10582
)}
10683
</div>
107-
<ProgressBar percent={progress?.percent} showPercentage />
84+
<ProgressBar percent={progressInfo?.percent} showPercentage />
10885
</div>
10986
);
11087

@@ -130,46 +107,14 @@ export const IDEUpdaterComponent = ({
130107
)}
131108
</div>
132109
{releaseNotes && (
133-
<div className="dialogRow">
134-
<div className="changelog-container" ref={changelogDivRef} />
110+
<div className="dialogRow changelog-container">
111+
<div className="changelog" ref={changelogDivRef} />
135112
</div>
136113
)}
137-
<div className="buttons-container">
138-
<button
139-
onClick={onSkipVersion}
140-
type="button"
141-
className="theia-button secondary skip-version"
142-
>
143-
{nls.localize(
144-
'arduino/ide-updater/skipVersionButton',
145-
'Skip Version'
146-
)}
147-
</button>
148-
<div className="push"></div>
149-
{closeButton}
150-
<button
151-
onClick={onDownload}
152-
type="button"
153-
className="theia-button primary"
154-
>
155-
{nls.localize('arduino/ide-updater/downloadButton', 'Download')}
156-
</button>
157-
</div>
158114
</div>
159115
</div>
160116
);
161117

162-
const onGoToDownloadClick = (
163-
event: React.SyntheticEvent<HTMLAnchorElement, Event>
164-
) => {
165-
const { target } = event.nativeEvent;
166-
if (target instanceof HTMLAnchorElement) {
167-
event.nativeEvent.preventDefault();
168-
windowService.openNewWindow(target.href, { external: true });
169-
onClose();
170-
}
171-
};
172-
173118
const GoToDownloadPage: () => React.ReactElement = () => (
174119
<div className="ide-updater-dialog--go-to-download-page">
175120
<div>
@@ -178,19 +123,6 @@ export const IDEUpdaterComponent = ({
178123
"An update for the Arduino IDE is available, but we're not able to download and install it automatically. Please go to the download page and download the latest version from there."
179124
)}
180125
</div>
181-
<div className="buttons-container">
182-
{closeButton}
183-
<a
184-
className="theia-button primary"
185-
href="https://www.arduino.cc/en/software#experimental-software"
186-
onClick={onGoToDownloadClick}
187-
>
188-
{nls.localize(
189-
'arduino/ide-updater/goToDownloadButton',
190-
'Go To Download'
191-
)}
192-
</a>
193-
</div>
194126
</div>
195127
);
196128

0 commit comments

Comments
 (0)