Skip to content

Commit d9ec4c0

Browse files
committed
Refactor all modal components to utilize the standardized Modal component structure by passing title, content_slot, and footer_slot props
1 parent 3078aea commit d9ec4c0

12 files changed

Lines changed: 175 additions & 182 deletions

File tree

‎packages/ui/src/components/editor/panel/modals/ChatInitializedModal/ChatInitializedModal.module.scss‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
.title {
2-
text-align: center;
3-
}
4-
5-
.container {
6-
display: flex;
7-
flex-direction: column;
8-
gap: var(--padding-12px);
9-
}
10-
111
.progress {
122
width: 100%;
133
height: 2px;

‎packages/ui/src/components/editor/panel/modals/ChatInitializedModal/ChatInitializedModal.tsx‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ export const ChatInitializedModal: React.FC<Props> = (props) => {
2828
}, [props.duration, props.on_close])
2929

3030
return (
31-
<Modal>
32-
<div className={styles.container}>
33-
<div className={styles.title}>{props.title}</div>
31+
<Modal
32+
title={props.title}
33+
content_slot={
3434
<div className={styles.progress}>
3535
<div
3636
className={styles.progress__fill}
@@ -40,10 +40,12 @@ export const ChatInitializedModal: React.FC<Props> = (props) => {
4040
}}
4141
/>
4242
</div>
43+
}
44+
footer_slot={
4345
<Button on_click={props.on_close} is_focused={true}>
4446
Close
4547
</Button>
46-
</div>
47-
</Modal>
48+
}
49+
/>
4850
)
4951
}

‎packages/ui/src/components/editor/panel/modals/CommitMessageModal/CommitMessageModal.module.scss‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
.title {
2-
text-align: center;
3-
font-weight: 500;
4-
font-size: var(--font-size-14px);
5-
margin-bottom: var(--padding-6px);
6-
}
7-
81
.textarea {
92
width: 100%;
103
background-color: var(--vscode-input-background);
@@ -23,12 +16,6 @@
2316
}
2417
}
2518

26-
.container {
27-
display: flex;
28-
flex-direction: column;
29-
gap: var(--padding-8px);
30-
}
31-
3219
.actions {
3320
display: flex;
3421
justify-content: flex-end;

‎packages/ui/src/components/editor/panel/modals/CommitMessageModal/CommitMessageModal.tsx‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@ export const CommitMessageModal: React.FC<Props> = (props) => {
4646
}
4747
}, [countdown, is_timer_active, handle_accept])
4848

49+
const stop_timer = () => {
50+
set_is_timer_active(false)
51+
}
52+
4953
return (
50-
<Modal>
51-
<div
52-
className={styles.container}
53-
onMouseDown={() => {
54-
set_is_timer_active(false)
55-
}}
56-
>
57-
<div className={styles.title}>Commit changes</div>
54+
<Modal
55+
title="Commit changes"
56+
content_slot={
5857
<TextareaAutosize
5958
className={styles.textarea}
6059
value={message}
@@ -66,8 +65,11 @@ export const CommitMessageModal: React.FC<Props> = (props) => {
6665
handle_accept()
6766
}
6867
}}
68+
onMouseDown={stop_timer}
6969
/>
70-
<div className={styles.actions}>
70+
}
71+
footer_slot={
72+
<div className={styles.actions} onMouseDown={stop_timer}>
7173
<Button on_click={props.on_cancel} is_secondary={true}>
7274
Cancel
7375
</Button>
@@ -80,7 +82,7 @@ export const CommitMessageModal: React.FC<Props> = (props) => {
8082
{is_timer_active && countdown > 0 && ` (${countdown})`}
8183
</Button>
8284
</div>
83-
</div>
84-
</Modal>
85+
}
86+
/>
8587
)
8688
}

‎packages/ui/src/components/editor/panel/modals/Modal/Modal.module.scss‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,26 @@
2121
}
2222
}
2323

