forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
70 lines (66 loc) · 1.72 KB
/
index.tsx
File metadata and controls
70 lines (66 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React from 'react';
import Tags from '../Tags';
import { Overlay, SandboxDescription } from '../SandboxCard/elements';
import {
Border,
TemplateTitle,
TemplateSubTitle,
MyTemplate,
} from './elements';
import { getSandboxName } from '../../utils/get-sandbox-name';
interface Props {
template?: {
id: string;
color: string;
sandbox: {
id: string;
title: string;
alias: string;
description: string;
tags?: string[];
};
};
i: number;
onClick?: () => void;
}
const BANNER = 'https://codesandbox.io/static/img/banner.png';
const SCREENSHOT_API_URL = (id: string) =>
`https://codesandbox.io/api/v1/sandboxes/${id}/screenshot.png`;
const CustomTemplate = ({ template, onClick, i }: Props) => {
if (!template) {
return (
<MyTemplate key={i}>
<img height="109px" alt="loading" src={BANNER} />
<Border />
<div>
<TemplateTitle>Loading</TemplateTitle>
</div>
</MyTemplate>
);
}
const { sandbox } = template;
const title = getSandboxName(sandbox);
return (
<MyTemplate key={i} onClick={onClick} overlayHeight={109}>
<img
height="109px"
src={
process.env.NODE_ENV === 'development'
? BANNER
: SCREENSHOT_API_URL(sandbox.id) || BANNER
}
alt={title}
/>
<Overlay>
<SandboxDescription>{sandbox.description}</SandboxDescription>
{sandbox.tags && <Tags tags={sandbox.tags} />}
</Overlay>
<Border color={template.color} />
<div>
<TemplateTitle>{title}</TemplateTitle>
<TemplateSubTitle>{sandbox.description}</TemplateSubTitle>
</div>
</MyTemplate>
);
};
export default CustomTemplate;