Skip to content

Commit f628f18

Browse files
committed
Add loading indicator
1 parent 09e8a27 commit f628f18

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

site/src/pages/TemplatesPage/TemplatesPageView.tsx

+25-26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Avatar from "@material-ui/core/Avatar"
2+
import Box from "@material-ui/core/Box"
23
import Button from "@material-ui/core/Button"
34
import Link from "@material-ui/core/Link"
45
import { makeStyles } from "@material-ui/core/styles"
@@ -15,12 +16,16 @@ import { Link as RouterLink } from "react-router-dom"
1516
import * as TypesGen from "../../api/typesGenerated"
1617
import { Margins } from "../../components/Margins/Margins"
1718
import { Stack } from "../../components/Stack/Stack"
19+
import { TableLoader } from "../../components/TableLoader/TableLoader"
1820
import { firstLetter } from "../../util/firstLetter"
1921

2022
dayjs.extend(relativeTime)
2123

2224
export const Language = {
2325
createButton: "Create Template",
26+
developerCount: (ownerCount: number): string => {
27+
return `${ownerCount} developer${ownerCount !== 1 && "s"}`
28+
},
2429
emptyViewCreate: "to standardize development workspaces for your team.",
2530
emptyViewNoPerms: "No templates have been created! Contact your Coder administrator.",
2631
}
@@ -29,7 +34,6 @@ export interface TemplatesPageViewProps {
2934
loading?: boolean
3035
canCreateTemplate?: boolean
3136
templates?: TypesGen.Template[]
32-
error?: unknown
3337
}
3438

3539
export const TemplatesPageView: React.FC<TemplatesPageViewProps> = (props) => {
@@ -49,6 +53,7 @@ export const TemplatesPageView: React.FC<TemplatesPageViewProps> = (props) => {
4953
</TableRow>
5054
</TableHead>
5155
<TableBody>
56+
{props.loading && <TableLoader />}
5257
{!props.loading && !props.templates?.length && (
5358
<TableRow>
5459
<TableCell colSpan={999}>
@@ -67,27 +72,25 @@ export const TemplatesPageView: React.FC<TemplatesPageViewProps> = (props) => {
6772
</TableCell>
6873
</TableRow>
6974
)}
70-
{props.templates?.map((template) => {
71-
return (
72-
<TableRow key={template.id} className={styles.templateRow}>
73-
<TableCell>
74-
<div className={styles.templateName}>
75-
<Avatar variant="square" className={styles.templateAvatar}>
76-
{firstLetter(template.name)}
77-
</Avatar>
78-
<Link component={RouterLink} to={`/templates/${template.id}`} className={styles.templateLink}>
79-
<b>{template.name}</b>
80-
<span>{template.description}</span>
81-
</Link>
82-
</div>
83-
</TableCell>
84-
<TableCell>
85-
{template.workspace_owner_count} developer{template.workspace_owner_count !== 1 && "s"}
86-
</TableCell>
87-
<TableCell>{dayjs().to(dayjs(template.updated_at))}</TableCell>
88-
</TableRow>
89-
)
90-
})}
75+
{props.templates?.map((template) => (
76+
<TableRow key={template.id} className={styles.templateRow}>
77+
<TableCell>
78+
<Box alignItems="center" display="flex">
79+
<Avatar variant="square" className={styles.templateAvatar}>
80+
{firstLetter(template.name)}
81+
</Avatar>
82+
<Link component={RouterLink} to={`/templates/${template.id}`} className={styles.templateLink}>
83+
<b>{template.name}</b>
84+
<span>{template.description}</span>
85+
</Link>
86+
</Box>
87+
</TableCell>
88+
89+
<TableCell>{Language.developerCount(template.workspace_owner_count)}</TableCell>
90+
91+
<TableCell>{dayjs().to(dayjs(template.updated_at))}</TableCell>
92+
</TableRow>
93+
))}
9194
</TableBody>
9295
</Table>
9396
</Margins>
@@ -133,10 +136,6 @@ const useStyles = makeStyles((theme) => ({
133136
height: 24,
134137
fontSize: 16,
135138
},
136-
templateName: {
137-
display: "flex",
138-
alignItems: "center",
139-
},
140139
templateLink: {
141140
display: "flex",
142141
flexDirection: "column",

0 commit comments

Comments
 (0)