1
1
import React from 'react' ;
2
2
import Helmet from 'react-helmet' ;
3
- import { Query } from 'react-apollo ' ;
3
+ import { useQuery } from '@apollo/ react-hooks ' ;
4
4
5
5
import { useOvermind } from 'app/overmind' ;
6
6
import getMostUsedTemplate from '../../../utils/get-most-used-template' ;
@@ -10,55 +10,44 @@ import { RECENT_SANDBOXES_CONTENT_QUERY } from '../../../queries';
10
10
11
11
export const RecentSandboxes = ( ) => {
12
12
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
+
13
32
return (
14
33
< >
15
34
< Helmet >
16
35
< title > Recent Sandboxes - CodeSandbox</ title >
17
36
</ 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
+ />
62
51
</ >
63
52
) ;
64
53
} ;
0 commit comments