Skip to content

Commit f4cb417

Browse files
authored
Fixes stripe Loading (codesandbox#2436)
* fix stripe * move script * fix ts
1 parent af862ac commit f4cb417

File tree

13 files changed

+141
-112
lines changed

13 files changed

+141
-112
lines changed

packages/app/src/app/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
</script>
4949
<!-- End Google Tag Manager -->
5050
<!-- <script async src="//cdn.headwayapp.co/widget.js"></script> -->
51-
<script async rel="prefetch" src="https://js.stripe.com/v3/"></script>
5251
<script src="<%= webpackConfig.output.publicPath %>static/browserfs3/browserfs<%=process.env.NODE_ENV
5352
=== 'development' ? '' : '.min'%>.js"
5453
type="text/javascript"></script>

packages/app/src/app/pages/Dashboard/Content/routes/DeletedSandboxes/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { Observer } from 'app/componentConnectors';
3+
import Helmet from 'react-helmet';
34
import { uniq } from 'lodash-es';
45
import { Query } from 'react-apollo';
56
import RemoveIcon from 'react-icons/lib/md/highlight-remove';
@@ -8,10 +9,11 @@ import { Content as Sandboxes } from '../../Sandboxes';
89

910
import { DELETED_SANDBOXES_CONTENT_QUERY } from '../../../queries';
1011

11-
const DeletedSandboxes = () => {
12-
document.title = 'Deleted Sandboxes - CodeSandbox';
13-
14-
return (
12+
const DeletedSandboxes = () => (
13+
<>
14+
<Helmet>
15+
<title>Deleted Sandboxes - CodeSandbox</title>
16+
</Helmet>
1517
<Query
1618
fetchPolicy="cache-and-network"
1719
query={DELETED_SANDBOXES_CONTENT_QUERY}
@@ -65,7 +67,7 @@ const DeletedSandboxes = () => {
6567
</Observer>
6668
)}
6769
</Query>
68-
);
69-
};
70+
</>
71+
);
7072

7173
export default DeletedSandboxes;

packages/app/src/app/pages/Dashboard/Content/routes/PathedSandboxes/index.js

