Skip to content

Commit f4c5365

Browse files
committed
Migrate the response history component implementation and styling to the shared UI package
1 parent 4a17647 commit f4c5365

8 files changed

Lines changed: 229 additions & 137 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
}
1818

1919
code {
20+
font-family: monospace;
2021
font-size: var(--font-size-11px);
2122
background-color: var(--vscode-textCodeBlock-background);
2223
padding: 2px 4px;
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
.responses {
2+
margin: 0 var(--padding-16px);
3+
display: flex;
4+
flex-direction: column;
5+
border-top-left-radius: var(--border-radius-5px);
6+
border-top-right-radius: var(--border-radius-5px);
7+
border: 1px solid var(--cwc-border-color-dimmed);
8+
border-bottom: 0px;
9+
padding-bottom: var(--padding-5px);
10+
margin-bottom: calc(var(--padding-5px) * -1);
11+
overflow: hidden;
12+
13+
&:hover {
14+
border-color: var(--cwc-border-color);
15+
}
16+
17+
&__item {
18+
display: flex;
19+
align-items: center;
20+
justify-content: space-between;
21+
gap: var(--padding-4px);
22+
padding: var(--padding-3px) var(--padding-8px);
23+
width: 100%;
24+
25+
&:hover {
26+
background-color: var(--vscode-list-hoverBackground);
27+
}
28+
29+
&--selected {
30+
background-color: var(--vscode-list-inactiveSelectionBackground);
31+
&:hover {
32+
background-color: var(--vscode-list-inactiveSelectionBackground);
33+
}
34+
}
35+
36+
&__instruction {
37+
text-align: left;
38+
font-size: var(--font-size-12px);
39+
white-space: nowrap;
40+
overflow: hidden;
41+
text-overflow: ellipsis;
42+
}
43+
44+
&__right {
45+
display: flex;
46+
align-items: center;
47+
gap: var(--padding-4px);
48+
flex-shrink: 0;
49+
font-size: var(--font-size-11px);
50+
}
51+
52+
&__date {
53+
flex-shrink: 0;
54+
color: var(--vscode-descriptionForeground);
55+
}
56+
57+
&__stats {
58+
display: flex;
59+
gap: var(--padding-2px);
60+
flex-shrink: 0;
61+
62+
&--added {
63+
color: var(--vscode-gitDecoration-addedResourceForeground);
64+
}
65+
66+
&--removed {
67+
color: var(--vscode-gitDecoration-deletedResourceForeground);
68+
}
69+
}
70+
}
71+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { useState } from 'react'
2+
import { Responses, ResponseHistoryItem } from './Responses'
3+
4+
export default {
5+
component: Responses
6+
}
7+
8+
const response_history: ResponseHistoryItem[] = [
9+
{
10+
response: 'response 1',
11+
raw_instructions: 'instruction 1',
12+
created_at: Date.now() - 1000 * 60 * 5, // 5 minutes ago
13+
lines_added: 10,
14+
lines_removed: 2
15+
},
16+
{
17+
response: 'response 2',
18+
raw_instructions: 'instruction 2',
19+
created_at: Date.now() - 1000 * 60 * 60 * 2, // 2 hours ago
20+
lines_added: 5,
21+
lines_removed: 8
22+
},
23+
{
24+
response: 'response 3',
25+
raw_instructions:
26+
'instruction 3, very long instruction that should be truncated with an ellipsis',
27+
created_at: Date.now() - 1000 * 60 * 60 * 24 * 3, // 3 days ago
28+
lines_added: 20,
29+
lines_removed: 1
30+
}
31+
]
32+
33+
export const Primary = () => {
34+
const [selected, set_selected] = useState<number>()
35+
return (
36+
<Responses
37+
response_history={response_history}
38+
selected_history_item_created_at={selected}
39+
on_response_history_item_click={(item) =>
40+
console.log('item clicked', item)
41+
}
42+
on_selected_history_item_change={(created_at) => {
43+
console.log('selection changed', created_at)
44+
set_selected(created_at)
45+
}}
46+
/>
47+
)
48+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { useEffect, useState } from 'react'
2+
import cn from 'classnames'
3+
import dayjs from 'dayjs'
4+
import relativeTime from 'dayjs/plugin/relativeTime'
5+
import { FileInPreview } from '@shared/types/file-in-preview'
6+
import styles from './Responses.module.scss'
7+
8+
dayjs.extend(relativeTime)
9+
10+
export type ResponseHistoryItem = {
11+
response: string
12+
raw_instructions?: string
13+
created_at: number
14+
lines_added?: number
15+
lines_removed?: number
16+
files?: FileInPreview[]
17+
}
18+
19+
type Props = {
20+
response_history: ResponseHistoryItem[]
21+
on_response_history_item_click: (item: {
22+
response: string
23+
raw_instructions?: string
24+
files?: FileInPreview[]
25+
}) => void
26+
selected_history_item_created_at?: number
27+
on_selected_history_item_change: (created_at: number) => void
28+
}
29+
30+
export const Responses: React.FC<Props> = (props) => {
31+
// Re-render every minute to update the relative time of the history responses.
32+
const [, set_now] = useState(Date.now())
33+
useEffect(() => {
34+
const interval = setInterval(() => {
35+
set_now(Date.now())
36+
}, 60 * 1000)
37+
38+
return () => {
39+
clearInterval(interval)
40+
}
41+
}, [])
42+
43+
if (props.response_history.length == 0) {
44+
return null
45+
}
46+
47+
return (
48+
<div className={styles.responses}>
49+
{props.response_history.map((item) => (
50+
<button
51+
key={item.created_at}
52+
className={cn(styles['responses__item'], {
53+
[styles['responses__item--selected']]:
54+
props.response_history.length > 1 &&
55+
props.selected_history_item_created_at == item.created_at
56+
})}
57+
title={item.raw_instructions}
58+
onClick={() => {
59+
props.on_response_history_item_click(item)
60+
props.on_selected_history_item_change(item.created_at)
61+
}}
62+
>
63+
<span className={styles['responses__item__instruction']}>
64+
{item.raw_instructions || 'Response without instructions'}
65+
</span>
66+
<div className={styles['responses__item__right']}>
67+
{item.lines_added !== undefined &&
68+
item.lines_removed !== undefined && (
69+
<div className={styles['responses__item__stats']}>
70+
<span className={styles['responses__item__stats--added']}>
71+
+{item.lines_added}
72+
</span>
73+
<span className={styles['responses__item__stats--removed']}>
74+
-{item.lines_removed}
75+
</span>
76+
</div>
77+
)}
78+
<span className={styles['responses__item__date']}>
79+
{dayjs(item.created_at).fromNow()}
80+
</span>
81+
</div>
82+
</button>
83+
))}
84+
</div>
85+
)
86+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Responses'

‎packages/vscode/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "gemini-coder",
33
"displayName": "Code Web Chat",
4-
"description": "The privacy AI coding without agents (CWC)",
4+
"description": "AI coding without agents (CWC)",
55
"version": "1.513.0",
66
"scripts": {
77
"build": "npx vsce package --no-dependencies",

‎packages/vscode/src/views/panel/frontend/Main/MainView/MainView.module.scss‎

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -15,74 +15,6 @@
1515
flex-direction: column;
1616
}
1717

18-
.responses {
19-
margin: 0 var(--padding-16px);
20-
display: flex;
21-
flex-direction: column;
22-
border-top-left-radius: var(--border-radius-5px);
23-
border-top-right-radius: var(--border-radius-5px);
24-
border: 1px solid var(--cwc-border-color-dimmed);
25-
border-bottom: 0px;
26-
padding-bottom: var(--padding-5px);
27-
margin-bottom: calc(var(--padding-5px) * -1);
28-
overflow: hidden;
29-
30-
&__item {
31-
display: flex;
32-
align-items: center;
33-
justify-content: space-between;
34-
gap: var(--padding-4px);
35-
padding: var(--padding-3px) var(--padding-8px);
36-
width: 100%;
37-
38-
&:hover {
39-
background-color: var(--vscode-list-hoverBackground);
40-
}
41-
42-
&--selected {
43-
background-color: var(--vscode-list-inactiveSelectionBackground);
44-
&:hover {
45-
background-color: var(--vscode-list-inactiveSelectionBackground);
46-
}
47-
}
48-
49-
&__instruction {
50-
text-align: left;
51-
font-size: var(--font-size-12px);
52-
white-space: nowrap;
53-
overflow: hidden;
54-
text-overflow: ellipsis;
55-
}
56-
57-
&__right {
58-
display: flex;
59-
align-items: center;
60-
gap: var(--padding-4px);
61-
flex-shrink: 0;
62-
font-size: var(--font-size-11px);
63-
}
64-
65-
&__date {
66-
flex-shrink: 0;
67-
color: var(--vscode-descriptionForeground);
68-
}
69-
70-
&__stats {
71-
display: flex;
72-
gap: var(--padding-2px);
73-
flex-shrink: 0;
74-
75-
&--added {
76-
color: var(--vscode-gitDecoration-addedResourceForeground);
77-
}
78-
79-
&--removed {
80-
color: var(--vscode-gitDecoration-deletedResourceForeground);
81-
}
82-
}
83-
}
84-
}
85-
8618
.chat-input-container {
8719
display: flex;
8820
flex-direction: column;

0 commit comments

Comments
 (0)