Skip to content

Commit ac00327

Browse files
committed
🔨 Switch Dependencies to use useOvermind
1 parent 4534009 commit ac00327

File tree

15 files changed

+336
-320
lines changed

15 files changed

+336
-320
lines changed

‎packages/app/src/app/overmind/actions.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,10 @@ type ModalName =
7474
| 'netlifyLogs'
7575
| 'newSandbox'
7676
| 'preferences'
77-
| 'share'
7877
| 'searchDependencies'
78+
| 'share'
7979
| 'signInForTemplates'
8080
| 'userSurvey';
81-
8281
export const modalOpened: Action<{ modal: ModalName; message?: string }> = (
8382
{ state, effects },
8483
{ modal, message }

‎packages/app/src/app/overmind/namespaces/editor/actions.ts‎

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const addNpmDependency: AsyncAction<{
2828
version?: string;
2929
isDev?: boolean;
3030
}> = withOwnedSandbox(
31-
async ({ effects, actions, state }, { name, version, isDev }) => {
31+
async ({ actions, effects, state }, { name, version, isDev }) => {
3232
effects.analytics.track('Add NPM Dependency');
3333
state.currentModal = null;
3434
let newVersion = version;
@@ -46,22 +46,22 @@ export const addNpmDependency: AsyncAction<{
4646
}
4747
);
4848

49-
export const npmDependencyRemoved: AsyncAction<{
50-
name: string;
51-
}> = withOwnedSandbox(async ({ state, effects, actions }, { name }) => {
52-
effects.analytics.track('Remove NPM Dependency');
49+
export const npmDependencyRemoved: AsyncAction<string> = withOwnedSandbox(
50+
async ({ actions, effects, state }, name) => {
51+
effects.analytics.track('Remove NPM Dependency');
5352

54-
const { parsed } = state.editor.parsedConfigurations.package;
53+
const { parsed } = state.editor.parsedConfigurations.package;
5554

56-
delete parsed.dependencies[name];
57-
parsed.dependencies = sortObjectByKeys(parsed.dependencies);
55+
delete parsed.dependencies[name];
56+
parsed.dependencies = sortObjectByKeys(parsed.dependencies);
5857

59-
await actions.editor.internal.saveCode({
60-
code: JSON.stringify(parsed, null, 2),
61-
moduleShortid: state.editor.currentPackageJSON.shortid,
62-
cbID: null,
63-
});
64-
});
58+
await actions.editor.internal.saveCode({
59+
code: JSON.stringify(parsed, null, 2),
60+
moduleShortid: state.editor.currentPackageJSON.shortid,
61+
cbID: null,
62+
});
63+
}
64+
);
6565

6666
export const sandboxChanged: AsyncAction<{ id: string }> = withLoadApp<{
6767
id: string;
@@ -471,9 +471,10 @@ export const fetchEnvironmentVariables: AsyncAction = async ({
471471
);
472472
};
473473

474-
export const updateEnvironmentVariables: AsyncAction<
475-
EnvironmentVariable
476-
> = async ({ state, effects }, environmentVariable) => {
474+
export const updateEnvironmentVariables: AsyncAction<EnvironmentVariable> = async (
475+
{ state, effects },
476+
environmentVariable
477+
) => {
477478
state.editor.currentSandbox.environmentVariables = await effects.api.saveEnvironmentVariable(
478479
state.editor.currentId,
479480
environmentVariable

‎packages/app/src/app/overmind/namespaces/workspace/actions.ts‎

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -122,38 +122,38 @@ export const sandboxInfoUpdated: AsyncAction = withOwnedSandbox(
122122
}
123123
);
124124

125-
export const externalResourceAdded: AsyncAction<{
126-
resource: string;
127-
}> = withOwnedSandbox(async ({ state, effects, actions }, { resource }) => {
128-
const { externalResources } = state.editor.currentSandbox;
125+
export const externalResourceAdded: AsyncAction<string> = withOwnedSandbox(
126+
async ({ effects, state }, resource) => {
127+
const { externalResources } = state.editor.currentSandbox;
129128

130-
externalResources.push(resource);
129+
externalResources.push(resource);
131130

132-
try {
133-
await effects.api.createResource(state.editor.currentId, resource);
134-
} catch (error) {
135-
externalResources.splice(externalResources.indexOf(resource), 1);
136-
effects.notificationToast.error('Could not save external resource');
131+
try {
132+
await effects.api.createResource(state.editor.currentId, resource);
133+
} catch (error) {
134+
externalResources.splice(externalResources.indexOf(resource), 1);
135+
effects.notificationToast.error('Could not save external resource');
136+
}
137137
}
138-
});
138+
);
139139

140-
export const externalResourceRemoved: AsyncAction<{
141-
resource: string;
142-
}> = withOwnedSandbox(async ({ state, effects, actions }, { resource }) => {
143-
const { externalResources } = state.editor.currentSandbox;
144-
const resourceIndex = externalResources.indexOf(resource);
140+
export const externalResourceRemoved: AsyncAction<string> = withOwnedSandbox(
141+
async ({ effects, state }, resource) => {
142+
const { externalResources } = state.editor.currentSandbox;
143+
const resourceIndex = externalResources.indexOf(resource);
145144

146-
externalResources.splice(resourceIndex, 1);
145+
externalResources.splice(resourceIndex, 1);
147146

148-
try {
149-
await effects.api.deleteResource(state.editor.currentId, resource);
150-
} catch (error) {
151-
externalResources.splice(resourceIndex, 0, resource);
152-
effects.notificationToast.error(
153-
'Could not save removal of external resource'
154-
);
147+
try {
148+
await effects.api.deleteResource(state.editor.currentId, resource);
149+
} catch (error) {
150+
externalResources.splice(resourceIndex, 0, resource);
151+
effects.notificationToast.error(
152+
'Could not save removal of external resource'
153+
);
154+
}
155155
}
156-
});
156+
);
157157

158158
export const integrationsOpened: Action = ({ state }) => {
159159
state.preferences.itemId = 'integrations';

‎packages/app/src/app/pages/Sandbox/Editor/Workspace/Dependencies/AddFont/FontPicker/List.tsx‎

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,55 @@
1-
import React, { FunctionComponent, useState, useMemo } from 'react';
1+
import React, {
2+
ChangeEvent,
3+
FunctionComponent,
4+
useMemo,
5+
useState,
6+
} from 'react';
7+
28
import { List, SearchFonts, FontLI, FontFamily, Arrow } from './elements';
39
import { fonts } from './fonts';
410

511
type Props = {
6-
onSelection: (e: any) => void;
712
activeFontFamily: string;
13+
onSelection: (font: string) => void;
814
};
9-
1015
export const FontList: FunctionComponent<Props> = ({
11-
onSelection,
1216
activeFontFamily,
17+
onSelection,
1318
}) => {
1419
const [searchTerm, setSearchTerm] = useState('');
15-
const usedFonts = fonts.slice(0, 200);
16-
17-
const updateSearch = (e: any) => setSearchTerm(e.target.value);
1820

19-
const getFonts: string[] = useMemo(
21+
const getFonts = useMemo(
2022
() =>
21-
usedFonts.filter(f =>
22-
f.toLowerCase().includes(searchTerm.trim().toLowerCase())
23-
),
24-
[searchTerm, usedFonts]
23+
fonts
24+
.slice(0, 200)
25+
.filter(font =>
26+
font.toLowerCase().includes(searchTerm.trim().toLowerCase())
27+
),
28+
[searchTerm]
2529
);
30+
31+
const updateSearch = ({ target: { value } }: ChangeEvent<HTMLInputElement>) =>
32+
setSearchTerm(value);
33+
2634
return (
2735
<>
2836
<Arrow />
37+
2938
<List>
3039
<SearchFonts
3140
type="text"
3241
value={searchTerm}
3342
onChange={updateSearch}
3443
placeholder="Search Typefaces"
3544
/>
36-
{getFonts.map((font: string) => (
45+
46+
{getFonts.map(font => (
3747
<FontLI
3848
key={font}
3949
onClick={() => onSelection(font)}
4050
onKeyPress={() => onSelection(font)}
4151
>
42-
<FontFamily type="button" active={font === activeFontFamily}>
52+
<FontFamily active={font === activeFontFamily} type="button">
4353
{font}
4454
</FontFamily>
4555
</FontLI>

0 commit comments

Comments
 (0)