Skip to content

Commit e77f41f

Browse files
committed
🔨 Switch PreferencesModal to use useOvermind
1 parent f10c0d5 commit e77f41f

File tree

26 files changed

+453
-416
lines changed

26 files changed

+453
-416
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
@@ -18,9 +18,10 @@ export const setDevtoolsOpen: Action<boolean> = ({ state }, isOpen) => {
1818
state.preferences.showDevtools = isOpen;
1919
};
2020

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

2627
if (itemId === 'integrations') {

‎packages/app/src/app/pages/common/Modals/PreferencesModal/Appearance/EditorTheme/elements.ts‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
import { PreferenceText as PreferenceTextBase } from '@codesandbox/common/lib/components/Preference/PreferenceText';
22
import styled from 'styled-components';
33

4-
export const BigTitle = styled.h2`
5-
font-weight: 600;
6-
color: white;
7-
font-size: 1rem;
8-
padding-top: 1.5rem;
9-
margin-bottom: 0.5rem;
10-
`;
11-
124
export const PreferenceText = styled(PreferenceTextBase)`
135
font-family: 'Source Code Pro';
146
font-size: 0.8rem;

‎packages/app/src/app/pages/common/Modals/PreferencesModal/Appearance/EditorTheme/index.tsx‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import { Text } from '@codesandbox/components';
12
import React, { FunctionComponent } from 'react';
23

34
import { useOvermind } from 'app/overmind';
4-
import { Text } from '@codesandbox/components';
55

66
import { Rule } from '../../elements';
7+
78
import { PreferenceText } from './elements';
89

910
export const EditorTheme: FunctionComponent = () => {
@@ -23,39 +24,35 @@ export const EditorTheme: FunctionComponent = () => {
2324

2425
return (
2526
<div>
26-
<Text block size={3} marginTop={8} marginBottom={2}>
27+
<Text block marginBottom={2} marginTop={8} size={3}>
2728
Editor Theme
2829
</Text>
2930

30-
<Text variant="muted" size={3} block>
31+
<Text block size={3} variant="muted">
3132
You can select your editor theme by selecting File {'->'} Preferences{' '}
3233
{'->'} Color Theme in the menu bar.
3334
</Text>
3435

3536
<Rule />
3637

37-
<Text size={3} marginBottom={2} block>
38+
<Text block marginBottom={2} size={3}>
3839
Custom VSCode Theme
3940
</Text>
4041

41-
<Text variant="muted" size={3} marginBottom={4} block>
42-
After changing this setting you
43-
{"'"}
44-
ll have to reload the browser and select {'"'}
45-
Custom
46-
{'"'} as your color theme.
42+
<Text block marginBottom={4} size={3} variant="muted">
43+
{`After changing this setting you'll have to reload the browser and select 'Custom' as your color theme.`}
4744
</Text>
4845

4946
<PreferenceText
5047
block
51-
style={{ minHeight: 130 }}
5248
isTextArea
5349
placeholder={`You can use your own theme from VSCode directly:
5450
1. Open VSCode
5551
2. Press (CMD or CTRL) + SHIFT + P
5652
3. Enter: '> Developer: Generate Color Scheme From Current Settings'
5753
4. Copy the contents and paste them here!`}
5854
rows={7}
55+
style={{ minHeight: 130 }}
5956
{...bindValue('manualCustomVSCodeTheme', true)}
6057
/>
6158
</div>

‎packages/app/src/app/pages/common/Modals/PreferencesModal/Appearance/index.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import React, { FunctionComponent } from 'react';
21
import { Text } from '@codesandbox/components';
2+
import React, { FunctionComponent } from 'react';
3+
34
import { PreferenceContainer, SubContainer } from '../elements';
45
import { VSCodePlaceholder } from '../VSCodePlaceholder';
6+
57
import { EditorTheme } from './EditorTheme';
68

79
export const Appearance: FunctionComponent = () => (
810
<div>
9-
<Text size={4} marginBottom={6} block variant="muted" weight="bold">
11+
<Text block marginBottom={6} size={4} variant="muted" weight="bold">
1012
Appearance
1113
</Text>
1214

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import React, { FunctionComponent } from 'react';
2-
import { useOvermind } from 'app/overmind';
31
import { Text, Element } from '@codesandbox/components';
42
import Badge from '@codesandbox/common/lib/utils/badges/Badge';
3+
import React, { FunctionComponent } from 'react';
4+
5+
import { useOvermind } from 'app/overmind';
56

67
export const Badges: FunctionComponent = () => {
78
const {
@@ -15,14 +16,14 @@ export const Badges: FunctionComponent = () => {
1516

1617
return (
1718
<>
18-
<Text size={4} marginBottom={6} block variant="muted" weight="bold">
19+
<Text block marginBottom={6} size={4} variant="muted" weight="bold">
1920
Badges
2021
</Text>
2122

2223
<Text size={3}>
23-
You currently have {badges.length} badge
24-
{badges.length === 1 ? '' : 's'}. You can click on the badges to toggle
25-
visibility.
24+
You currently have{' '}
25+
{`${badges.length} badge${badges.length === 1 ? '' : 's'}`}. You can
26+
click on the badges to toggle visibility.
2627
</Text>
2728

2829
<Element marginTop={4}>
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
PreferenceContainer,
99
PaddedPreference,
1010
Rule,
11-
} from '../../elements';
11+
} from '../elements';
1212

1313
export const Prettier: FunctionComponent = () => {
1414
const {
@@ -17,7 +17,10 @@ export const Prettier: FunctionComponent = () => {
1717
},
1818
state: {
1919
preferences: {
20-
settings: { prettierConfig },
20+
settings: {
21+
prettierConfig,
22+
prettierConfig: { fluid },
23+
},
2124
},
2225
},
2326
} = useOvermind();
@@ -56,23 +59,16 @@ export const Prettier: FunctionComponent = () => {
5659
</Text>
5760

5861
<Rule />
59-
<Element
60-
css={css({
61-
pointerEvents: prettierConfig.fluid ? 'none' : 'all',
62-
})}
63-
>
62+
63+
<Element css={css({ pointerEvents: fluid ? 'none' : 'all' })}>
6464
<PaddedPreference
65-
style={{ opacity: prettierConfig.fluid ? 0.5 : 1 }}
65+
style={{ opacity: fluid ? 0.5 : 1 }}
6666
title="Print width"
6767
type="number"
6868
{...bindValue('printWidth')}
6969
/>
7070

71-
<Text
72-
size={2}
73-
variant="muted"
74-
style={{ opacity: prettierConfig.fluid ? 0.5 : 1 }}
75-
>
71+
<Text size={2} variant="muted" style={{ opacity: fluid ? 0.5 : 1 }}>
7672
Specify the line length that the printer will wrap on.
7773
</Text>
7874
</Element>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import React, { FunctionComponent } from 'react';
2-
31
import { Text } from '@codesandbox/components';
2+
import React, { FunctionComponent } from 'react';
43

54
import { Question } from './elements';
65
import { Prettier } from './Prettier';
76

87
export const CodeFormatting: FunctionComponent = () => (
98
<>
10-
<Text size={4} marginBottom={4} block variant="muted" weight="bold">
9+
<Text block marginBottom={4} size={4} variant="muted" weight="bold">
1110
Prettier Settings{' '}
1211
<a
1312
href="https://prettier.io/docs/en/options.html"
14-
target="_blank"
1513
rel="noopener noreferrer"
14+
target="_blank"
1615
>
1716
<Question />
1817
</a>
1918
</Text>
19+
2020
<Prettier />
2121
</>
2222
);
Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
1-
import React from 'react';
1+
import { Preference } from '@codesandbox/common/lib/components/Preference';
2+
import { Text, Element } from '@codesandbox/components';
3+
import React, { FunctionComponent, useState } from 'react';
4+
25
import Modal from 'app/components/Modal';
36
import { useOvermind } from 'app/overmind';
4-
import { Text, Element } from '@codesandbox/components';
5-
import { Preference } from '@codesandbox/common/lib/components/Preference';
67

7-
import { Alert } from '../../../Common/Alert';
8-
import { PreferenceContainer } from '../../elements';
9-
import { VSCodePlaceholder } from '../../VSCodePlaceholder';
8+
import { Alert } from '../../Common/Alert';
9+
10+
import { VSCodePlaceholder } from '../VSCodePlaceholder';
11+
12+
import { PreferenceContainer } from '../elements';
1013

11-
const isSafari: boolean = /^((?!chrome|android).)*safari/i.test(
12-
navigator.userAgent
13-
);
14-
const isFF: boolean = navigator.userAgent.toLowerCase().includes('firefox');
14+
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
15+
const isFF = navigator.userAgent.toLowerCase().includes('firefox');
1516

16-
export const EditorSettings: React.FC = () => {
17-
const [showModal, setShowModal] = React.useState(false);
17+
export const EditorSettings: FunctionComponent = () => {
1818
const {
19-
state: {
20-
preferences: { settings },
21-
},
2219
actions: {
2320
preferences: { settingChanged },
2421
},
22+
state: {
23+
preferences: { settings },
24+
},
2525
} = useOvermind();
26+
const [showModal, setShowModal] = useState(false);
2627

2728
const bindValue = (name: string) => ({
28-
value: settings[name],
2929
setValue: (value: any) => {
3030
settingChanged({ name, value });
31+
3132
setShowModal(true);
3233
},
34+
value: settings[name],
3335
});
3436

3537
return (
3638
<>
37-
<Text size={4} marginBottom={6} block variant="muted" weight="bold">
39+
<Text block marginBottom={6} size={4} variant="muted" weight="bold">
3840
Appearance
3941
</Text>
4042

@@ -49,35 +51,36 @@ export const EditorSettings: React.FC = () => {
4951
type="boolean"
5052
{...bindValue('vimMode')}
5153
/>
54+
5255
<Text
53-
marginTop={2}
5456
block
57+
marginTop={2}
5558
size={2}
56-
variant="muted"
5759
style={{ maxWidth: '60%', lineHeight: 1.5 }}
60+
variant="muted"
5861
>
5962
Toggling the VIM extension will require a refresh. When enabled,
6063
use the command palette to control VIM
6164
</Text>
6265
</PreferenceContainer>
6366
</Element>
67+
6468
{isSafari || isFF ? (
65-
<Text size={2} variant="muted" marginBottom={2} block marginTop={2}>
69+
<Text block marginBottom={2} marginTop={2} size={2} variant="muted">
6670
The VIM extension currently only works on Chrome and Microsoft Edge.
6771
</Text>
6872
) : null}
73+
6974
<Modal
7075
isOpen={showModal}
7176
onClose={() => setShowModal(false)}
7277
width={400}
7378
>
7479
<Alert
75-
title="Toggle VIM extension"
7680
description="You need to refresh the browser for this to take effect, do you want to do that now?"
7781
onCancel={() => setShowModal(false)}
78-
onPrimaryAction={() => {
79-
location.reload(true);
80-
}}
82+
onPrimaryAction={() => location.reload(true)}
83+
title="Toggle VIM extension"
8184
/>
8285
</Modal>
8386
</Element>

0 commit comments

Comments
 (0)