Skip to content

Commit d4810aa

Browse files
committed
πŸ”¨ Switch PreferencesModal to use useOvermind
1 parent f2f3c22 commit d4810aa

File tree

20 files changed

+349
-298
lines changed

20 files changed

+349
-298
lines changed

β€Žpackages/app/src/app/overmind/namespaces/preferences/actions.tsβ€Ž

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ export const setDevtoolsOpen: Action<boolean> = ({ state }, isOpen) => {
1919
state.preferences.showDevtools = isOpen;
2020
};
2121

22-
export const itemIdChanged: AsyncAction<{
23-
itemId: string;
24-
}> = async ({ state, actions, effects }, { itemId }) => {
22+
export const itemIdChanged: AsyncAction<string> = async (
23+
{ effects, state, actions },
24+
itemId
25+
) => {
2526
state.preferences.itemId = itemId;
2627

2728
if (itemId === 'keybindings') {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useOvermind } from 'app/overmind';
44
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
55
import Badge from '@codesandbox/common/lib/utils/badges/Badge';
66

7-
import { Title } from '../elements';
7+
import { Title } from './elements';
88

99
export const Badges: FunctionComponent = () => {
1010
const {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
PaddedPreference,
99
SubDescription,
1010
Rule,
11-
} from '../../elements';
11+
} from '../elements';
1212

1313
export const Prettier: FunctionComponent = () => {
1414
const {
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
1+
import React, { FunctionComponent, useState } from 'react';
2+
13
import { Alert } from 'app/components/Alert';
24
import Modal from 'app/components/Modal';
35
import { useOvermind } from 'app/overmind';
4-
import React from 'react';
56

67
import {
78
PaddedPreference,
89
PreferenceContainer,
910
SubContainer,
1011
SubDescription,
1112
Title,
12-
} from '../../elements';
13-
import { VSCodePlaceholder } from '../../VSCodePlaceholder';
14-
15-
const isSafari: boolean = /^((?!chrome|android).)*safari/i.test(
16-
navigator.userAgent
17-
);
18-
const isFF: boolean = navigator.userAgent.toLowerCase().includes('firefox');
13+
} from '../elements';
14+
import { VSCodePlaceholder } from '../VSCodePlaceholder';
1915

20-
export const EditorSettings: React.FC = () => {
21-
const [showModal, setShowModal] = React.useState(false);
16+
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
17+
const isFF = navigator.userAgent.toLowerCase().includes('firefox');
2218

19+
export const EditorSettings: FunctionComponent = () => {
2320
const {
24-
state: {
25-
preferences: { settings },
26-
},
2721
actions: {
2822
preferences: { settingChanged },
2923
},
24+
state: {
25+
preferences: { settings },
26+
},
3027
} = useOvermind();
28+
const [showModal, setShowModal] = useState(false);
3129

3230
const bindValue = (name: string) => ({
33-
value: settings[name],
3431
setValue: (value: any) => {
3532
settingChanged({ name, value });
33+
3634
setShowModal(true);
3735
},
36+
value: settings[name],
3837
});
3938

4039
return (
@@ -51,11 +50,13 @@ export const EditorSettings: React.FC = () => {
5150
type="boolean"
5251
{...bindValue('vimMode')}
5352
/>
53+
5454
<SubDescription>
5555
Toggling the VIM extension will require a refresh. When enabled, use
5656
the command palette to control VIM
5757
</SubDescription>
5858
</PreferenceContainer>
59+
5960
{isSafari || isFF ? (
6061
<SubDescription
6162
css={`
@@ -65,18 +66,17 @@ export const EditorSettings: React.FC = () => {
6566
The VIM extension currently only works on Chrome and Microsoft Edge.
6667
</SubDescription>
6768
) : null}
69+
6870
<Modal
6971
isOpen={showModal}
7072
onClose={() => setShowModal(false)}
7173
width={400}
7274
>
7375
<Alert
74-
title="Toggle VIM extension"
7576
body="You need to refresh the browser for this to take effect, do you want to do that now?"
7677
onCancel={() => setShowModal(false)}
77-
onConfirm={() => {
78-
location.reload(true);
79-
}}
78+
onConfirm={() => location.reload(true)}
79+
title="Toggle VIM extension"
8080
/>
8181
</Modal>
8282
</SubContainer>
Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
1-
import React from 'react';
1+
import React, { FunctionComponent } from 'react';
2+
23
import { useOvermind } from 'app/overmind';
34

45
import {
5-
Title,
6-
SubContainer,
7-
PreferenceContainer,
86
PaddedPreference,
9-
SubDescription,
7+
PreferenceContainer,
108
Rule,
11-
} from '../../elements';
12-
13-
export const PreviewSettings: React.FC = () => {
14-
const { state, actions } = useOvermind();
15-
const bindValue = name => ({
16-
value: state.preferences.settings[name],
17-
setValue: value =>
18-
actions.preferences.settingChanged({
19-
name,
20-
value,
21-
}),
9+
SubContainer,
10+
SubDescription,
11+
Title,
12+
} from '../elements';
13+
14+
export const PreviewSettings: FunctionComponent = () => {
15+
const {
16+
actions: {
17+
preferences: { settingChanged },
18+
},
19+
state: {
20+
preferences: { settings },
21+
},
22+
} = useOvermind();
23+
24+
const bindValue = (name: string) => ({
25+
setValue: value => settingChanged({ name, value }),
26+
value: settings[name],
2227
});
2328

2429
return (
@@ -29,29 +34,36 @@ export const PreviewSettings: React.FC = () => {
2934
<PreferenceContainer>
3035
<PaddedPreference
3136
title="Preview on edit"
37+
tooltip="Only update on save"
3238
type="boolean"
3339
{...bindValue('livePreviewEnabled')}
34-
tooltip="Only update on save"
3540
/>
41+
3642
<SubDescription>
3743
Preview the latest code without saving.
3844
</SubDescription>
45+
3946
<Rule />
47+
4048
<PaddedPreference
4149
title="Clear console"
50+
tooltip="Clear console when executing"
4251
type="boolean"
4352
{...bindValue('clearConsoleEnabled')}
44-
tooltip="Clear console when executing"
4553
/>
54+
4655
<SubDescription>
4756
Clear your developer console between every execution.
4857
</SubDescription>
58+
4959
<Rule />
60+
5061
<PaddedPreference
5162
title="Instant preview"
5263
type="boolean"
5364
{...bindValue('instantPreviewEnabled')}
5465
/>
66+
5567
<SubDescription>Show preview on every keypress.</SubDescription>
5668
</PreferenceContainer>
5769
</SubContainer>
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import React from 'react';
1+
import React, { FunctionComponent } from 'react';
22

33
import {
4-
Title,
4+
PreferenceContainer,
55
SubContainer,
66
SubDescription,
7-
PreferenceContainer,
8-
} from '../elements';
7+
Title,
8+
} from './elements';
99

10-
export const Experiments: React.FunctionComponent = () => (
10+
export const Experiments: FunctionComponent = () => (
1111
<div>
1212
<Title>Experiments</Title>
1313

β€Žpackages/app/src/app/pages/common/Modals/PreferencesModal/Integrations/index.jsβ€Ž

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React, { FunctionComponent } from 'react';
2+
3+
import { GithubIntegration } from 'app/pages/common/GithubIntegration';
4+
import { ZeitIntegration } from 'app/pages/common/ZeitIntegration';
5+
6+
import { Title } from '../elements';
7+
8+
import { Container } from './elements';
9+
10+
export const Integrations: FunctionComponent = () => (
11+
<div>
12+
<Title>Integrations</Title>
13+
14+
<Container>
15+
<ZeitIntegration />
16+
17+
<GithubIntegration />
18+
</Container>
19+
</div>
20+
);

0 commit comments

Comments
Β (0)