Skip to content

Commit b1590c0

Browse files
jyash97SaraVieira
authored andcommitted
fix(ux): disable button for already added fonts (codesandbox#3005)
1 parent 92a1131 commit b1590c0

File tree

2 files changed

+15
-3
lines changed
  • packages/app/src/app/pages/Sandbox/Editor/Workspace/Dependencies

2 files changed

+15
-3
lines changed

packages/app/src/app/pages/Sandbox/Editor/Workspace/Dependencies/AddFont/index.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Button } from '@codesandbox/common/lib/components/Button';
33
import { FontPicker } from './FontPicker/index';
44
import { Container } from './elements';
55

6-
export const AddFont = ({ addResource }) => {
6+
export const AddFont = ({ addResource, addedResource }) => {
77
const [activeFontFamily, setActiveFontFamily] = useState('Roboto');
88

99
const addFont = async () => {
@@ -14,6 +14,10 @@ export const AddFont = ({ addResource }) => {
1414
}
1515
};
1616

17+
const fontAlreadyExists = addedResource.filter(font =>
18+
font.includes(activeFontFamily)
19+
);
20+
1721
return (
1822
<>
1923
<Container>
@@ -24,8 +28,15 @@ export const AddFont = ({ addResource }) => {
2428
/>
2529
</Container>
2630
<Container>
27-
<Button disabled={!activeFontFamily} block small onClick={addFont}>
28-
Add Typeface
31+
<Button
32+
disabled={!activeFontFamily || fontAlreadyExists.length}
33+
block
34+
small
35+
onClick={addFont}
36+
>
37+
{fontAlreadyExists.length > 0
38+
? 'Typeface already added'
39+
: 'Add Typeface'}
2940
</Button>
3041
</Container>
3142
</>

packages/app/src/app/pages/Sandbox/Editor/Workspace/Dependencies/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export const Dependencies: FunctionComponent = () => {
115115
resource,
116116
})
117117
}
118+
addedResource={fonts}
118119
/>
119120
{fonts.map(resource => (
120121
<ExternalFonts

0 commit comments

Comments
 (0)