Skip to content

Commit 8755e5a

Browse files
committed
Rename primary webview view to promptView and introduce CompactableActionButton for footer and header actions
- in footer, place 'history' icon (next to discord) with label "History" that invokes 'history' command - add missing translations [Fragment] - add missing translations[Fragment] - based on 'donate button' create 'discord button', copy colors from `apps/editor/src/views/panel/frontend/components/Layout/Footer/Footer.module.scss`. - remove discord icon from the footer - unify discord and donate button as 'home header action button' accept icon icon/codicon as props - place 'undo' to the right of 'history'. shrink labels in order determined by their length (shortest shrink first) - should shrink labels of 'discord'/'buy my a coffee' if there is not enough space, one by one, shorter first. - extract footer buttons like 'undo' 'apply...' etc. to ui component 'CompactableActionButton' - enhance `packages/ui/src/components/editor/panel/CompactableActionButton/CompactableActionButton.tsx` as needed and use instead `packages/ui/src/components/editor/panel/HomeHeaderActionButton/HomeHeaderActionButton.tsx` (that should be removed) - because labels use translations, thus are unknown width, compacting should dynamicaly determine order of items by their lenghts (the goal is to compact shortest labels first, longest last) - duplicate [Fragment] to header.buy-me-a-coffee - add missing translations[Fragment] - the view that currently is shown below 'workspace' and called 'Code Web Chat', should be named 'Prompt' - rename id codeWebChatView to promptView - from 'prompt' view, remove 'history' action button as it is acessed from elsewhere
1 parent 151eba5 commit 8755e5a

18 files changed

Lines changed: 299 additions & 205 deletions

File tree

‎apps/editor/package.json‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@
8888
"initialSize": 3
8989
},
9090
{
91-
"id": "codeWebChatView",
92-
"name": "Code Web Chat",
91+
"id": "promptView",
92+
"name": "Prompt",
9393
"type": "webview",
9494
"icon": "resources/activity-bar-icon.svg",
9595
"initialSize": 5
@@ -744,29 +744,24 @@
744744
"when": "view == codeWebChatViewOpenEditors",
745745
"group": "navigation@6"
746746
},
747-
{
748-
"command": "codeWebChat.history",
749-
"when": "view == codeWebChatView",
750-
"group": "navigation@1"
751-
},
752747
{
753748
"command": "codeWebChat.settings",
754-
"when": "view == codeWebChatView",
749+
"when": "view == promptView",
755750
"group": "navigation@2"
756751
},
757752
{
758753
"command": "codeWebChat.visitWebsite",
759-
"when": "view == codeWebChatView",
754+
"when": "view == promptView",
760755
"group": "1_more@1"
761756
},
762757
{
763758
"command": "codeWebChat.openRepository",
764-
"when": "view == codeWebChatView",
759+
"when": "view == promptView",
765760
"group": "1_more@2"
766761
},
767762
{
768763
"command": "codeWebChat.followOnX",
769-
"when": "view == codeWebChatView",
764+
"when": "view == promptView",
770765
"group": "1_more@3"
771766
}
772767
],

