Skip to content

Commit 17ac5e9

Browse files
author
Ives van Hoorne
committed
Add view counting
1 parent 57d6ee0 commit 17ac5e9

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

src/app/pages/Sandbox/Editor/Workspace/Project/index.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,28 @@ const Item = styled.div`
1111
font-size: .875rem;
1212
`;
1313

14+
const ViewCount = styled.span`
15+
color: white;
16+
font-weight: 500;
17+
`;
18+
19+
const ViewCountDescription = styled.span`
20+
color: rgba(255, 255, 255, 0.6);
21+
`;
22+
23+
const ViewCountContainer = styled.div`
24+
margin: .5rem 1rem;
25+
font-size: .875rem;
26+
`;
27+
1428
type Props = {
1529
id: string,
1630
title: string,
1731
description: string,
32+
viewCount: number,
1833
forkedSandbox: ?{ title: string, id: string },
1934
updateSandboxInfo: (id: string, title: string, description: string) => void,
35+
preventTransition: boolean,
2036
};
2137

2238
export default class Project extends React.PureComponent {
@@ -61,7 +77,7 @@ export default class Project extends React.PureComponent {
6177
};
6278

6379
render() {
64-
const { forkedSandbox, preventTransition } = this.props;
80+
const { forkedSandbox, viewCount, preventTransition } = this.props;
6581
const { title, description } = this.state;
6682
return (
6783
<div>
@@ -100,6 +116,14 @@ export default class Project extends React.PureComponent {
100116
</ConfirmLink>
101117
</Item>
102118
</div>}
119+
<WorkspaceSubtitle>Statistics</WorkspaceSubtitle>
120+
<ViewCountContainer>
121+
<ViewCount>{viewCount}{' '}</ViewCount>
122+
<ViewCountDescription>
123+
unique
124+
{viewCount === 1 ? ' view' : ' views'}
125+
</ViewCountDescription>
126+
</ViewCountContainer>
103127
</div>
104128
);
105129
}

src/app/pages/Sandbox/Editor/Workspace/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const Workspace = ({ sandbox, sandboxActions }: Props) => (
4343
updateSandboxInfo={sandboxActions.updateSandboxInfo}
4444
id={sandbox.id}
4545
title={sandbox.title}
46+
viewCount={sandbox.viewCount}
4647
description={sandbox.description}
4748
forkedSandbox={sandbox.forkedFromSandbox}
4849
preventTransition={sandbox.modules.some(m => m.isNotSynced)}

src/common/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export type Sandbox = {
4343
id: string,
4444
title: ?string,
4545
description: string,
46+
viewCount: number,
4647
modules: Array<Module>,
4748
currentModule: ?Module,
4849
directories: Array<Directory>,

src/sandbox/external-resources.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ function addJS(resource: string) {
3232
}
3333

3434
function addResource(resource: string) {
35-
const kind = resource.match(/\.([^.]*)$/)[1];
35+
const match = resource.match(/\.([^.]*)$/);
3636

37-
if (kind === 'css') {
37+
if (match && match[1] === 'css') {
3838
addCSS(resource);
39-
} else if (kind === 'js') {
39+
} else {
4040
addJS(resource);
4141
}
4242
}

0 commit comments

Comments
 (0)