Skip to content

Commit 1761811

Browse files
committed
improved loading ux
1 parent 0aeb61c commit 1761811

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/components/DockerSetup.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// ============================================================================
44

55
import type { SelectOption } from '@opentui/core';
6+
import { useKeyboard } from '@opentui/react';
67
import { useEffect, useMemo, useState } from 'react';
78
import {
89
checkDockerStatus,
@@ -176,6 +177,12 @@ export function DockerSetup({
176177
onComplete({ type: 'cancelled' });
177178
};
178179

180+
useKeyboard((key) => {
181+
if (key.name === 'escape') {
182+
handleCancel();
183+
}
184+
});
185+
179186
// ---- Checking State ----
180187
if (state.type === 'checking') {
181188
return (
@@ -199,9 +206,12 @@ export function DockerSetup({
199206
padding: 1,
200207
flexDirection: 'column',
201208
flexGrow: 1,
209+
alignItems: 'center',
210+
justifyContent: 'center',
202211
}}
203212
>
204-
<text style={{ fg: '#00cc00' }}>Docker is running!</text>
213+
<text style={{ fg: '#0c0' }}>Docker is running!</text>
214+
<text style={{ fg: '#555555', marginTop: 1 }}>Press Esc to exit</text>
205215
</box>
206216
</box>
207217
);
@@ -214,7 +224,8 @@ export function DockerSetup({
214224
return (
215225
<Loading
216226
title={title}
217-
message={`${state.message}\nThis may take a minute while ${providerName} initializes`}
227+
message={state.message}
228+
detail={`This may take a minute while ${providerName} initializes`}
218229
onCancel={handleCancel}
219230
/>
220231
);
@@ -227,7 +238,8 @@ export function DockerSetup({
227238
return (
228239
<Loading
229240
title={title}
230-
message={`Installing ${providerName}...\nThis may take a few minutes.`}
241+
message={`Installing ${providerName}`}
242+
detail="This may take a few minutes."
231243
onCancel={handleCancel}
232244
/>
233245
);
@@ -245,6 +257,8 @@ export function DockerSetup({
245257
padding: 1,
246258
flexDirection: 'column',
247259
flexGrow: 1,
260+
alignItems: 'center',
261+
justifyContent: 'center',
248262
}}
249263
>
250264
<text style={{ fg: '#ff4444' }}>Error: {state.message}</text>

src/components/Loading.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import { useKeyboard } from '@opentui/react';
2-
import { useEffect, useState } from 'react';
2+
import { useEffect, useRef, useState } from 'react';
33

44
export interface LoadingProps {
55
title?: string;
66
message?: string;
7+
detail?: string;
78
onCancel: () => void;
89
}
910

1011
export function Loading({
1112
title = 'Loading',
1213
message = 'Please wait',
14+
detail,
1315
onCancel,
1416
}: LoadingProps) {
17+
const count = useRef(0);
1518
const [dots, setDots] = useState('');
1619

1720
useKeyboard((key) => {
@@ -22,7 +25,8 @@ export function Loading({
2225

2326
useEffect(() => {
2427
const interval = setInterval(() => {
25-
setDots((d) => (d.length >= 3 ? '' : `${d}.`));
28+
count.current += 1;
29+
setDots('.'.repeat(count.current % 4).padEnd(3, ' '));
2630
}, 300);
2731
return () => clearInterval(interval);
2832
}, []);
@@ -37,13 +41,16 @@ export function Loading({
3741
padding: 1,
3842
flexDirection: 'column',
3943
flexGrow: 1,
44+
alignItems: 'center',
45+
justifyContent: 'center',
4046
}}
4147
>
42-
<text style={{ fg: '#888888' }}>
48+
<text style={{ fg: '#eee' }}>
4349
{message}
4450
{dots}
4551
</text>
46-
<text style={{ fg: '#555555', marginTop: 1 }}>Press Esc to cancel</text>
52+
{detail && <text style={{ fg: '#888', marginTop: 1 }}>{detail}</text>}
53+
<text style={{ fg: '#555', marginTop: 1 }}>Press Esc to cancel</text>
4754
</box>
4855
</box>
4956
);

0 commit comments

Comments
 (0)