diff --git a/packages/app/src/app/overmind/namespaces/preferences/actions.ts b/packages/app/src/app/overmind/namespaces/preferences/actions.ts index 66bf2452f78..b70cdf671e4 100755 --- a/packages/app/src/app/overmind/namespaces/preferences/actions.ts +++ b/packages/app/src/app/overmind/namespaces/preferences/actions.ts @@ -18,9 +18,10 @@ export const setDevtoolsOpen: Action = ({ state }, isOpen) => { state.preferences.showDevtools = isOpen; }; -export const itemIdChanged: AsyncAction<{ - itemId: string; -}> = async ({ state, actions, effects }, { itemId }) => { +export const itemIdChanged: AsyncAction = async ( + { actions, state }, + itemId +) => { state.preferences.itemId = itemId; if (itemId === 'integrations') { diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/Appearance/EditorTheme/elements.ts b/packages/app/src/app/pages/common/Modals/PreferencesModal/Appearance/EditorTheme/elements.ts index a7c0552e67c..008743eed80 100644 --- a/packages/app/src/app/pages/common/Modals/PreferencesModal/Appearance/EditorTheme/elements.ts +++ b/packages/app/src/app/pages/common/Modals/PreferencesModal/Appearance/EditorTheme/elements.ts @@ -1,14 +1,6 @@ import { PreferenceText as PreferenceTextBase } from '@codesandbox/common/lib/components/Preference/PreferenceText'; import styled from 'styled-components'; -export const BigTitle = styled.h2` - font-weight: 600; - color: white; - font-size: 1rem; - padding-top: 1.5rem; - margin-bottom: 0.5rem; -`; - export const PreferenceText = styled(PreferenceTextBase)` font-family: 'Source Code Pro'; font-size: 0.8rem; diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/Appearance/EditorTheme/index.tsx b/packages/app/src/app/pages/common/Modals/PreferencesModal/Appearance/EditorTheme/index.tsx index e4db81c7004..42f879ea054 100644 --- a/packages/app/src/app/pages/common/Modals/PreferencesModal/Appearance/EditorTheme/index.tsx +++ b/packages/app/src/app/pages/common/Modals/PreferencesModal/Appearance/EditorTheme/index.tsx @@ -1,9 +1,10 @@ +import { Text } from '@codesandbox/components'; import React, { FunctionComponent } from 'react'; import { useOvermind } from 'app/overmind'; -import { Text } from '@codesandbox/components'; import { Rule } from '../../elements'; + import { PreferenceText } from './elements'; export const EditorTheme: FunctionComponent = () => { @@ -23,32 +24,27 @@ export const EditorTheme: FunctionComponent = () => { return (
- + Editor Theme - + You can select your editor theme by selecting File {'->'} Preferences{' '} {'->'} Color Theme in the menu bar. - + Custom VSCode Theme - - After changing this setting you - {"'"} - ll have to reload the browser and select {'"'} - Custom - {'"'} as your color theme. + + {`After changing this setting you'll have to reload the browser and select 'Custom' as your color theme.`} { 3. Enter: '> Developer: Generate Color Scheme From Current Settings' 4. Copy the contents and paste them here!`} rows={7} + style={{ minHeight: 130 }} {...bindValue('manualCustomVSCodeTheme', true)} />
diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/Appearance/index.tsx b/packages/app/src/app/pages/common/Modals/PreferencesModal/Appearance/index.tsx index 8201f10d685..1c47b31f8dd 100644 --- a/packages/app/src/app/pages/common/Modals/PreferencesModal/Appearance/index.tsx +++ b/packages/app/src/app/pages/common/Modals/PreferencesModal/Appearance/index.tsx @@ -1,12 +1,14 @@ -import React, { FunctionComponent } from 'react'; import { Text } from '@codesandbox/components'; +import React, { FunctionComponent } from 'react'; + import { PreferenceContainer, SubContainer } from '../elements'; import { VSCodePlaceholder } from '../VSCodePlaceholder'; + import { EditorTheme } from './EditorTheme'; export const Appearance: FunctionComponent = () => (
- + Appearance diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/Badges/index.tsx b/packages/app/src/app/pages/common/Modals/PreferencesModal/Badges.tsx similarity index 79% rename from packages/app/src/app/pages/common/Modals/PreferencesModal/Badges/index.tsx rename to packages/app/src/app/pages/common/Modals/PreferencesModal/Badges.tsx index b0d0be5da4a..aebfefac772 100644 --- a/packages/app/src/app/pages/common/Modals/PreferencesModal/Badges/index.tsx +++ b/packages/app/src/app/pages/common/Modals/PreferencesModal/Badges.tsx @@ -1,7 +1,8 @@ -import React, { FunctionComponent } from 'react'; -import { useOvermind } from 'app/overmind'; import { Text, Element } from '@codesandbox/components'; import Badge from '@codesandbox/common/lib/utils/badges/Badge'; +import React, { FunctionComponent } from 'react'; + +import { useOvermind } from 'app/overmind'; export const Badges: FunctionComponent = () => { const { @@ -15,14 +16,14 @@ export const Badges: FunctionComponent = () => { return ( <> - + Badges - You currently have {badges.length} badge - {badges.length === 1 ? '' : 's'}. You can click on the badges to toggle - visibility. + You currently have{' '} + {`${badges.length} badge${badges.length === 1 ? '' : 's'}`}. You can + click on the badges to toggle visibility. diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/CodeFormatting/Prettier/index.tsx b/packages/app/src/app/pages/common/Modals/PreferencesModal/CodeFormatting/Prettier.tsx similarity index 90% rename from packages/app/src/app/pages/common/Modals/PreferencesModal/CodeFormatting/Prettier/index.tsx rename to packages/app/src/app/pages/common/Modals/PreferencesModal/CodeFormatting/Prettier.tsx index d23ba3e95f0..d1aa9773d4f 100644 --- a/packages/app/src/app/pages/common/Modals/PreferencesModal/CodeFormatting/Prettier/index.tsx +++ b/packages/app/src/app/pages/common/Modals/PreferencesModal/CodeFormatting/Prettier.tsx @@ -8,7 +8,7 @@ import { PreferenceContainer, PaddedPreference, Rule, -} from '../../elements'; +} from '../elements'; export const Prettier: FunctionComponent = () => { const { @@ -17,7 +17,10 @@ export const Prettier: FunctionComponent = () => { }, state: { preferences: { - settings: { prettierConfig }, + settings: { + prettierConfig, + prettierConfig: { fluid }, + }, }, }, } = useOvermind(); @@ -56,23 +59,16 @@ export const Prettier: FunctionComponent = () => { - + + - + Specify the line length that the printer will wrap on. diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/CodeFormatting/index.tsx b/packages/app/src/app/pages/common/Modals/PreferencesModal/CodeFormatting/index.tsx index 43cc35f2724..a3dcb5672bc 100644 --- a/packages/app/src/app/pages/common/Modals/PreferencesModal/CodeFormatting/index.tsx +++ b/packages/app/src/app/pages/common/Modals/PreferencesModal/CodeFormatting/index.tsx @@ -1,22 +1,22 @@ -import React, { FunctionComponent } from 'react'; - import { Text } from '@codesandbox/components'; +import React, { FunctionComponent } from 'react'; import { Question } from './elements'; import { Prettier } from './Prettier'; export const CodeFormatting: FunctionComponent = () => ( <> - + Prettier Settings{' '} + ); diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/EditorPageSettings/EditorSettings/index.tsx b/packages/app/src/app/pages/common/Modals/PreferencesModal/EditorPageSettings/EditorSettings.tsx similarity index 73% rename from packages/app/src/app/pages/common/Modals/PreferencesModal/EditorPageSettings/EditorSettings/index.tsx rename to packages/app/src/app/pages/common/Modals/PreferencesModal/EditorPageSettings/EditorSettings.tsx index 12c14111efc..d7db2b40246 100644 --- a/packages/app/src/app/pages/common/Modals/PreferencesModal/EditorPageSettings/EditorSettings/index.tsx +++ b/packages/app/src/app/pages/common/Modals/PreferencesModal/EditorPageSettings/EditorSettings.tsx @@ -1,40 +1,42 @@ -import React from 'react'; +import { Preference } from '@codesandbox/common/lib/components/Preference'; +import { Text, Element } from '@codesandbox/components'; +import React, { FunctionComponent, useState } from 'react'; + import Modal from 'app/components/Modal'; import { useOvermind } from 'app/overmind'; -import { Text, Element } from '@codesandbox/components'; -import { Preference } from '@codesandbox/common/lib/components/Preference'; -import { Alert } from '../../../Common/Alert'; -import { PreferenceContainer } from '../../elements'; -import { VSCodePlaceholder } from '../../VSCodePlaceholder'; +import { Alert } from '../../Common/Alert'; + +import { VSCodePlaceholder } from '../VSCodePlaceholder'; + +import { PreferenceContainer } from '../elements'; -const isSafari: boolean = /^((?!chrome|android).)*safari/i.test( - navigator.userAgent -); -const isFF: boolean = navigator.userAgent.toLowerCase().includes('firefox'); +const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); +const isFF = navigator.userAgent.toLowerCase().includes('firefox'); -export const EditorSettings: React.FC = () => { - const [showModal, setShowModal] = React.useState(false); +export const EditorSettings: FunctionComponent = () => { const { - state: { - preferences: { settings }, - }, actions: { preferences: { settingChanged }, }, + state: { + preferences: { settings }, + }, } = useOvermind(); + const [showModal, setShowModal] = useState(false); const bindValue = (name: string) => ({ - value: settings[name], setValue: (value: any) => { settingChanged({ name, value }); + setShowModal(true); }, + value: settings[name], }); return ( <> - + Appearance @@ -49,35 +51,36 @@ export const EditorSettings: React.FC = () => { type="boolean" {...bindValue('vimMode')} /> + Toggling the VIM extension will require a refresh. When enabled, use the command palette to control VIM + {isSafari || isFF ? ( - + The VIM extension currently only works on Chrome and Microsoft Edge. ) : null} + setShowModal(false)} width={400} > setShowModal(false)} - onPrimaryAction={() => { - location.reload(true); - }} + onPrimaryAction={() => location.reload(true)} + title="Toggle VIM extension" /> diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/EditorPageSettings/PreviewSettings/index.tsx b/packages/app/src/app/pages/common/Modals/PreferencesModal/EditorPageSettings/PreviewSettings.tsx similarity index 73% rename from packages/app/src/app/pages/common/Modals/PreferencesModal/EditorPageSettings/PreviewSettings/index.tsx rename to packages/app/src/app/pages/common/Modals/PreferencesModal/EditorPageSettings/PreviewSettings.tsx index 42d99ab696c..580d5263917 100644 --- a/packages/app/src/app/pages/common/Modals/PreferencesModal/EditorPageSettings/PreviewSettings/index.tsx +++ b/packages/app/src/app/pages/common/Modals/PreferencesModal/EditorPageSettings/PreviewSettings.tsx @@ -1,27 +1,33 @@ -import React from 'react'; -import { useOvermind } from 'app/overmind'; import { Text } from '@codesandbox/components'; +import React, { FunctionComponent } from 'react'; + +import { useOvermind } from 'app/overmind'; + import { - SubContainer, - PreferenceContainer, PaddedPreference, + PreferenceContainer, + SubContainer, Rule, -} from '../../elements'; - -export const PreviewSettings: React.FC = () => { - const { state, actions } = useOvermind(); - const bindValue = name => ({ - value: state.preferences.settings[name], - setValue: value => - actions.preferences.settingChanged({ - name, - value, - }), +} from '../elements'; + +export const PreviewSettings: FunctionComponent = () => { + const { + actions: { + preferences: { settingChanged }, + }, + state: { + preferences: { settings }, + }, + } = useOvermind(); + + const bindValue = (name: string) => ({ + setValue: value => settingChanged({ name, value }), + value: settings[name], }); return (
- + Preview @@ -29,29 +35,36 @@ export const PreviewSettings: React.FC = () => { + Preview the latest code without saving. + + + Clear your developer console between every execution. + + + Show preview on every keypress. diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/Experiments/ContainerLSP.tsx b/packages/app/src/app/pages/common/Modals/PreferencesModal/Experiments/ContainerLSP.tsx index 3f84a260998..9500c53a2fe 100644 --- a/packages/app/src/app/pages/common/Modals/PreferencesModal/Experiments/ContainerLSP.tsx +++ b/packages/app/src/app/pages/common/Modals/PreferencesModal/Experiments/ContainerLSP.tsx @@ -1,6 +1,8 @@ +import { Text } from '@codesandbox/components'; import React, { FunctionComponent } from 'react'; + import { useOvermind } from 'app/overmind'; -import { Text } from '@codesandbox/components'; + import { PaddedPreference } from '../elements'; export const ContainerLSP: FunctionComponent = () => { @@ -14,18 +16,19 @@ export const ContainerLSP: FunctionComponent = () => { return user ? ( <> toggleContainerLspExperiment()} + setValue={toggleContainerLspExperiment} title="Use container language server" tooltip="Language server" type="boolean" value={user.experiments.containerLsp} /> + As part of making containers more powerful we now allow the language server to run there. Please help us test it :-) diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/Experiments/index.tsx b/packages/app/src/app/pages/common/Modals/PreferencesModal/Experiments/index.tsx index 2e8300b9f0a..acc0f32d0a4 100644 --- a/packages/app/src/app/pages/common/Modals/PreferencesModal/Experiments/index.tsx +++ b/packages/app/src/app/pages/common/Modals/PreferencesModal/Experiments/index.tsx @@ -1,13 +1,16 @@ -import React from 'react'; import { Text, Element } from '@codesandbox/components'; +import React, { FunctionComponent } from 'react'; + import { SubContainer } from '../elements'; + import { ContainerLSP } from './ContainerLSP'; -export const Experiments: React.FunctionComponent = () => ( +export const Experiments: FunctionComponent = () => ( <> - + Experiments + diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/Integrations/elements.js b/packages/app/src/app/pages/common/Modals/PreferencesModal/Integrations/elements.ts similarity index 100% rename from packages/app/src/app/pages/common/Modals/PreferencesModal/Integrations/elements.js rename to packages/app/src/app/pages/common/Modals/PreferencesModal/Integrations/elements.ts diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/Integrations/index.js b/packages/app/src/app/pages/common/Modals/PreferencesModal/Integrations/index.js deleted file mode 100644 index b16f4e5adfd..00000000000 --- a/packages/app/src/app/pages/common/Modals/PreferencesModal/Integrations/index.js +++ /dev/null @@ -1,22 +0,0 @@ -import React from 'react'; - -import { VercelIntegration } from 'app/pages/common/VercelIntegration'; -import { GithubIntegration } from 'app/pages/common/GithubIntegration'; -import { Text } from '@codesandbox/components'; - -import { Container } from './elements'; - -export function Integrations() { - return ( -
- - Integrations - - - - - - -
- ); -} diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/Integrations/index.tsx b/packages/app/src/app/pages/common/Modals/PreferencesModal/Integrations/index.tsx new file mode 100644 index 00000000000..82031929e15 --- /dev/null +++ b/packages/app/src/app/pages/common/Modals/PreferencesModal/Integrations/index.tsx @@ -0,0 +1,21 @@ +import { Text } from '@codesandbox/components'; +import React, { FunctionComponent } from 'react'; + +import { GithubIntegration } from 'app/pages/common/GithubIntegration'; +import { VercelIntegration } from 'app/pages/common/VercelIntegration'; + +import { Container } from './elements'; + +export const Integrations: FunctionComponent = () => ( +
+ + Integrations + + + + + + + +
+); diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/KeyMapping/index.tsx b/packages/app/src/app/pages/common/Modals/PreferencesModal/KeyMapping.tsx similarity index 65% rename from packages/app/src/app/pages/common/Modals/PreferencesModal/KeyMapping/index.tsx rename to packages/app/src/app/pages/common/Modals/PreferencesModal/KeyMapping.tsx index 987b6268c88..5cb23464d99 100644 --- a/packages/app/src/app/pages/common/Modals/PreferencesModal/KeyMapping/index.tsx +++ b/packages/app/src/app/pages/common/Modals/PreferencesModal/KeyMapping.tsx @@ -1,13 +1,14 @@ import React, { FunctionComponent } from 'react'; import { Text } from '@codesandbox/components'; -import { VSCodePlaceholder } from '../VSCodePlaceholder'; +import { VSCodePlaceholder } from './VSCodePlaceholder'; export const KeyMapping: FunctionComponent = () => ( <> - + Key Bindings + ); diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/PaymentInfo/Icons.tsx b/packages/app/src/app/pages/common/Modals/PreferencesModal/PaymentInfo/Card/Icons.tsx similarity index 94% rename from packages/app/src/app/pages/common/Modals/PreferencesModal/PaymentInfo/Icons.tsx rename to packages/app/src/app/pages/common/Modals/PreferencesModal/PaymentInfo/Card/Icons.tsx index befaaf07a00..db2e58a79da 100644 --- a/packages/app/src/app/pages/common/Modals/PreferencesModal/PaymentInfo/Icons.tsx +++ b/packages/app/src/app/pages/common/Modals/PreferencesModal/PaymentInfo/Card/Icons.tsx @@ -1,6 +1,8 @@ -import React from 'react'; +import React, { FunctionComponent, SVGProps } from 'react'; -export const AmexIcon = props => ( +type IconProps = SVGProps; + +export const AmexIcon: FunctionComponent = props => ( ( ); -export const MasterCardIcon = props => ( +export const MasterCardIcon: FunctionComponent = props => ( ( ); -export const VisaIcon = props => ( +export const VisaIcon: FunctionComponent = props => ( ( ); -export const BlankIcon = props => ( +export const BlankIcon: FunctionComponent = props => ( ( ); -export const DiscoverIcon = props => ( +export const DiscoverIcon: FunctionComponent = props => ( = ({ brand }) => { + const iconsByBrand = { + 'American Express': AmexIcon, + Discover: DiscoverIcon, + MasterCard: MasterCardIcon, + Visa: VisaIcon, + }; + const IconByBrand = iconsByBrand[brand] || BlankIcon; + + return ; +}; + +export const Card: FunctionComponent = () => { + const { + state: { + preferences: { paymentDetails }, + }, + } = useOvermind(); + const { brand, last4, name } = paymentDetails || {}; + + return ( + + + + + + + + + {brand} + + + ending in + + + {last4} + + + + + + {name} + + + + + ); +}; diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/PaymentInfo/index.tsx b/packages/app/src/app/pages/common/Modals/PreferencesModal/PaymentInfo/index.tsx index 30d6b779cc6..9e9db32e547 100644 --- a/packages/app/src/app/pages/common/Modals/PreferencesModal/PaymentInfo/index.tsx +++ b/packages/app/src/app/pages/common/Modals/PreferencesModal/PaymentInfo/index.tsx @@ -1,45 +1,15 @@ -import React, { ComponentProps, FunctionComponent, useEffect } from 'react'; +import { Element, Stack, Text } from '@codesandbox/components'; +import React, { FunctionComponent, useEffect } from 'react'; import { SubscribeForm } from 'app/components/SubscribeForm'; import { useOvermind } from 'app/overmind'; -import css from '@styled-system/css'; -import { Text, Element, Stack } from '@codesandbox/components'; -import { - AmexIcon, - MasterCardIcon, - VisaIcon, - BlankIcon, - DiscoverIcon, -} from './Icons'; +import { Card } from './Card'; -const Icon = (name: string) => { - let icon; - switch (name) { - case 'MasterCard': - icon = MasterCardIcon; - break; - case 'American Express': - icon = AmexIcon; - break; - case 'Discover': - icon = DiscoverIcon; - break; - case 'Visa': - icon = VisaIcon; - break; - - default: - icon = BlankIcon; - } - - return icon; -}; - -export const PaymentInfo: FunctionComponent = () => { +const Body: FunctionComponent = () => { const { actions: { - preferences: { paymentDetailsRequested, paymentDetailsUpdated }, + preferences: { paymentDetailsUpdated }, }, state: { preferences: { @@ -49,92 +19,67 @@ export const PaymentInfo: FunctionComponent = () => { }, }, } = useOvermind(); + const { name } = paymentDetails || {}; - useEffect(() => { - paymentDetailsRequested(); - }, [paymentDetailsRequested]); + if (isLoadingPaymentDetails) { + return ( + + Loading payment details... + + ); + } - const updatePaymentDetails: ComponentProps< - typeof SubscribeForm - >['subscribe'] = ({ token }) => paymentDetailsUpdated(token); + if (paymentDetailError) { + return ( + + {`An error occurred: ${paymentDetailError}`} + + ); + } - const Body = () => { - const { brand, last4, name } = paymentDetails || {}; - if (isLoadingPaymentDetails) { - return ( - - Loading payment details... + return ( + + + + Update card info - ); - } - if (paymentDetailError) { - return ( - - An error occurred: {paymentDetailError} + paymentDetailsUpdated(token)} + /> + + + + + Current card - ); - } - return ( - <> - - - - Update card info - - - - - - Current card - - - - {Icon(brand)()} - - - - - {brand} - {' '} - ending in - - {last4} - - - - - {name} - - - - - - - - ); - }; + + + + ); +}; + +export const PaymentInfo: FunctionComponent = () => { + const { + actions: { + preferences: { paymentDetailsRequested }, + }, + } = useOvermind(); + + useEffect(() => { + paymentDetailsRequested(); + }, [paymentDetailsRequested]); return ( - + Payment Info +
); diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/SideNavigation.tsx b/packages/app/src/app/pages/common/Modals/PreferencesModal/SideNavigation.tsx new file mode 100644 index 00000000000..4ede41321cb --- /dev/null +++ b/packages/app/src/app/pages/common/Modals/PreferencesModal/SideNavigation.tsx @@ -0,0 +1,77 @@ +import { Element, Stack, Text } from '@codesandbox/components'; +import css from '@styled-system/css'; +import React, { ComponentType, FunctionComponent } from 'react'; + +import { useOvermind } from 'app/overmind'; + +type MenuItem = { + Icon: ComponentType; + id: string; + title: string; +}; +type Props = { + menuItems: MenuItem[]; +}; +export const SideNavigation: FunctionComponent = ({ menuItems }) => { + const { + actions: { + preferences: { itemIdChanged }, + }, + state: { + preferences: { itemId = 'appearance' }, + }, + } = useOvermind(); + + return ( + + + Preferences + + + + {menuItems.map(({ Icon, id, title }) => ( + itemIdChanged(id)} + > + + + + + {title} + + ))} + + + ); +}; diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/SideNavigation/index.js b/packages/app/src/app/pages/common/Modals/PreferencesModal/SideNavigation/index.js deleted file mode 100644 index 0b06fc3e102..00000000000 --- a/packages/app/src/app/pages/common/Modals/PreferencesModal/SideNavigation/index.js +++ /dev/null @@ -1,54 +0,0 @@ -import React from 'react'; -import { Element, Text, Stack } from '@codesandbox/components'; -import css from '@styled-system/css'; - -export const SideNavigation = ({ menuItems, itemId, setItem }) => ( - - - Preferences - - - {menuItems.map(item => ( - setItem({ itemId: item.id })} - key={item.title} - selected={itemId === item.id} - > - {item.icon} - {item.title} - - ))} - - -); diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/VSCodePlaceholder/OpenVSCodeSettingsButton/index.tsx b/packages/app/src/app/pages/common/Modals/PreferencesModal/VSCodePlaceholder/OpenVSCodeSettingsButton.tsx similarity index 100% rename from packages/app/src/app/pages/common/Modals/PreferencesModal/VSCodePlaceholder/OpenVSCodeSettingsButton/index.tsx rename to packages/app/src/app/pages/common/Modals/PreferencesModal/VSCodePlaceholder/OpenVSCodeSettingsButton.tsx diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/VSCodePlaceholder/index.tsx b/packages/app/src/app/pages/common/Modals/PreferencesModal/VSCodePlaceholder/index.tsx index 7093a42db9c..666f37a8fdc 100644 --- a/packages/app/src/app/pages/common/Modals/PreferencesModal/VSCodePlaceholder/index.tsx +++ b/packages/app/src/app/pages/common/Modals/PreferencesModal/VSCodePlaceholder/index.tsx @@ -1,26 +1,20 @@ import { editorUrl } from '@codesandbox/common/lib/utils/url-generator'; +import { Text } from '@codesandbox/components'; import React, { FunctionComponent } from 'react'; import { Route } from 'react-router-dom'; -import { Text } from '@codesandbox/components'; import { OpenVSCodeSettingsButton } from './OpenVSCodeSettingsButton'; -type Props = { - hideTitle?: boolean; -}; -export const VSCodePlaceholder: FunctionComponent = ({ - hideTitle = false, -}) => - hideTitle ? null : ( - <> - - Some options are disabled because they are handled by VSCode. You can - open the settings of VSCode by pressing {"'"} - CTRL/CMD + ,{"'"}. - - match && } - /> - - ); +export const VSCodePlaceholder: FunctionComponent = () => ( + <> + + Some options are disabled because they are handled by VSCode. You can open + the settings of VSCode by pressing CTRL/CMD + ,. + + + (match ? : null)} + /> + +); diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/elements.ts b/packages/app/src/app/pages/common/Modals/PreferencesModal/elements.ts index 25cb1f28e09..c70d3037617 100644 --- a/packages/app/src/app/pages/common/Modals/PreferencesModal/elements.ts +++ b/packages/app/src/app/pages/common/Modals/PreferencesModal/elements.ts @@ -12,15 +12,16 @@ export const SubContainer = styled.div` `; export const PreferenceContainer = styled.div<{ disabled?: boolean }>` - padding-top: 0.5rem; + ${({ disabled }) => css` + padding-top: 0.5rem; - ${props => - props.disabled && - css` - opacity: 0.5; - pointer-events: none; - cursor: disabled; - `} + ${disabled && + css` + opacity: 0.5; + pointer-events: none; + cursor: disabled; + `} + `}; `; // Preference is typed in a bad way, not possible to infer diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/index.tsx b/packages/app/src/app/pages/common/Modals/PreferencesModal/index.tsx index 8b0b60be622..2c27764d57e 100644 --- a/packages/app/src/app/pages/common/Modals/PreferencesModal/index.tsx +++ b/packages/app/src/app/pages/common/Modals/PreferencesModal/index.tsx @@ -1,131 +1,118 @@ -import React, { useMemo } from 'react'; -import { useOvermind } from 'app/overmind'; -import css from '@styled-system/css'; import { Stack } from '@codesandbox/components'; +import css from '@styled-system/css'; +import React, { ComponentProps, ComponentType, FunctionComponent } from 'react'; -import AppearanceIcon from 'react-icons/lib/md/color-lens'; import CodeIcon from 'react-icons/lib/fa/code'; -import CreditCardIcon from 'react-icons/lib/md/credit-card'; +import CodeFormatIcon from 'react-icons/lib/fa/dedent'; +import FlaskIcon from 'react-icons/lib/fa/flask'; import BrowserIcon from 'react-icons/lib/go/browser'; +import KeyboardIcon from 'react-icons/lib/go/keyboard'; import StarIcon from 'react-icons/lib/go/star'; -import FlaskIcon from 'react-icons/lib/fa/flask'; -import CodeFormatIcon from 'react-icons/lib/fa/dedent'; +import AppearanceIcon from 'react-icons/lib/md/color-lens'; +import CreditCardIcon from 'react-icons/lib/md/credit-card'; import IntegrationIcon from 'react-icons/lib/md/device-hub'; -import KeyboardIcon from 'react-icons/lib/go/keyboard'; -import { SideNavigation } from './SideNavigation'; +import { useOvermind } from 'app/overmind'; + +import { Alert } from '../Common/Alert'; import { Appearance } from './Appearance'; +import { Badges } from './Badges'; +import { CodeFormatting } from './CodeFormatting'; import { EditorSettings } from './EditorPageSettings/EditorSettings'; import { PreviewSettings } from './EditorPageSettings/PreviewSettings'; -import { CodeFormatting } from './CodeFormatting'; -import { PaymentInfo } from './PaymentInfo'; -import { Integrations } from './Integrations'; -import { Badges } from './Badges'; import { Experiments } from './Experiments'; +import { Integrations } from './Integrations'; import { KeyMapping } from './KeyMapping'; -import { Alert } from '../Common/Alert'; +import { PaymentInfo } from './PaymentInfo'; +import { SideNavigation } from './SideNavigation'; -const PreferencesModal: React.FC = () => { +type MenuItem = ComponentProps['menuItems'][0] & { + Content: ComponentType; +}; +const getItems = (isLoggedIn: boolean, isPatron: boolean): MenuItem[] => + [ + { + Content: Appearance, + Icon: AppearanceIcon, + id: 'appearance', + title: 'Appearance', + }, + { + Content: EditorSettings, + Icon: CodeIcon, + id: 'editor', + title: 'Editor', + }, + { + Content: CodeFormatting, + Icon: CodeFormatIcon, + id: 'prettierSettings', + title: 'Prettier Settings', + }, + { + Content: PreviewSettings, + Icon: BrowserIcon, + id: 'preview', + title: 'Preview', + }, + { + Content: KeyMapping, + Icon: KeyboardIcon, + id: 'keybindings', + title: 'Key Bindings', + }, + isLoggedIn && { + Content: Integrations, + Icon: IntegrationIcon, + id: 'integrations', + title: 'Integrations', + }, + isPatron && { + Content: PaymentInfo, + Icon: CreditCardIcon, + id: 'paymentInfo', + title: 'Payment Info', + }, + isPatron && { + Content: Badges, + Icon: StarIcon, + id: 'badges', + title: 'Badges', + }, + { + Content: Experiments, + Icon: FlaskIcon, + id: 'experiments', + title: 'Experiments', + }, + ].filter(Boolean); + +export const PreferencesModal: FunctionComponent = () => { const { state: { - isPatron, isLoggedIn, + isPatron, preferences: { itemId = 'appearance' }, }, - actions: { - preferences: { itemIdChanged }, - }, } = useOvermind(); - - const items = useMemo( - () => - [ - { - id: 'appearance', - title: 'Appearance', - icon: , - content: , - }, - { - id: 'editor', - title: 'Editor', - icon: , - content: , - }, - { - id: 'prettierSettings', - title: 'Prettier Settings', - icon: , - content: , - }, - { - id: 'preview', - title: 'Preview', - icon: , - content: , - }, - { - id: 'keybindings', - title: 'Key Bindings', - icon: , - content: , - }, - isLoggedIn && { - id: 'integrations', - title: 'Integrations', - icon: , - content: , - }, - isPatron && { - id: 'paymentInfo', - title: 'Payment Info', - icon: , - content: , - }, - isPatron && { - id: 'badges', - title: 'Badges', - icon: , - content: , - }, - { - id: 'experiments', - title: 'Experiments', - icon: , - content: , - }, - ].filter(Boolean), - [isLoggedIn, isPatron] - ); - - const item = items.find(currentItem => currentItem.id === itemId); + const items = getItems(isLoggedIn, isPatron); + const { Content } = items.find(({ id }) => id === itemId); return ( - - + + + - {item.content} + ); }; - -export default PreferencesModal; diff --git a/packages/app/src/app/pages/common/Modals/index.tsx b/packages/app/src/app/pages/common/Modals/index.tsx index 356c0498f5c..5c527ad0d15 100644 --- a/packages/app/src/app/pages/common/Modals/index.tsx +++ b/packages/app/src/app/pages/common/Modals/index.tsx @@ -22,7 +22,7 @@ import { LiveSessionEnded } from './LiveSessionEnded'; import LiveSessionVersionMismatch from './LiveSessionVersionMismatch'; import { NetlifyLogs } from './NetlifyLogs'; import { PickSandboxModal } from './PickSandboxModal'; -import PreferencesModal from './PreferencesModal'; +import { PreferencesModal } from './PreferencesModal'; import { SearchDependenciesModal } from './SearchDependenciesModal'; import { SelectSandboxModal } from './SelectSandboxModal'; import { ShareModal } from './ShareModal'; diff --git a/packages/app/src/app/pages/common/VercelIntegration/index.tsx b/packages/app/src/app/pages/common/VercelIntegration.tsx similarity index 88% rename from packages/app/src/app/pages/common/VercelIntegration/index.tsx rename to packages/app/src/app/pages/common/VercelIntegration.tsx index 347e0870bf6..2ffed87925e 100644 --- a/packages/app/src/app/pages/common/VercelIntegration/index.tsx +++ b/packages/app/src/app/pages/common/VercelIntegration.tsx @@ -7,7 +7,9 @@ import { useOvermind } from 'app/overmind'; type Props = { small?: boolean; }; -export const VercelIntegration: FunctionComponent = ({ small }) => { +export const VercelIntegration: FunctionComponent = ({ + small = false, +}) => { const { actions: { signInVercelClicked, signOutVercelClicked }, state: { user, isLoadingVercel },