File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
packages/app/src/app/pages/Sandbox/Editor/Workspace/Dependencies Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { Button } from '@codesandbox/common/lib/components/Button';
33import { FontPicker } from './FontPicker/index' ;
44import { 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 </ >
Original file line number Diff line number Diff line change @@ -115,6 +115,7 @@ export const Dependencies: FunctionComponent = () => {
115115 resource,
116116 } )
117117 }
118+ addedResource = { fonts }
118119 />
119120 { fonts . map ( resource => (
120121 < ExternalFonts
You can’t perform that action at this time.
0 commit comments