Skip to content

Commit eac4c93

Browse files
committed
feat(gpt-runner-web): add responsive ui for chat page
1 parent ce6baf5 commit eac4c93

File tree

11 files changed

+330
-9
lines changed

11 files changed

+330
-9
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// see: https://github.com/smol-ai/developer
12
export { askCodeContext } from './ask-code-context'
23
export { code2prompt } from './code-to-prompt'
34
export { createAnything } from './create-anything'
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import type { FC } from 'react'
22
import type { ChatStreamReqParams } from '../../../../server/src/controllers/chatgpt.controller'
3+
import { FlexColumn } from '../../styles/global.styles'
34

45
export interface ChatMessagePanelProps extends ChatStreamReqParams { }
56
export const ChatMessagePanel: FC<ChatMessagePanelProps> = (props) => {
67
const { systemPrompt, messages, prompt, temperature } = props
78

8-
return <></>
9+
return <FlexColumn>
10+
11+
</FlexColumn>
912
}

packages/gpt-runner-web/client/src/components/indeterminate-progress-bar/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ export const IndeterminateProgressBar: FC = () => {
5555
<div
5656
style={{
5757
position: 'absolute',
58-
background: 'var(--vscode-progressBar-background)',
58+
background: 'var(--progressBar-background)',
5959
width: `${(longLength / lengthRatio) * 100}%`,
6060
height: '100%',
6161
}}
6262
/>
6363
<div
6464
style={{
6565
position: 'absolute',
66-
background: 'var(--vscode-progressBar-background)',
66+
background: 'var(--progressBar-background)',
6767
width: `${(shortLength / lengthRatio) * 100}%`,
6868
height: '100%',
6969
right: 0,

packages/gpt-runner-web/client/src/components/sidebar/sidebar.styles.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { styled } from 'styled-components'
33
export const SidebarWrapper = styled.div`
44
display: flex;
55
flex-direction: column;
6+
width: 100%;
67
`
78

89
export const SidebarSearch = styled.div`
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import type { RuleSet } from 'styled-components'
2+
import { css } from 'styled-components'
3+
4+
/**
5+
* The viewport width breakpoints
6+
*/
7+
export enum Breakpoints {
8+
sm = 375,
9+
md = 768,
10+
lg = 1000,
11+
xl = 1240,
12+
}
13+
14+
export type BreakpointName = keyof typeof Breakpoints
15+
16+
export type StyledType = RuleSet<object>
17+
18+
export function withBreakpoint(breakpoint: BreakpointName,
19+
style: StyledType) {
20+
switch (breakpoint) {
21+
case 'sm':
22+
return css`
23+
@media (max-width: ${Breakpoints.sm}px) {
24+
${style}
25+
}
26+
`
27+
case 'md':
28+
return css`
29+
@media (min-width: ${Breakpoints.md}px) {
30+
${style}
31+
}
32+
`
33+
case 'lg':
34+
return css`
35+
@media (min-width: ${Breakpoints.lg}px) {
36+
${style}
37+
}
38+
`
39+
case 'xl':
40+
return css`
41+
@media (min-width: ${Breakpoints.xl}px) {
42+
${style}
43+
}
44+
`
45+
default:
46+
return ''
47+
}
48+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { useMedia } from 'react-use'
2+
import { Breakpoints } from '../helpers/with-breakpoint'
3+
4+
export function useIsMobile() {
5+
const isMobile = useMedia(`(max-width: ${Breakpoints.sm}px)`, false)
6+
7+
return isMobile
8+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { css, styled } from 'styled-components'
2+
import { withBreakpoint } from '../../helpers/with-breakpoint'
3+
4+
export const SidebarWrapper = styled.div`
5+
max-width: 300px;
6+
min-width: 200px;
7+
width: 40%;
8+
height: 100%;
9+
flex-shrink: 0;
10+
11+
${withBreakpoint('sm', css`
12+
max-width: 100%;
13+
width: 100%;
14+
`)}
15+
`

packages/gpt-runner-web/client/src/pages/chat/index.tsx

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
import type { FC } from 'react'
2+
import { useCallback } from 'react'
3+
import { VSCodePanelTab, VSCodePanelView, VSCodePanels } from '@vscode/webview-ui-toolkit/react'
24
import type { SidebarProps } from '../../components/sidebar'
35
import { Sidebar } from '../../components/sidebar'
6+
import { useIsMobile } from '../../hooks/use-is-mobile.hook'
7+
import { ChatMessagePanel } from '../../components/chat-message-panel'
8+
import { FlexColumn, FlexRow } from '../../styles/global.styles'
9+
import { SidebarWrapper } from './chat.styles'
410

511
const Chat: FC = () => {
12+
const isMobile = useIsMobile()
13+
614
const sidebar: SidebarProps = {
715
topToolbar: {
816
title: 'GPT Runner',
917
actions: [],
1018
},
19+
onCreateChat: () => { },
20+
onDeleteChat: () => { },
21+
onRenameChat: () => { },
1122
tree: {
1223
items: [
1324
{
@@ -35,9 +46,36 @@ const Chat: FC = () => {
3546
],
3647
},
3748
}
38-
return <div>
39-
<Sidebar {...sidebar}></Sidebar>
40-
</div>
49+
50+
const renderSidebar = useCallback(() => {
51+
return <SidebarWrapper>
52+
<Sidebar {...sidebar}></Sidebar>
53+
</SidebarWrapper>
54+
}, [sidebar])
55+
56+
const renderChatPanel = useCallback(() => {
57+
return <FlexColumn style={{ flex: 1 }}>
58+
<ChatMessagePanel></ChatMessagePanel>
59+
</FlexColumn>
60+
}, [])
61+
62+
if (isMobile) {
63+
return <VSCodePanels>
64+
<VSCodePanelTab id="explore">Explore</VSCodePanelTab>
65+
<VSCodePanelTab id="chat">Chat</VSCodePanelTab>
66+
<VSCodePanelView id="explore">
67+
{renderSidebar()}
68+
</VSCodePanelView>
69+
<VSCodePanelView id="chat">
70+
{renderChatPanel()}
71+
</VSCodePanelView>
72+
</VSCodePanels>
73+
}
74+
75+
return <FlexRow>
76+
{renderSidebar()}
77+
{renderChatPanel()}
78+
</FlexRow>
4179
}
4280

4381
Chat.displayName = 'Chat'

packages/gpt-runner-web/client/src/styles/global.styles.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createGlobalStyle } from 'styled-components'
1+
import { createGlobalStyle, styled } from 'styled-components'
22

33
export const GlobalStyle = createGlobalStyle`
44
#root {
@@ -25,3 +25,23 @@ export const GlobalStyle = createGlobalStyle`
2525
margin: 0;
2626
}
2727
`
28+
29+
export const FlexRow = styled.div`
30+
display: flex;
31+
flex-direction: row;
32+
`
33+
34+
export const FlexColumn = styled.div`
35+
display: flex;
36+
flex-direction: column;
37+
`
38+
39+
export const FlexRowCenter = styled(FlexRow)`
40+
justify-content: center;
41+
align-items: center;
42+
`
43+
44+
export const FlexColumnCenter = styled(FlexColumn)`
45+
justify-content: center;
46+
align-items: center;
47+
`

packages/gpt-runner-web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"react-markdown": "^8.0.7",
6060
"react-router-dom": "^6.11.2",
6161
"react-syntax-highlighter": "^15.5.0",
62+
"react-use": "^17.4.0",
6263
"styled-components": "^6.0.0-rc.1",
6364
"zustand": "^4.3.8"
6465
},

0 commit comments

Comments
 (0)