Skip to content

Commit 9a5c994

Browse files
committed
feat: hide remote seciton if no endpoints
1 parent 62467c0 commit 9a5c994

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/pages/practice/Lab.tsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,30 +63,34 @@ export const Page: React.FC = () => {
6363
const endpoints = data.lab.endpoints
6464
return <>
6565
<Markdown source={data.lab.content}></Markdown>
66-
<EndpointContainer>
67-
{
68-
endpoints.map((endpoint, id) => {
69-
const onClick = () => {
70-
if(terminals.find(term => term === endpoint)) {
71-
setTermianls(terminals.filter(term => term !== endpoint))
72-
} else {
73-
setTermianls(terminals.concat([endpoint]))
66+
{
67+
!!endpoints.length && <EndpointContainer>
68+
{
69+
endpoints.map((endpoint, id) => {
70+
const onClick = () => {
71+
if(terminals.find(term => term === endpoint)) {
72+
setTermianls(terminals.filter(term => term !== endpoint))
73+
} else {
74+
setTermianls(terminals.concat([endpoint]))
75+
}
7476
}
75-
}
76-
return <Button key={id} onClick={onClick}intent={Intent.PRIMARY} outlined={true}>{t('lab.endpoint') + id.toString()}</Button>
77-
})
78-
}
79-
<Button onClick={() => setTermianls([])} intent={Intent.DANGER} outlined={true}>{t('lab.clear')}</Button>
80-
</EndpointContainer>
77+
return <Button key={id} onClick={onClick}intent={Intent.PRIMARY} outlined={true}>{t('lab.endpoint') + id.toString()}</Button>
78+
})
79+
}
80+
<Button onClick={() => setTermianls([])} intent={Intent.DANGER} outlined={true}>{t('lab.clear')}</Button>
81+
</EndpointContainer>
82+
}
8183
</>
8284
})
8385
return <ScrollCard>
8486
<Container>
8587
{ content }
86-
{ terminals.map((endpoint, idx) => <BlockWrapper key={idx}>
87-
<H3>{endpoint.host}</H3>
88-
<Terminal {...endpoint} id={'terminal' + endpoint.host + ':' + endpoint.port } key={idx}/>
89-
</BlockWrapper>) }
88+
{
89+
terminals.map((endpoint, idx) => <BlockWrapper key={idx}>
90+
<H3>{endpoint.host}</H3>
91+
<Terminal {...endpoint} id={'terminal' + endpoint.host + ':' + endpoint.port } key={idx}/>
92+
</BlockWrapper>)
93+
}
9094
</Container>
9195
</ScrollCard>
9296
}

0 commit comments

Comments
 (0)