11import React , { useState , KeyboardEvent , ChangeEvent , FormEvent } from 'react' ;
2- import { useHistory } from 'react-router-dom' ;
2+ import { Link as RouterLink } from 'react-router-dom' ;
33import { useOvermind } from 'app/overmind' ;
44import { sandboxUrl } from '@codesandbox/common/lib/utils/url-generator' ;
55import { ESC } from '@codesandbox/common/lib/utils/keycodes' ;
66import {
77 Stack ,
88 Element ,
99 Text ,
10+ Link ,
1011 Stats ,
1112 Input ,
1213 SkeletonText ,
@@ -20,7 +21,6 @@ export const SandboxCard = ({ sandbox, isTemplate = false, ...props }) => {
2021 const { actions } = useOvermind ( ) ;
2122 const [ edit , setEdit ] = useState ( false ) ;
2223 const [ newName , setNewName ] = useState ( sandboxTitle ) ;
23- const history = useHistory ( ) ;
2424
2525 const url = sandboxUrl ( {
2626 id : sandbox . id ,
@@ -63,73 +63,77 @@ export const SandboxCard = ({ sandbox, isTemplate = false, ...props }) => {
6363 } ;
6464
6565 return (
66- < Stack
67- direction = "vertical"
68- gap = { 2 }
69- css = { css ( {
70- width : '100%' ,
71- height : 240 ,
72- border : '1px solid' ,
73- borderColor : 'grays.600' ,
74- borderRadius : 'medium' ,
75- overflow : 'hidden' ,
76- transition : 'all ease-in-out' ,
77- transitionDuration : theme => theme . speeds [ 4 ] ,
78- ':hover, :focus, :focus-within' : {
79- cursor : edit ? 'normal' : 'pointer' ,
80- boxShadow : theme => '0 4px 16px 0 ' + theme . colors . grays [ 900 ] ,
81- } ,
82- } ) }
83- { ...props }
66+ < Link
67+ as = { RouterLink }
68+ to = { url }
8469 onClick = { event => {
85- if ( edit || isMenuClicked ( event ) ) return ;
86- history . push ( url ) ;
70+ if ( edit || isMenuClicked ( event ) ) event . preventDefault ( ) ;
8771 } }
8872 >
89- < Element
90- as = "div"
73+ < Stack
74+ direction = "vertical"
75+ gap = { 2 }
9176 css = { css ( {
92- height : 160 ,
93- backgroundColor : 'grays.600' ,
94- backgroundImage : `url(${ sandbox . screenshotUrl } )` ,
95- backgroundSize : 'cover' ,
96- backgroundPosition : 'center center' ,
97- backgroundRepeat : 'no-repeat' ,
77+ width : '100%' ,
78+ height : 240 ,
79+ border : '1px solid' ,
80+ borderColor : 'grays.600' ,
81+ borderRadius : 'medium' ,
82+ overflow : 'hidden' ,
83+ transition : 'all ease-in-out' ,
84+ transitionDuration : theme => theme . speeds [ 4 ] ,
85+ ':hover, :focus, :focus-within' : {
86+ cursor : edit ? 'normal' : 'pointer' ,
87+ boxShadow : theme => '0 4px 16px 0 ' + theme . colors . grays [ 900 ] ,
88+ } ,
9889 } ) }
99- />
100- < Stack justify = "space-between" align = "center" marginLeft = { 4 } >
101- { edit ? (
102- < form onSubmit = { onSubmit } >
103- < Input
104- value = { newName }
105- ref = { inputRef }
106- onChange = { onChange }
107- onKeyDown = { onKeyDown }
108- onBlur = { onBlur }
109- />
110- </ form >
111- ) : (
112- < Text size = { 3 } weight = "medium" >
113- { sandboxTitle }
114- </ Text >
115- ) }
116- < MenuOptions
117- sandbox = { sandbox }
118- isTemplate = { isTemplate }
119- onRename = { enterEditing }
90+ { ...props }
91+ >
92+ < Element
93+ as = "div"
94+ css = { css ( {
95+ height : 160 ,
96+ backgroundColor : 'grays.600' ,
97+ backgroundImage : `url(${ sandbox . screenshotUrl } )` ,
98+ backgroundSize : 'cover' ,
99+ backgroundPosition : 'center center' ,
100+ backgroundRepeat : 'no-repeat' ,
101+ } ) }
120102 />
103+ < Stack justify = "space-between" align = "center" marginLeft = { 4 } >
104+ { edit ? (
105+ < form onSubmit = { onSubmit } >
106+ < Input
107+ value = { newName }
108+ ref = { inputRef }
109+ onChange = { onChange }
110+ onKeyDown = { onKeyDown }
111+ onBlur = { onBlur }
112+ />
113+ </ form >
114+ ) : (
115+ < Text size = { 3 } weight = "medium" >
116+ { sandboxTitle }
117+ </ Text >
118+ ) }
119+ < MenuOptions
120+ sandbox = { sandbox }
121+ isTemplate = { isTemplate }
122+ onRename = { enterEditing }
123+ />
124+ </ Stack >
125+ < Stack marginX = { 4 } >
126+ < Stats
127+ css = { css ( { fontSize : 2 } ) }
128+ sandbox = { {
129+ viewCount : kFormatter ( sandbox . viewCount ) ,
130+ likeCount : kFormatter ( sandbox . likeCount ) ,
131+ forkCount : kFormatter ( sandbox . forkCount ) ,
132+ } }
133+ />
134+ </ Stack >
121135 </ Stack >
122- < Stack marginX = { 4 } >
123- < Stats
124- css = { css ( { fontSize : 2 } ) }
125- sandbox = { {
126- viewCount : kFormatter ( sandbox . viewCount ) ,
127- likeCount : kFormatter ( sandbox . likeCount ) ,
128- forkCount : kFormatter ( sandbox . forkCount ) ,
129- } }
130- />
131- </ Stack >
132- </ Stack >
136+ </ Link >
133137 ) ;
134138} ;
135139
0 commit comments