24+
.title {
25+
text-align: center;
26+
font-weight: 500;
27+
font-size: var(--font-size-14px);
28+
padding: var(--padding-12px) var(--padding-12px) var(--padding-2px)
29+
var(--padding-12px);
30+
}
31+
32+
.content {
33+
padding: var(--padding-8px) var(--padding-12px);
34+
}
35+
36+
.footer {
37+
padding: var(--padding-12px);
38+
border-top: 1px solid var(--vscode-sideBarSectionHeader-border);
39+
}
40+
2441
.container {
2542
position: relative;
2643
z-index: 1;
27-
padding: var(--padding-16px) var(--padding-12px) var(--padding-12px)
28-
var(--padding-12px);
2944
border-radius: var(--border-radius-8px);
3045
border: 1px solid var(--vscode-sideBarSectionHeader-border);
3146
width: 100%;
@@ -35,4 +50,6 @@
3550
color: var(--vscode-quickInput-foreground);
3651
border: 1px solid var(--vscode-widget-border);
3752
box-shadow: 0 0 8px 2px var(--vscode-widget-shadow);
53+
display: flex;
54+
flex-direction: column;
3855
}
Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
1+
import { Scrollable } from '../../Scrollable'
12
import styles from './Modal.module.scss'
23

34
type Props = {
4-
children: React.ReactNode
5+
title?: string
6+
content_slot?: React.ReactNode
7+
footer_slot?: React.ReactNode
8+
content_max_height?: string
59
}
610

711
export const Modal: React.FC<Props> = (props) => {
812
return (
913
<div className={styles.overlay}>
10-
<div className={styles.container}>{props.children}</div>
14+
<div className={styles.container}>
15+
{props.title && <div className={styles.title}>{props.title}</div>}
16+
17+
{props.content_slot &&
18+
(props.content_max_height ? (
19+
<Scrollable max_height={props.content_max_height}>
20+
<div className={styles.content}>{props.content_slot}</div>
21+
</Scrollable>
22+
) : (
23+
<div className={styles.content}>{props.content_slot}</div>
24+
))}
25+
26+
{props.footer_slot && (
27+
<div className={styles.footer}>{props.footer_slot}</div>
28+
)}
29+
</div>
1130
</div>
1231
)
1332
}

‎packages/ui/src/components/editor/panel/modals/ProgressModal/ProgressModal.module.scss‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
.title {
2-
text-align: center;
3-
}
4-
51
.elapsed-time {
62
text-align: center;
73
font-size: 20px;
@@ -36,12 +32,6 @@
3632
}
3733
}
3834

39-
.container {
40-
display: flex;
41-
flex-direction: column;
42-
gap: var(--padding-12px);
43-
}
44-
4535
.files-container {
4636
display: flex;
4737
flex-direction: column;

‎packages/ui/src/components/editor/panel/modals/ProgressModal/ProgressModal.tsx‎

Lines changed: 91 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -64,101 +64,104 @@ export const ProgressModal: React.FC<Props> = (props) => {
6464
}, [props.title])
6565

