Skip to content

Commit f9906fc

Browse files
committed
refactor: RecentSandboxes to use apollo react hooks
1 parent 57d94f0 commit f9906fc

File tree

1 file changed

+34
-45
lines changed
  • packages/app/src/app/pages/Dashboard/Content/routes/RecentSandboxes

1 file changed

+34
-45
lines changed
Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import Helmet from 'react-helmet';
3-
import { Query } from 'react-apollo';
3+
import { useQuery } from '@apollo/react-hooks';
44

55
import { useOvermind } from 'app/overmind';
66
import getMostUsedTemplate from '../../../utils/get-most-used-template';
@@ -10,55 +10,44 @@ import { RECENT_SANDBOXES_CONTENT_QUERY } from '../../../queries';
1010

1111
export const RecentSandboxes = () => {
1212
const { state } = useOvermind();
13+
const { loading, error, data } = useQuery(RECENT_SANDBOXES_CONTENT_QUERY, {
14+
variables: {
15+
orderField: state.dashboard.orderBy.field,
16+
orderDirection: state.dashboard.orderBy.order.toUpperCase(),
17+
},
18+
});
19+
const sandboxes = loading ? [] : (data && data.me && data.me.sandboxes) || [];
20+
21+
let mostUsedTemplate = null;
22+
try {
23+
mostUsedTemplate = getMostUsedTemplate(sandboxes);
24+
} catch (e) {
25+
// Not critical
26+
}
27+
28+
// We want to hide all templates
29+
// TODO: make this a query variable for graphql and move the logic to the server
30+
const noTemplateSandboxes = sandboxes.filter(s => !s.customTemplate);
31+
1332
return (
1433
<>
1534
<Helmet>
1635
<title>Recent Sandboxes - CodeSandbox</title>
1736
</Helmet>
18-
<Query
19-
variables={{
20-
orderField: state.dashboard.orderBy.field,
21-
orderDirection: state.dashboard.orderBy.order.toUpperCase(),
22-
}}
23-
query={RECENT_SANDBOXES_CONTENT_QUERY}
24-
>
25-
{({ loading, error, data }) => {
26-
if (error) {
27-
return <div>Error!</div>;
28-
}
29-
30-
const sandboxes = loading
31-
? []
32-
: (data && data.me && data.me.sandboxes) || [];
33-
34-
let mostUsedTemplate = null;
35-
try {
36-
mostUsedTemplate = getMostUsedTemplate(sandboxes);
37-
} catch (e) {
38-
// Not critical
39-
}
40-
41-
// We want to hide all templates
42-
// TODO: make this a query variable for graphql and move the logic to the server
43-
const noTemplateSandboxes = sandboxes.filter(s => !s.customTemplate);
44-
45-
return (
46-
<Sandboxes
47-
isLoading={loading}
48-
Header="Recent Sandboxes"
49-
ExtraElement={({ style }) => (
50-
<CreateNewSandbox
51-
mostUsedSandboxTemplate={mostUsedTemplate}
52-
style={style}
53-
/>
54-
)}
55-
hideFilters
56-
sandboxes={noTemplateSandboxes}
57-
page="recent"
58-
/>
59-
);
60-
}}
61-
</Query>
37+
{error && <div>Error!</div>}
38+
<Sandboxes
39+
isLoading={loading}
40+
Header="Recent Sandboxes"
41+
ExtraElement={({ style }) => (
42+
<CreateNewSandbox
43+
mostUsedSandboxTemplate={mostUsedTemplate}
44+
style={style}
45+
/>
46+
)}
47+
hideFilters
48+
sandboxes={noTemplateSandboxes}
49+
page="recent"
50+
/>
6251
</>
6352
);
6453
};

0 commit comments

Comments
 (0)