Skip to content

Commit f793f0d

Browse files
committed
Extract ForkedFrom
1 parent 4eba176 commit f793f0d

File tree

4 files changed

+43
-25
lines changed

4 files changed

+43
-25
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Link as LinkBase } from 'react-router-dom';
2+
import styled, { css } from 'styled-components';
3+
4+
export const Link = styled(LinkBase)`
5+
${({ theme }) => css`
6+
color: ${theme.templateColor} !important;
7+
`}
8+
`;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { getSandboxName } from '@codesandbox/common/lib/utils/get-sandbox-name';
2+
import { sandboxUrl } from '@codesandbox/common/lib/utils/url-generator';
3+
import React, { FunctionComponent } from 'react';
4+
5+
import { useOvermind } from 'app/overmind';
6+
7+
import { Item, PropertyName, PropertyValue } from '../elements';
8+
9+
import { Link } from './elements';
10+
11+
export const ForkedFrom: FunctionComponent = () => {
12+
const {
13+
state: {
14+
editor: {
15+
currentSandbox: { forkedFromSandbox, forkedTemplateSandbox },
16+
},
17+
},
18+
} = useOvermind();
19+
20+
return (
21+
<Item>
22+
<PropertyName>
23+
{forkedTemplateSandbox ? 'Template' : 'Forked From'}
24+
</PropertyName>
25+
26+
<PropertyValue>
27+
<Link to={sandboxUrl(forkedFromSandbox || forkedTemplateSandbox)}>
28+
{getSandboxName(forkedFromSandbox || forkedTemplateSandbox)}
29+
</Link>
30+
</PropertyValue>
31+
</Item>
32+
);
33+
};

packages/app/src/app/pages/Sandbox/Editor/Workspace/Project/elements.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Question from 'react-icons/lib/go/question';
22
import EditPenIcon from 'react-icons/lib/md/create';
3-
import { Link } from 'react-router-dom';
43
import styled, { css } from 'styled-components';
54

65
export const Container = styled.div`
@@ -82,12 +81,6 @@ export const Icon = styled(Question)`
8281
cursor: pointer;
8382
`;
8483

85-
export const TemplateStyledLink = styled(Link)`
86-
${({ theme }) => css`
87-
color: ${theme.templateColor} !important;
88-
`}
89-
`;
90-
9184
export const BundlerLink = styled.a.attrs({
9285
target: '_blank',
9386
rel: 'noreferrer noopener',

packages/app/src/app/pages/Sandbox/Editor/Workspace/Project/index.tsx

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import Tooltip from '@codesandbox/common/lib/components/Tooltip';
22
import getTemplateDefinition from '@codesandbox/common/lib/templates';
3-
import { getSandboxName } from '@codesandbox/common/lib/utils/get-sandbox-name';
4-
import { sandboxUrl } from '@codesandbox/common/lib/utils/url-generator';
53
import React, { FunctionComponent } from 'react';
64

75
import { useOvermind } from 'app/overmind';
@@ -20,8 +18,8 @@ import {
2018
PropertyName,
2119
PropertyValue,
2220
StatsContainer,
23-
TemplateStyledLink,
2421
} from './elements';
22+
import { ForkedFrom } from './ForkedFrom';
2523
import { Frozen } from './Frozen';
2624
import { Git } from './Git';
2725
import { Keywords } from './Keywords';
@@ -83,21 +81,7 @@ export const Project: FunctionComponent<Props> = ({ editable = false }) => {
8381

8482
{editable && <Frozen />}
8583

86-
{(forkedFromSandbox || forkedTemplateSandbox) && (
87-
<Item>
88-
<PropertyName>
89-
{forkedTemplateSandbox ? 'Template' : 'Forked From'}
90-
</PropertyName>
91-
92-
<PropertyValue>
93-
<TemplateStyledLink
94-
to={sandboxUrl(forkedFromSandbox || forkedTemplateSandbox)}
95-
>
96-
{getSandboxName(forkedFromSandbox || forkedTemplateSandbox)}
97-
</TemplateStyledLink>
98-
</PropertyValue>
99-
</Item>
100-
)}
84+
{(forkedFromSandbox || forkedTemplateSandbox) && <ForkedFrom />}
10185

10286
<Item>
10387
<PropertyName>

0 commit comments

Comments
 (0)