6666
return (
67-
<Modal>
68-
<div className={styles.container}>
69-
<div className={styles.title}>{props.title}</div>
70-
<div className={styles['elapsed-time']}>{elapsed_time.toFixed(1)}s</div>
67+
<Modal
68+
title={props.title}
69+
content_slot={
70+
<>
71+
<div className={styles['elapsed-time']}>
72+
{elapsed_time.toFixed(1)}s
73+
</div>
7174

72-
{props.files ? (
73-
<div className={styles['files-container']}>
74-
{props.files.map((file) => {
75-
const last_slash_index = file.file_path.lastIndexOf('/')
76-
const file_name =
77-
last_slash_index === -1
78-
? file.file_path
79-
: file.file_path.substring(last_slash_index + 1)
80-
const directory_path =
81-
last_slash_index === -1
82-
? ''
83-
: file.file_path.substring(0, last_slash_index)
75+
{props.files ? (
76+
<div className={styles['files-container']}>
77+
{props.files.map((file) => {
78+
const last_slash_index = file.file_path.lastIndexOf('/')
79+
const file_name =
80+
last_slash_index === -1
81+
? file.file_path
82+
: file.file_path.substring(last_slash_index + 1)
83+
const directory_path =
84+
last_slash_index === -1
85+
? ''
86+
: file.file_path.substring(0, last_slash_index)
8487

85-
return (
86-
<div key={file.file_path} className={styles['file-item']}>
87-
<div className={styles['file-item__header']}>
88-
<div className={styles['file-item__name']}>
89-
<span>{file_name}</span>
90-
<span>{directory_path}</span>
88+
return (
89+
<div key={file.file_path} className={styles['file-item']}>
90+
<div className={styles['file-item__header']}>
91+
<div className={styles['file-item__name']}>
92+
<span>{file_name}</span>
93+
<span>{directory_path}</span>
94+
</div>
95+
<div
96+
className={cn(
97+
styles['file-item__status'],
98+
styles[`file-item__status--${file.status}`]
99+
)}
100+
>
101+
{get_status_text(file.status)}
102+
</div>
91103
</div>
92-
<div
93-
className={cn(
94-
styles['file-item__status'],
95-
styles[`file-item__status--${file.status}`]
104+
<div className={styles.progress}>
105+
{file.status === 'thinking' ||
106+
(file.status === 'receiving' &&
107+
file.progress === undefined) ? (
108+
<div
109+
className={styles['progress__fill--indeterminate']}
110+
/>
111+
) : (
112+
<div
113+
className={cn(styles.progress__fill, {
114+
[styles['progress__fill--done']]:
115+
file.status === 'done',
116+
[styles['progress__fill--error']]:
117+
file.status === 'error'
118+
})}
119+
style={{
120+
width: `${
121+
file.status === 'done' || file.status === 'error'
122+
? 100
123+
: file.status === 'receiving' &&
124+
file.progress !== undefined
125+
? file.progress
126+
: 0
127+
}%`
128+
}}
129+
/>
96130
)}
97-
>
98-
{get_status_text(file.status)}
99131
</div>
132+
{file.status === 'receiving' &&
133+
file.tokens_per_second !== undefined && (
134+
<div className={styles['file-item__details']}>
135+
~{format_tokens_per_second(file.tokens_per_second)}{' '}
136+
tokens/s
137+
</div>
138+
)}
100139
</div>
101-
<div className={styles.progress}>
102-
{file.status === 'thinking' ||
103-
(file.status === 'receiving' &&
104-
file.progress === undefined) ? (
105-
<div
106-
className={styles['progress__fill--indeterminate']}
107-
/>
108-
) : (
109-
<div
110-
className={cn(styles.progress__fill, {
111-
[styles['progress__fill--done']]:
112-
file.status === 'done',
113-
[styles['progress__fill--error']]:
114-
file.status === 'error'
115-
})}
116-
style={{
117-
width: `${
118-
file.status === 'done' || file.status === 'error'
119-
? 100
120-
: file.status === 'receiving' &&
121-
file.progress !== undefined
122-
? file.progress
123-
: 0
124-
}%`
125-
}}
126-
/>
127-
)}
128-
</div>
129-
{file.status === 'receiving' &&
130-
file.tokens_per_second !== undefined && (
131-
<div className={styles['file-item__details']}>
132-
~{format_tokens_per_second(file.tokens_per_second)}{' '}
133-
tokens/s
134-
</div>
135-
)}
140+
)
141+
})}
142+
</div>
143+
) : (
144+
<>
145+
{props.tokens_per_second !== undefined && (
146+
<div className={styles['tokens-per-second']}>
147+
~{format_tokens_per_second(props.tokens_per_second)} tokens/s
136148
</div>
137-
)
138-
})}
139-
</div>
140-
) : (
141-
<>
142-
{props.tokens_per_second !== undefined && (
143-
<div className={styles['tokens-per-second']}>
144-
~{format_tokens_per_second(props.tokens_per_second)} tokens/s
145-
</div>
146-
)}
147-
<div className={styles.progress}>
148-
{props.progress !== undefined ? (
149-
<div
150-
className={styles.progress__fill}
151-
style={{ width: `${props.progress}%` }}
152-
/>
153-
) : (
154-
<div className={styles['progress__fill--indeterminate']} />
155149
)}
156-
</div>
157-
</>
158-
)}
159-
160-
<Button on_click={props.on_cancel}>Cancel</Button>
161-
</div>
162-
</Modal>
150+
<div className={styles.progress}>
151+
{props.progress !== undefined ? (
152+
<div
153+
className={styles.progress__fill}
154+
style={{ width: `${props.progress}%` }}
155+
/>
156+
) : (
157+
<div className={styles['progress__fill--indeterminate']} />
158+
)}
159+
</div>
160+
</>
161+
)}
162+
</>
163+
}
164+
footer_slot={<Button on_click={props.on_cancel}>Cancel</Button>}
165+
/>
163166
)
164167
}

0 commit comments

Comments
 (0)