Skip to content

Commit 17867e5

Browse files
authored
Fix clicky conflict between folder menu and folder link (codesandbox#4057)
1 parent ff50980 commit 17867e5

File tree

2 files changed

+82
-65
lines changed

2 files changed

+82
-65
lines changed

packages/app/src/app/pages/NewDashboard/Components/FolderCard/index.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import React, { useState } from 'react';
2-
import { Link as LinkBase } from 'react-router-dom';
3-
import { Stack, Text, Input, Link, Element } from '@codesandbox/components';
2+
import { Link as RouterLink } from 'react-router-dom';
3+
import {
4+
Stack,
5+
Text,
6+
Input,
7+
Link,
8+
Element,
9+
isMenuClicked,
10+
} from '@codesandbox/components';
411
import css from '@styled-system/css';
512
import { useOvermind } from 'app/overmind';
613
import { join, dirname } from 'path';
@@ -37,7 +44,13 @@ export const FolderCard = ({
3744
};
3845

3946
return (
40-
<Link as={newFolder ? Element : LinkBase} to={`/new-dashboard/all` + path}>
47+
<Link
48+
as={newFolder ? Element : RouterLink}
49+
to={`/new-dashboard/all` + path}
50+
onClick={event => {
51+
if (isMenuClicked(event)) event.preventDefault();
52+
}}
53+
>
4154
<Stack
4255
direction="vertical"
4356
gap={2}

packages/app/src/app/pages/NewDashboard/Components/SandboxCard/index.tsx

Lines changed: 66 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import React, { useState, KeyboardEvent, ChangeEvent, FormEvent } from 'react';
2-
import { useHistory } from 'react-router-dom';
2+
import { Link as RouterLink } from 'react-router-dom';
33
import { useOvermind } from 'app/overmind';
44
import { sandboxUrl } from '@codesandbox/common/lib/utils/url-generator';
55
import { ESC } from '@codesandbox/common/lib/utils/keycodes';
66
import {
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

Comments
 (0)