Skip to content

Commit a4c90c5

Browse files
feat: Add icon to the template page (#3604)
1 parent 690e6c6 commit a4c90c5

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

site/src/pages/TemplatePage/TemplatePageView.stories.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ Example.args = {
1717
templateVersions: [Mocks.MockTemplateVersion],
1818
}
1919

20+
export const NoIcon = Template.bind({})
21+
NoIcon.args = {
22+
template: { ...Mocks.MockTemplate, icon: "" },
23+
activeTemplateVersion: Mocks.MockTemplateVersion,
24+
templateResources: [Mocks.MockWorkspaceResource, Mocks.MockWorkspaceResource2],
25+
templateVersions: [Mocks.MockTemplateVersion],
26+
}
27+
2028
export const SmallViewport = Template.bind({})
2129
SmallViewport.args = {
2230
template: Mocks.MockTemplate,

site/src/pages/TemplatePage/TemplatePageView.tsx

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Avatar from "@material-ui/core/Avatar"
12
import Button from "@material-ui/core/Button"
23
import Link from "@material-ui/core/Link"
34
import { makeStyles } from "@material-ui/core/styles"
@@ -7,6 +8,7 @@ import frontMatter from "front-matter"
78
import { FC } from "react"
89
import ReactMarkdown from "react-markdown"
910
import { Link as RouterLink } from "react-router-dom"
11+
import { firstLetter } from "util/firstLetter"
1012
import { Template, TemplateVersion, WorkspaceResource } from "../../api/typesGenerated"
1113
import { Margins } from "../../components/Margins/Margins"
1214
import {
@@ -44,6 +46,7 @@ export const TemplatePageView: FC<TemplatePageViewProps> = ({
4446
}) => {
4547
const styles = useStyles()
4648
const readme = frontMatter(activeTemplateVersion.readme)
49+
const hasIcon = template.icon && template.icon !== ""
4750

4851
const getStartedResources = (resources: WorkspaceResource[]) => {
4952
return resources.filter((resource) => resource.workspace_transition === "start")
@@ -73,13 +76,26 @@ export const TemplatePageView: FC<TemplatePageViewProps> = ({
7376
</Stack>
7477
}
7578
>
76-
<PageHeaderTitle>{template.name}</PageHeaderTitle>
77-
<PageHeaderSubtitle>
78-
{template.description === "" ? Language.noDescription : template.description}
79-
</PageHeaderSubtitle>
79+
<Stack direction="row" spacing={3} className={styles.pageTitle}>
80+
<div>
81+
{hasIcon ? (
82+
<div className={styles.iconWrapper}>
83+
<img src={template.icon} alt="" />
84+
</div>
85+
) : (
86+
<Avatar className={styles.avatar}>{firstLetter(template.name)}</Avatar>
87+
)}
88+
</div>
89+
<div>
90+
<PageHeaderTitle>{template.name}</PageHeaderTitle>
91+
<PageHeaderSubtitle>
92+
{template.description === "" ? Language.noDescription : template.description}
93+
</PageHeaderSubtitle>
94+
</div>
95+
</Stack>
8096
</PageHeader>
8197

82-
<Stack spacing={3}>
98+
<Stack spacing={2.5}>
8399
<TemplateStats template={template} activeVersion={activeTemplateVersion} />
84100
<WorkspaceSection
85101
title={Language.resourcesTitle}
@@ -137,5 +153,20 @@ export const useStyles = makeStyles((theme) => {
137153
versionsTableContents: {
138154
margin: 0,
139155
},
156+
pageTitle: {
157+
alignItems: "center",
158+
},
159+
avatar: {
160+
width: theme.spacing(6),
161+
height: theme.spacing(6),
162+
fontSize: theme.spacing(3),
163+
},
164+
iconWrapper: {
165+
width: theme.spacing(6),
166+
height: theme.spacing(6),
167+
"& img": {
168+
width: "100%",
169+
},
170+
},
140171
}
141172
})

site/src/pages/TemplatesPage/TemplatesPageView.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,5 +225,9 @@ const useStyles = makeStyles((theme) => ({
225225
width: 36,
226226
height: 36,
227227
padding: 2,
228+
229+
"& img": {
230+
width: "100%",
231+
},
228232
},
229233
}))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy