Skip to content

Commit 747a9a9

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

File tree

4 files changed

+215
-185
lines changed

4 files changed

+215
-185
lines changed

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

+20-92
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,33 @@
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';
54
import * as ReactDOM from '@theia/core/shared/react-dom';
65
import ReactMarkdown from 'react-markdown';
7-
import { ProgressInfo, UpdateInfo } from '../../../common/protocol/ide-updater';
6+
import {
7+
UpdateInfo,
8+
UpdateProgress,
9+
} from '../../../common/protocol/ide-updater';
810
import ProgressBar from '../../components/ProgressBar';
911

1012
export type IDEUpdaterComponentProps = {
1113
updateInfo: UpdateInfo;
12-
windowService: WindowService;
13-
downloadFinished?: boolean;
14-
downloadStarted?: boolean;
15-
progress?: ProgressInfo;
16-
error?: Error;
17-
onDownload: () => void;
18-
onClose: () => void;
19-
onSkipVersion: () => void;
20-
onCloseAndInstall: () => void;
14+
updateProgress: UpdateProgress;
2115
};
2216

2317
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,
18+
updateInfo,
19+
updateProgress: {
20+
downloadStarted = false,
21+
downloadFinished = false,
22+
progressInfo,
23+
error,
24+
},
3425
}: IDEUpdaterComponentProps): React.ReactElement => {
35-
const changelogDivRef = React.useRef() as React.MutableRefObject<
36-
HTMLDivElement
37-
>;
26+
const { version, releaseNotes } = updateInfo;
27+
const changelogDivRef =
28+
React.useRef() as React.MutableRefObject<HTMLDivElement>;
3829
React.useEffect(() => {
39-
if (!!releaseNotes) {
30+
if (!!releaseNotes && changelogDivRef.current) {
4031
let changelog: string;
4132
if (typeof releaseNotes === 'string') changelog = releaseNotes;
4233
else
@@ -58,12 +49,7 @@ export const IDEUpdaterComponent = ({
5849
changelogDivRef.current
5950
);
6051
}
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-
);
52+
}, [updateInfo]);
6753

6854
const DownloadCompleted: () => React.ReactElement = () => (
6955
<div className="ide-updater-dialog--downloaded">
@@ -80,19 +66,6 @@ export const IDEUpdaterComponent = ({
8066
'Close the software and install the update on your machine.'
8167
)}
8268
</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>
9669
</div>
9770
);
9871

@@ -104,7 +77,7 @@ export const IDEUpdaterComponent = ({
10477
'Downloading the latest version of the Arduino IDE.'
10578
)}
10679
</div>
107-
<ProgressBar percent={progress?.percent} showPercentage />
80+
<ProgressBar percent={progressInfo?.percent} showPercentage />
10881
</div>
10982
);
11083

@@ -130,46 +103,14 @@ export const IDEUpdaterComponent = ({
130103
)}
131104
</div>
132105
{releaseNotes && (
133-
<div className="dialogRow">
134-
<div className="changelog-container" ref={changelogDivRef} />
106+
<div className="dialogRow changelog-container">
107+
<div className="changelog" ref={changelogDivRef} />
135108
</div>
136109
)}
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>
158110
</div>
159111
</div>
160112
);
161113

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-
173114
const GoToDownloadPage: () => React.ReactElement = () => (
174115
<div className="ide-updater-dialog--go-to-download-page">
175116
<div>
@@ -178,19 +119,6 @@ export const IDEUpdaterComponent = ({
178119
"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."
179120
)}
180121
</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>
194122
</div>
195123
);
196124

0 commit comments

Comments
 (0)