‎apps/editor/src/extension.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const activate = async (extension_context: vscode.ExtensionContext) => {
8888

8989
extension_context.subscriptions.push(
9090
vscode.window.registerWebviewViewProvider(
91-
'codeWebChatView',
91+
'promptView',
9292
panel_view_provider,
9393
{
9494
webviewOptions: {

‎apps/editor/src/views/panel/frontend/Home/Home.module.scss‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
gap: 4px;
1717
}
1818

19+
&__right {
20+
display: flex;
21+
align-items: center;
22+
gap: 4px;
23+
}
24+
1925
&__home {
2026
display: flex;
2127
align-items: center;

‎apps/editor/src/views/panel/frontend/Home/Home.tsx‎

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect } from 'react'
1+
import { useState, useEffect, useRef, useLayoutEffect } from 'react'
22
import styles from './Home.module.scss'
33
import { Scrollable as UiScrollable } from '@ui/components/editor/common/Scrollable'
44
import { Tabs as UiTabs } from '@ui/components/editor/panel/Tabs'
@@ -11,10 +11,11 @@ import { ResponseHistoryItem } from '@shared/types/response-history-item'
1111
import { Separator as UiSeparator } from '@ui/components/editor/panel/Separator'
1212
import { Translation, use_translation } from '../i18n/use-translation'
1313
import { IconButton as UiIconButton } from '@ui/components/editor/common/IconButton'
14-
import { DonateButton as UiDonateButton } from '@ui/components/editor/panel/DonateButton'
14+
import { CompactableActionButton } from '@ui/components/editor/panel/CompactableActionButton'
1515
import { Tasks as UiTasks } from '@ui/components/editor/panel/Tasks'
1616
import { use_tasks } from './hooks/use-tasks'
1717
import { use_sticky_mode } from './hooks/use-sticky-mode'
18+
import { use_compacting, use_compact_order } from '@shared/hooks'
1819

1920
type Props = {
2021
vscode: any
@@ -62,6 +63,25 @@ export const Home: React.FC<Props> = (props) => {
6263
? active_workspace_root
6364
: roots[0]
6465

66+
const { container_ref, compact_step, report_width } = use_compacting(2)
67+
const left_ref = useRef<HTMLDivElement>(null)
68+
const right_ref = useRef<HTMLDivElement>(null)
69+
70+
const discord_label = 'Discord'
71+
const coffee_label = t('header.buy-me-a-coffee')
72+
73+
const compact_order = use_compact_order([discord_label, coffee_label])
74+
75+
useLayoutEffect(() => {
76+
if (left_ref.current && right_ref.current) {
77+
const width =
78+
left_ref.current.getBoundingClientRect().width +
79+
right_ref.current.getBoundingClientRect().width +
80+
8
81+
report_width(width, compact_step)
82+
}
83+
}, [compact_step, report_width])
84+
6585
useEffect(() => {
6686
const handle_message = (event: MessageEvent<BackendMessage>) => {
6787
const message = event.data
@@ -86,17 +106,27 @@ export const Home: React.FC<Props> = (props) => {
86106

87107
return (
88108
<>
89-
<div className={styles.header}>
90-
<div className={styles['header__left']}>
109+
<div className={styles.header} ref={container_ref}>
110+
<div className={styles['header__left']} ref={left_ref}>
91111
<div className={styles['header__home']}>
92112
<span className="codicon codicon-home" />
93113
</div>
94114
<span className={styles['header__text']}>{t('header.home')}</span>
95115
</div>
96-
<UiDonateButton
97-
label={t('recent-donations.buy-me-a-coffee')}
98-
on_click={props.on_donate_click}
99-
/>
116+
<div className={styles['header__right']} ref={right_ref}>
117+
<CompactableActionButton
118+
label={discord_label}
119+
href="https://discord.gg/KJySXsrSX5"
120+
icon="DISCORD"
121+
is_compact={compact_step >= compact_order[0]}
122+
/>
123+
<CompactableActionButton
124+
label={coffee_label}
125+
on_click={props.on_donate_click}
126+
codicon="coffee"
127+
is_compact={compact_step >= compact_order[1]}
128+
/>
129+
</div>
100130
</div>
101131

102132
<UiScrollable on_scroll={handle_scroll} top_shadow>

‎apps/editor/src/views/panel/frontend/Panel.tsx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@ export const Panel = () => {
242242
})
243243
}
244244

245+
const handle_history_click = () => {
246+
post_message(vscode, {
247+
command: 'EXECUTE_COMMAND',
248+
command_id: 'codeWebChat.history'
249+
})
250+
}
251+
245252
const handle_undo_click = () => {
246253
post_message(vscode, {
247254
command: 'UNDO'
@@ -306,7 +313,7 @@ export const Panel = () => {
306313
<LayoutContext.Provider value={layout_context_value}>
307314
<div className={styles.container} data-modern-ui={is_modern_ui}>
308315
<div className={styles.slot}>
309-
<Layout>
316+
<Layout on_history_click={handle_history_click}>
310317
<div
311318
className={cn(styles.content, {
312319
[styles['content--hidden']]: active_view != 'main'
Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.footer {
2-
--button-size: 24px;
32
position: relative;
43
z-index: -1; // Makes context menu of a web configuration appear above
54
display: flex;
@@ -19,63 +18,4 @@
1918
&__left {
2019
display: flex;
2120
}
22-
23-
&__icon-button {
24-
display: flex;
25-
align-items: center;
26-
justify-content: center;
27-
height: var(--button-size);
28-
width: var(--button-size);
29-
border-radius: 4px;
30-
31-
> svg {
32-
flex-shrink: 0;
33-
width: 16px;
34-
height: 16px;
35-
}
36-
37-
&--discord {
38-
background-color: #5765f2;
39-
40-
> svg {
41-
fill: white;
42-
}
43-
44-
&:hover {
45-
background-color: color-mix(in srgb, #5765f2, white 10%);
46-
}
47-
}
48-
}
49-
50-
&__action-button {
51-
display: flex;
52-
align-items: center;
53-
flex-shrink: 0;
54-
gap: 4px;
55-
height: var(--button-size);
56-
padding: 0 6px 0 3px;
57-
border-radius: 4px;
58-
59-
&:hover:not(:disabled) {
60-
background-color: var(--vscode-toolbar-hoverBackground);
61-
}
62-
63-
&:disabled {
64-
opacity: var(--disabled-opacity);
65-
}
66-
67-
&__text {
68-
display: inline;
69-
}
70-
71-
&--compact &__text {
72-
display: none;
73-
}
74-
75-
&--compact {
76-
padding: 0;
77-
width: var(--button-size);
78-
justify-content: center;
79-
}
80-
}
8121
}

‎apps/editor/src/views/panel/frontend/components/Layout/Footer/Footer.tsx‎

Lines changed: 39 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { useState, useEffect, useContext, useRef, useLayoutEffect } from 'react'
2-
import cn from 'classnames'
3-
import { Icon as UiIcon } from '@ui/components/editor/common/Icon'
42
import styles from './Footer.module.scss'
5-
import { use_compacting } from '@shared/hooks'
3+
import { use_compacting, use_compact_order } from '@shared/hooks'
64
import { LayoutContext } from '../../../contexts/LayoutContext'
75
import { use_translation } from '../../../i18n/use-translation'
6+
import { CompactableActionButton } from '@ui/components/editor/panel/CompactableActionButton'
87

9-
export const Footer: React.FC = () => {
8+
type Props = {
9+
on_history_click?: () => void
10+
}
11+
12+
export const Footer: React.FC<Props> = (props) => {
1013
const {
1114
can_undo,
1215
on_apply_click,
@@ -16,10 +19,20 @@ export const Footer: React.FC = () => {
1619

1720
const { t } = use_translation()
1821

22+
const history_label = t('footer.action.history')
23+
const undo_label = t('footer.action.undo')
24+
const apply_label = t('footer.action.apply-from-clipboard')
25+
26+
const compact_order = use_compact_order([
27+
history_label,
28+
undo_label,
29+
apply_label
30+
])
31+
1932
const [is_apply_disabled_temporarily, set_is_apply_disabled_temporarily] =
2033
useState(false)
2134

22-
const { container_ref, compact_step, report_width } = use_compacting(2)
35+
const { container_ref, compact_step, report_width } = use_compacting(3)
2336
const left_ref = useRef<HTMLDivElement>(null)
2437
const right_ref = useRef<HTMLDivElement>(null)
2538

@@ -54,57 +67,32 @@ export const Footer: React.FC = () => {
5467
<>
5568
<div className={styles.footer} ref={container_ref}>
5669
<div ref={left_ref} className={styles.footer__left}>
57-
<a
58-
className={cn(
59-
styles['footer__icon-button'],
60-
styles['footer__icon-button--discord']
61-
)}
62-
href="https://discord.gg/KJySXsrSX5"
63-
title={t('footer.get-involved')}
64-
>
65-
<UiIcon variant="DISCORD" />
66-
</a>
70+
<CompactableActionButton
71+
is_compact={compact_step >= compact_order[0]}
72+
on_click={props.on_history_click}
73+
title={t('footer.history-title')}
74+
codicon="history"
75+
label={history_label}
76+
/>
77+
<CompactableActionButton
78+
is_compact={compact_step >= compact_order[1]}
79+
on_click={on_undo_click}
80+
title={t('footer.undo-title')}
81+
disabled={!can_undo}
82+
codicon="discard"
83+
label={undo_label}
84+
/>
6785
</div>
6886

6987
<div ref={right_ref}>
70-
<button
71-
className={cn(styles['footer__action-button'], {
72-
[styles['footer__action-button--compact']]: compact_step >= 1
73-
})}
74-
onClick={on_undo_click}
75-
title={t('footer.undo-title')}
76-
disabled={!can_undo}
77-
>
78-
<span
79-
className={cn(
80-
styles['footer__action-button__icon'],
81-
'codicon',
82-
'codicon-discard'
83-
)}
84-
/>
85-
<span className={styles['footer__action-button__text']}>
86-
{t('footer.action.undo')}
87-
</span>
88-
</button>
89-
<button
90-
className={cn(styles['footer__action-button'], {
91-
[styles['footer__action-button--compact']]: compact_step >= 2
92-
})}
93-
onClick={handle_apply_click}
88+
<CompactableActionButton
89+
is_compact={compact_step >= compact_order[2]}
90+
on_click={handle_apply_click}
9491
title={t('footer.apply-title')}
9592
disabled={is_apply_disabled_temporarily}
96-
>
97-
<span
98-
className={cn(
99-
styles['footer__action-button__icon'],
100-
'codicon',
101-
'codicon-clippy'
102-
)}
103-
/>
104-
<span className={styles['footer__action-button__text']}>
105-
{t('footer.action.apply-from-clipboard')}
106-
</span>
107-
</button>
93+
codicon="clippy"
94+
label={apply_label}
95+
/>
10896
</div>
10997
</div>
11098
</>

‎apps/editor/src/views/panel/frontend/components/Layout/Layout.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import { Footer } from './Footer'
33

44
type Props = {
55
children: React.ReactNode
6+
on_history_click?: () => void
67
}
78

89
export const Layout: React.FC<Props> = (props) => {
910
return (
1011
<div className={styles.container}>
1112
<div className={styles.content}>{props.children}</div>
12-
<Footer />
13+
<Footer on_history_click={props.on_history_click} />
1314
</div>
1415
)
1516
}

0 commit comments

Comments
 (0)