Lines changed: 65 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import Helmet from 'react-helmet';
23
import { Observer } from 'app/componentConnectors';
34
import { Query } from 'react-apollo';
45
import { basename } from 'path';
@@ -14,71 +15,77 @@ import { getPossibleTemplates } from '../../Sandboxes/utils';
1415
const PathedSandboxes = props => {
1516
const path = '/' + decodeURIComponent(props.match.params.path || '');
1617
const teamId = props.match.params.teamId;
17-
18-
document.title = `${basename(path) || 'Dashboard'} - CodeSandbox`;
1918
return (
20-
<Query query={PATHED_SANDBOXES_CONTENT_QUERY} variables={{ path, teamId }}>
21-
{({ loading, error, data }) => (
22-
<Observer>
23-
{({ store }) => {
24-
if (error) {
25-
console.error(error);
26-
return <div>Error!</div>;
27-
}
19+
<>
20+
<Helmet>
21+
<title>{basename(path) || 'Dashboard'} - CodeSandbox</title>
22+
</Helmet>
23+
<Query
24+
query={PATHED_SANDBOXES_CONTENT_QUERY}
25+
variables={{ path, teamId }}
26+
>
27+
{({ loading, error, data }) => (
28+
<Observer>
29+
{({ store }) => {
30+
if (error) {
31+
console.error(error);
32+
return <div>Error!</div>;
33+
}
2834

29-
const sandboxes =
30-
loading || !data.me.collection
31-
? []
32-
: data.me.collection.sandboxes;
35+
const sandboxes =
36+
loading || !data.me.collection
37+
? []
38+
: data.me.collection.sandboxes;
3339

34-
const possibleTemplates = getPossibleTemplates(sandboxes);
40+
const possibleTemplates = getPossibleTemplates(sandboxes);
3541

36-
// We want to hide all templates
37-
// TODO: make this a query variable for graphql and move the logic to the server
38-
const noTemplateSandboxes = sandboxes.filter(
39-
s => !s.customTemplate
40-
);
41-
const orderedSandboxes = store.dashboard.getFilteredSandboxes(
42-
noTemplateSandboxes
43-
);
42+
// We want to hide all templates
43+
// TODO: make this a query variable for graphql and move the logic to the server
44+
const noTemplateSandboxes = sandboxes.filter(
45+
s => !s.customTemplate
46+
);
47+
const orderedSandboxes = store.dashboard.getFilteredSandboxes(
48+
noTemplateSandboxes
49+
);
4450

45-
let mostUsedTemplate = null;
46-
if (!loading) {
47-
try {
48-
mostUsedTemplate = getMostUsedTemplate(sandboxes);
49-
} catch (e) {
50-
// Not critical
51+
let mostUsedTemplate = null;
52+
if (!loading) {
53+
try {
54+
mostUsedTemplate = getMostUsedTemplate(sandboxes);
55+
} catch (e) {
56+
// Not critical
57+
}
5158
}
52-
}
5359

54-
return (
55-
<Sandboxes
56-
ExtraElement={({ style }) => (
57-
<CreateNewSandbox
58-
collectionId={
59-
data &&
60-
data.me &&
61-
data.me.collection &&
62-
data.me.collection.id
63-
}
64-
mostUsedSandboxTemplate={mostUsedTemplate}
65-
style={style}
66-
/>
67-
)}
68-
isLoading={loading}
69-
possibleTemplates={possibleTemplates}
70-
Header={<Navigation teamId={teamId} path={path} />}
71-
// Fix React Virtualized First
72-
// SubHeader={
73-
// <Folders me={data.me} loading={loading} teamId={teamId} />
74-
// }
75-
sandboxes={orderedSandboxes}
76-
/>
77-
);
78-
}}
79-
</Observer>
80-
)}
81-
</Query>
60+
return (
61+
<Sandboxes
62+
ExtraElement={({ style }) => (
63+
<CreateNewSandbox
64+
collectionId={
65+
data &&
66+
data.me &&
67+
data.me.collection &&
68+
data.me.collection.id
69+
}
70+
mostUsedSandboxTemplate={mostUsedTemplate}
71+
style={style}
72+
/>
73+
)}
74+
isLoading={loading}
75+
possibleTemplates={possibleTemplates}
76+
Header={<Navigation teamId={teamId} path={path} />}
77+
// Fix React Virtualized First
78+
// SubHeader={
79+
// <Folders me={data.me} loading={loading} teamId={teamId} />
80+
// }
81+
sandboxes={orderedSandboxes}
82+
/>
83+
);
84+
}}
85+
</Observer>
86+
)}
87+
</Query>
88+
</>
8289
);
8390
};
8491

packages/app/src/app/pages/Dashboard/Content/routes/RecentSandboxes/index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { observer, inject } from 'app/componentConnectors';
3+
import Helmet from 'react-helmet';
34

45
import { Query } from 'react-apollo';
56

@@ -10,9 +11,11 @@ import { Content as Sandboxes } from '../../Sandboxes';
1011
import CreateNewSandbox from '../../CreateNewSandbox';
1112
import { RECENT_SANDBOXES_CONTENT_QUERY } from '../../../queries';
1213

13-
const RecentSandboxes = ({ store }) => {
14-
document.title = 'Recent Sandboxes - CodeSandbox';
15-
return (
14+
const RecentSandboxes = ({ store }) => (
15+
<>
16+
<Helmet>
17+
<title>Recent Sandboxes - CodeSandbox</title>
18+
</Helmet>
1619
<Query
1720
variables={{
1821
orderField: store.dashboard.orderBy.field,
@@ -57,7 +60,7 @@ const RecentSandboxes = ({ store }) => {
5760
);
5861
}}
5962
</Query>
60-
);
61-
};
63+
</>
64+
);
6265

6366
export default inject('signals', 'store')(observer(RecentSandboxes));

packages/app/src/app/pages/Dashboard/Content/routes/SearchSandboxes/index.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import Helmet from 'react-helmet';
23
import { Observer } from 'app/componentConnectors';
34
import { Query } from 'react-apollo';
45
import Fuse from 'fuse.js';
@@ -50,12 +51,6 @@ const SearchSandboxes = () => (
5051
? `${sandboxes.length} search results for '${search}'`
5152
: 'Search results for all sandboxes';
5253

53-
if (search) {
54-
document.title = `Search: '${search}' - CodeSandbox`;
55-
} else {
56-
document.title = `Search - CodeSandbox`;
57-
}
58-
5954
let possibleTemplates = [];
6055
if (sandboxes) {
6156
possibleTemplates = getPossibleTemplates(sandboxes);
@@ -66,14 +61,23 @@ const SearchSandboxes = () => (
6661
}
6762

6863
return (
69-
<Sandboxes
70-
isLoading={loading}
71-
Header={Header}
72-
page="search"
73-
hideOrder={Boolean(search)}
74-
sandboxes={loading ? [] : sandboxes}
75-
possibleTemplates={possibleTemplates}
76-
/>
64+
<>
65+
<Helmet>
66+
<title>
67+
{search
68+
? `Search: '${search}' - CodeSandbox`
69+
: 'Search - CodeSandbox'}
70+
</title>
71+
</Helmet>
72+
<Sandboxes
73+
isLoading={loading}
74+
Header={Header}
75+
page="search"
76+
hideOrder={Boolean(search)}
77+
sandboxes={loading ? [] : sandboxes}
78+
possibleTemplates={possibleTemplates}
79+
/>
80+
</>
7781
);
7882
}}
7983
</Observer>

packages/app/src/app/pages/Dashboard/Content/routes/TeamView/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import Helmet from 'react-helmet';
23
import { Query, Mutation } from 'react-apollo';
34
import { Observer } from 'app/componentConnectors';
45
import { sortBy } from 'lodash-es';
@@ -69,14 +70,15 @@ class TeamView extends React.PureComponent {
6970
return null;
7071
}
7172

72-
document.title = `${data.me.team.name} - CodeSandbox`;
73-
7473
const description =
7574
data.me.team.description ||
7675
`This is a description for your team. You can change this description and invite people to the team so they can edit the sandboxes of this team.`;
7776

7877
return (
7978
<TeamContainer>
79+
<Helmet>
80+
<title>{data.me.team.name} - CodeSandbox</title>
81+
</Helmet>
8082
<Section>
8183
<HeaderContainer>{data.me.team.name}</HeaderContainer>
8284
<Description>

packages/app/src/app/pages/Dashboard/Content/routes/Templates/Templates.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React, { useEffect } from 'react';
1+
import React from 'react';
2+
import Helmet from 'react-helmet';
23
import { sortBy } from 'lodash-es';
34
import { useQuery } from '@apollo/react-hooks';
45
import track from '@codesandbox/common/lib/utils/analytics';
@@ -12,17 +13,13 @@ import { LIST_TEMPLATES, unmakeTemplates } from '../../../queries';
1213
import { Container, Grid, EmptyTitle } from './elements';
1314
import { Navigation } from './Navigation';
1415

15-
export const Templates = props => {
16-
const teamId = props.match.params.teamId;
16+
export const Templates = ({ match }) => {
17+
const teamId = match.params.teamId;
1718

1819
const { loading, error, data } = useQuery(LIST_TEMPLATES, {
1920
variables: { teamId },
2021
});
2122

22-
useEffect(() => {
23-
document.title = `${teamId ? 'Team' : 'My'} Templates - CodeSandbox`;
24-
}, [teamId]);
25-
2623
if (error) {
2724
console.error(error);
2825
return <div>Error!</div>;
@@ -50,6 +47,9 @@ export const Templates = props => {
5047

5148
return (
5249
<Container>
50+
<Helmet>
51+
<title>{teamId ? 'Team' : 'My'} Templates - CodeSandbox</title>
52+
</Helmet>
5353
<Navigation teamId={teamId} number={sortedTemplates.length} />
5454
{!sortedTemplates.length && (
5555
<div>

packages/app/src/app/pages/Live/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
22
import { Link } from 'react-router-dom';
3+
import Helmet from 'react-helmet';
34
import { getSandboxName } from '@codesandbox/common/lib/utils/get-sandbox-name';
45
import Fullscreen from '@codesandbox/common/lib/components/flex/Fullscreen';
56
import Padding from '@codesandbox/common/lib/components/spacing/Padding';
@@ -171,15 +172,16 @@ class LivePage extends React.Component {
171172

172173
const sandbox = store.editor.currentSandbox;
173174

174-
if (sandbox) {
175-
document.title = `${getSandboxName(sandbox)} - CodeSandbox`;
176-
}
177-
178175
return (
179-
<React.Fragment>
176+
<>
177+
{sandbox && (
178+
<Helmet>
179+
<title>{getSandboxName(sandbox)} - CodeSandbox</title>
180+
</Helmet>
181+
)}
180182
<Editor match={match} />
181183
<QuickActions />
182-
</React.Fragment>
184+
</>
183185
);
184186
}
185187
}

packages/app/src/app/pages/Patron/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import Helmet from 'react-helmet';
23
import MaxWidth from '@codesandbox/common/lib/components/flex/MaxWidth';
34
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
45
import Centered from '@codesandbox/common/lib/components/flex/Centered';
@@ -14,10 +15,12 @@ class Patron extends React.Component {
1415
this.props.signals.patron.patronMounted();
1516
}
1617
render() {
17-
document.title = 'Patron - CodeSandbox';
18-
1918
return (
2019
<MaxWidth>
20+
<Helmet>
21+
<title>Patron - CodeSandbox</title>
22+
<script async src="https://js.stripe.com/v3/" />
23+
</Helmet>
2124
<Margin vertical={1.5} horizontal={1.5}>
2225
<Navigation title="Become a Patron" />
2326
<Content>

packages/app/src/app/pages/Profile/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* @flow */
22
import React from 'react';
3+
import Helmet from 'react-helmet';
34
import { Route, Switch } from 'react-router-dom';
45
import MaxWidth from '@codesandbox/common/lib/components/flex/MaxWidth';
56
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
@@ -51,9 +52,11 @@ class Profile extends React.Component<Props> {
5152

5253
const user = store.profile.current;
5354

54-
document.title = `${user.name || user.username} - CodeSandbox`;
5555
return (
5656
<Container>
57+
<Helmet>
58+
<title>{user.name || user.username} - CodeSandbox</title>
59+
</Helmet>
5760
<Header user={user} />
5861
<Content>
5962
<MaxWidth>

0 commit comments

Comments
 (0)