|
1 | 1 | import React from 'react'; |
2 | | -import { observer, inject } from 'app/componentConnectors'; |
3 | 2 | import Helmet from 'react-helmet'; |
4 | | - |
5 | 3 | import { Query } from 'react-apollo'; |
6 | 4 |
|
| 5 | +import { useOvermind } from 'app/overmind'; |
7 | 6 | import getMostUsedTemplate from '../../../utils/get-most-used-template'; |
8 | | - |
9 | 7 | import { Content as Sandboxes } from '../../Sandboxes'; |
10 | | - |
11 | 8 | import CreateNewSandbox from '../../CreateNewSandbox'; |
12 | 9 | import { RECENT_SANDBOXES_CONTENT_QUERY } from '../../../queries'; |
13 | 10 |
|
14 | | -const RecentSandboxes = ({ store }) => ( |
15 | | - <> |
16 | | - <Helmet> |
17 | | - <title>Recent Sandboxes - CodeSandbox</title> |
18 | | - </Helmet> |
19 | | - <Query |
20 | | - variables={{ |
21 | | - orderField: store.dashboard.orderBy.field, |
22 | | - orderDirection: store.dashboard.orderBy.order.toUpperCase(), |
23 | | - }} |
24 | | - query={RECENT_SANDBOXES_CONTENT_QUERY} |
25 | | - > |
26 | | - {({ loading, error, data }) => { |
27 | | - if (error) { |
28 | | - return <div>Error!</div>; |
29 | | - } |
| 11 | +const RecentSandboxes = () => { |
| 12 | + const { state } = useOvermind(); |
| 13 | + return ( |
| 14 | + <> |
| 15 | + <Helmet> |
| 16 | + <title>Recent Sandboxes - CodeSandbox</title> |
| 17 | + </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 | + } |
30 | 29 |
|
31 | | - const sandboxes = loading |
32 | | - ? [] |
33 | | - : (data && data.me && data.me.sandboxes) || []; |
| 30 | + const sandboxes = loading |
| 31 | + ? [] |
| 32 | + : (data && data.me && data.me.sandboxes) || []; |
34 | 33 |
|
35 | | - let mostUsedTemplate = null; |
36 | | - try { |
37 | | - mostUsedTemplate = getMostUsedTemplate(sandboxes); |
38 | | - } catch (e) { |
39 | | - // Not critical |
40 | | - } |
| 34 | + let mostUsedTemplate = null; |
| 35 | + try { |
| 36 | + mostUsedTemplate = getMostUsedTemplate(sandboxes); |
| 37 | + } catch (e) { |
| 38 | + // Not critical |
| 39 | + } |
41 | 40 |
|
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(s => !s.customTemplate); |
| 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); |
45 | 44 |
|
46 | | - return ( |
47 | | - <Sandboxes |
48 | | - isLoading={loading} |
49 | | - Header="Recent Sandboxes" |
50 | | - ExtraElement={({ style }) => ( |
51 | | - <CreateNewSandbox |
52 | | - mostUsedSandboxTemplate={mostUsedTemplate} |
53 | | - style={style} |
54 | | - /> |
55 | | - )} |
56 | | - hideFilters |
57 | | - sandboxes={noTemplateSandboxes} |
58 | | - page="recent" |
59 | | - /> |
60 | | - ); |
61 | | - }} |
62 | | - </Query> |
63 | | - </> |
64 | | -); |
| 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> |
| 62 | + </> |
| 63 | + ); |
| 64 | +}; |
65 | 65 |
|
66 | | -export default inject('signals', 'store')(observer(RecentSandboxes)); |
| 66 | +export default RecentSandboxes; |
0 commit comments