Skip to content

Commit 4e53556

Browse files
committed
Refactor the Response Preview footer logic into a dedicated component
1 parent 99bca73 commit 4e53556

6 files changed

Lines changed: 67 additions & 46 deletions

File tree

‎packages/ui/src/components/editor/panel/Page/Page.module.scss‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@
3434
}
3535

3636
.footer {
37-
display: flex;
3837
gap: var(--padding-8px);
3938
padding: var(--padding-12px);
4039
border-top: 1px solid var(--vscode-sideBarSectionHeader-border);
41-
42-
> button {
43-
flex: 1;
44-
}
4540
}

‎packages/ui/src/components/editor/panel/ResponsePreview/ResponsePreview.module.scss‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
font-size: var(--padding-12px);
1212
border: 1px solid var(--vscode-sideBarSectionHeader-border);
1313
opacity: var(--dimmed-opacity);
14-
margin: 0 var(--padding-12px) var(--padding-8px) var(--padding-12px);
14+
margin: 0 var(--padding-12px);
1515
border-radius: var(--border-radius-5px);
1616

1717
> span {
@@ -53,6 +53,7 @@
5353
background: var(--vscode-list-hoverBackground);
5454
padding: var(--padding-5px) var(--padding-7px);
5555
border-radius: var(--border-radius-8px);
56+
word-wrap: break-word;
5657
}
5758

5859
> div:first-child {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.container {
2+
display: flex;
3+
width: 100%;
4+
gap: var(--padding-8px);
5+
6+
> * {
7+
flex: 1;
8+
}
9+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Button } from '../Button'
2+
import styles from './ResponsePreviewFooter.module.scss'
3+
4+
type Props = {
5+
on_discard: () => void
6+
on_approve: () => void
7+
is_approve_disabled: boolean
8+
}
9+
10+
export const ResponsePreviewFooter: React.FC<Props> = ({
11+
on_discard,
12+
on_approve,
13+
is_approve_disabled
14+
}) => {
15+
return (
16+
<div className={styles.container}>
17+
<Button on_click={on_discard} is_secondary>
18+
Discard
19+
</Button>
20+
<Button on_click={on_approve} disabled={is_approve_disabled}>
21+
Approve
22+
</Button>
23+
</div>
24+
)
25+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './ResponsePreviewFooter'

‎packages/vscode/src/views/panel/frontend/Panel.tsx‎

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import { ChatInitializedModal as UiChatInitializedModal } from '@ui/components/e
1313
import { CommitMessageModal as UiCommitMessageModal } from '@ui/components/editor/panel/modals/CommitMessageModal'
1414
import { StageFilesModal as UiStageFilesModal } from '@ui/components/editor/panel/modals/StageFilesModal'
1515
import { use_panel } from './hooks/use-panel'
16-
import { Button } from '@ui/components/editor/panel/Button'
1716
import { FileInPreview } from '@shared/types/file-in-preview'
1817
import { LayoutContext } from './contexts/LayoutContext'
1918
import { Layout } from './components/Layout/Layout'
19+
import { ResponsePreviewFooter as UiResponsePreviewFooter } from '@ui/components/editor/panel/ResponsePreviewFooter'
2020

2121
const vscode = acquireVsCodeApi()
2222

@@ -299,46 +299,36 @@ export const Panel = () => {
299299
post_message(vscode, { command: 'EDITS_REVIEW', files: [] })
300300
}}
301301
footer_slot={
302-
<>
303-
<Button
304-
on_click={() => {
305-
set_response_history((prev) =>
306-
prev.filter(
307-
(i) =>
308-
i.created_at != selected_history_item_created_at
309-
)
302+
<UiResponsePreviewFooter
303+
on_discard={() => {
304+
set_response_history((prev) =>
305+
prev.filter(
306+
(i) => i.created_at != selected_history_item_created_at
310307
)
311-
set_selected_history_item_created_at(undefined)
312-
post_message(vscode, {
313-
command: 'EDITS_REVIEW',
314-
files: []
315-
})
316-
}}
317-
is_secondary
318-
>
319-
Discard
320-
</Button>
321-
<Button
322-
on_click={() => {
323-
const accepted_files = items_to_review.filter(
324-
(f) => 'file_path' in f && f.is_checked
325-
) as FileInPreview[]
326-
set_response_history([])
327-
set_selected_history_item_created_at(undefined)
328-
post_message(vscode, {
329-
command: 'EDITS_REVIEW',
330-
files: accepted_files
331-
})
332-
}}
333-
disabled={
334-
items_to_review.filter(
335-
(f) => 'file_path' in f && f.is_checked
336-
).length == 0
337-
}
338-
>
339-
Approve
340-
</Button>
341-
</>
308+
)
309+
set_selected_history_item_created_at(undefined)
310+
post_message(vscode, {
311+
command: 'EDITS_REVIEW',
312+
files: []
313+
})
314+
}}
315+
on_approve={() => {
316+
const accepted_files = items_to_review.filter(
317+
(f) => 'file_path' in f && f.is_checked
318+
) as FileInPreview[]
319+
set_response_history([])
320+
set_selected_history_item_created_at(undefined)
321+
post_message(vscode, {
322+
command: 'EDITS_REVIEW',
323+
files: accepted_files
324+
})
325+
}}
326+
is_approve_disabled={
327+
items_to_review.filter(
328+
(f) => 'file_path' in f && f.is_checked
329+
).length == 0
330+
}
331+
/>
342332
}
343333
>
344334
<UiResponsePreview

0 commit comments

Comments
 (0)