@@ -10,6 +10,7 @@ import postMessage from './api.js';
1010import _ from 'lodash' ;
1111import { VSCodeButton , VSCodeLink , VSCodeTextField } from '@vscode/webview-ui-toolkit/react' ;
1212import { Link } from '@vscode/webview-ui-toolkit' ;
13+ import { cn } from './misc.js' ;
1314
1415type Props = { user ?: t . UserUI ; welcome : t . WelcomeUIState ; earlyAccessEmail ?: string } ;
1516
@@ -75,6 +76,7 @@ export default function Welcome(props: Props) {
7576
7677function WelcomeSessions ( props : Props ) {
7778 const { welcome } = props ;
79+ const [ atTop , setAtTop ] = useState ( true ) ;
7880
7981 function login ( e : React . MouseEvent ) {
8082 e . stopPropagation ( ) ;
@@ -94,59 +96,70 @@ function WelcomeSessions(props: Props) {
9496 const featured = welcome . sessions . filter (
9597 s => s . group === 'remote' && s . head . id !== current ?. head . id && ! recent . some ( r => r . head . id === s . head . id ) ,
9698 ) ;
97- const empty = ! current && recent . length === 0 && featured . length === 0 ;
99+
100+ useEffect ( ( ) => {
101+ function scrolled ( ) {
102+ setAtTop ( ! document . scrollingElement ?. scrollTop ) ;
103+ }
104+
105+ scrolled ( ) ;
106+ window . addEventListener ( 'scroll' , scrolled ) ;
107+ return ( ) => window . removeEventListener ( 'scroll' , scrolled ) ;
108+ } , [ ] ) ;
98109
99110 return (
100111 < Screen className = "welcome-sessions" >
101112 { /*<LatencyTest store={this.props.store} />*/ }
102- < Section className = "search-section" >
103- < Section . Body >
104- < div className = "search-subsection subsection" >
105- < VSCodeTextField
106- placeholder = "Search"
107- autofocus
108- value = { welcome . searchQuery }
109- onInput = { search }
110- > </ VSCodeTextField >
111-
112- < VSCodeButton
113- onClick = { ( ) => postMessage ( { type : 'welcome/openWorkspace' } ) }
114- title = "Open session"
115- appearance = "secondary"
116- >
117- < span className = "codicon codicon-folder-opened" />
118- </ VSCodeButton >
119- < VSCodeButton
120- onClick = { ( ) => postMessage ( { type : 'welcome/openNewSessionInRecorder' } ) }
121- title = "Record a new session"
122- >
123- < span className = "codicon codicon-device-camera-video" />
124- </ VSCodeButton >
125- </ div >
126- { ! props . user && (
127- < div className = "signin-subsection subsection" >
128- < VSCodeLink href = "#" onClick = { login } >
129- Log in
130- </ VSCodeLink > { ' ' }
131- or{ ' ' }
132- < VSCodeLink href = "#" onClick = { join } >
133- join
134- </ VSCodeLink > { ' ' }
135- to publish your own sessions.
136- </ div >
137- ) }
138- </ Section . Body >
139- </ Section >
140- < SessionsSection user = { props . user } title = "WORKSPACE" listings = { _ . compact ( [ current ] ) } />
113+ < div className = { cn ( 'search-header' , atTop && 'at-top' ) } >
114+ < VSCodeTextField placeholder = "Search" autofocus value = { welcome . searchQuery } onInput = { search } > </ VSCodeTextField >
115+ < VSCodeButton
116+ onClick = { ( ) => postMessage ( { type : 'welcome/openWorkspace' } ) }
117+ title = "Open session"
118+ appearance = "secondary"
119+ >
120+ < span className = "codicon codicon-folder-opened" />
121+ </ VSCodeButton >
122+ < VSCodeButton
123+ onClick = { ( ) => postMessage ( { type : 'welcome/openNewSessionInRecorder' } ) }
124+ title = "Record a new session"
125+ >
126+ < span className = "codicon codicon-device-camera-video" />
127+ </ VSCodeButton >
128+ </ div >
129+ { ! props . user && (
130+ < div className = "signin" >
131+ < VSCodeLink href = "#" onClick = { login } >
132+ Log in
133+ </ VSCodeLink > { ' ' }
134+ or{ ' ' }
135+ < VSCodeLink href = "#" onClick = { join } >
136+ join
137+ </ VSCodeLink > { ' ' }
138+ to publish your own sessions.
139+ </ div >
140+ ) }
141+ < SessionsSection
142+ user = { props . user }
143+ title = "WORKSPACE"
144+ listings = { _ . compact ( [ current ] ) }
145+ emptyMessage = "No session found in workspace"
146+ />
141147 { recent . length > 0 && < SessionsSection user = { props . user } title = "RECENT" listings = { recent } /> }
142- < SessionsSection user = { props . user } title = "FEATURED" listings = { featured } loading = { welcome . loadingFeatured } />
148+ < SessionsSection
149+ user = { props . user }
150+ title = "FEATURED"
151+ listings = { featured }
152+ loading = { welcome . loadingFeatured }
153+ emptyMessage = "Could not fetch featured sessions"
154+ />
143155 </ Screen >
144156 ) ;
145157}
146158
147159type SessionsSectionProps = {
148160 user ?: t . UserUI ;
149161 title : string ;
162+ emptyMessage ?: string ;
150163 listings : t . SessionUIListing [ ] ;
151164 bordered ?: boolean ;
152165 loading ?: boolean ;
@@ -174,9 +187,9 @@ function SessionsSection(props: SessionsSectionProps) {
174187 onShare = { share }
175188 />
176189 ) }
177- { props . listings . length === 0 && ! props . loading && (
178- < div className = "empty-listings" >
179- < p > No session found in workspace </ p >
190+ { props . listings . length === 0 && ! props . loading && props . emptyMessage && (
191+ < Section . Messages >
192+ < p > { props . emptyMessage } </ p >
180193 { /*
181194 <VSCodeButton
182195 appearance="secondary"
@@ -185,7 +198,7 @@ function SessionsSection(props: SessionsSectionProps) {
185198 >
186199 Open session
187200 </VSCodeButton>*/ }
188- </ div >
201+ </ Section . Messages >
189202 ) }
190203 </ Section . Body >
191204 </ Section >
0 commit comments