diff --git a/packages/app/src/app/overmind/namespaces/profile/actions.ts b/packages/app/src/app/overmind/namespaces/profile/actions.ts index 1b67986fe72..65eaac6ef79 100755 --- a/packages/app/src/app/overmind/namespaces/profile/actions.ts +++ b/packages/app/src/app/overmind/namespaces/profile/actions.ts @@ -2,28 +2,28 @@ import { Sandbox } from '@codesandbox/common/lib/types'; import { Action, AsyncAction } from 'app/overmind'; import { withLoadApp } from 'app/overmind/factories'; -export const profileMounted: AsyncAction<{ - username: string; -}> = withLoadApp(async ({ state, effects }, { username }) => { - state.profile.isLoadingProfile = true; - state.profile.notFound = false; - - const profile = await effects.api.getProfile(username); - - state.profile.profiles[profile.id] = profile; - state.profile.currentProfileId = profile.id; +export const profileMounted: AsyncAction = withLoadApp( + async ({ effects, state }, username) => { + state.profile.isLoadingProfile = true; + state.profile.notFound = false; + + const profile = await effects.api.getProfile(username); + + state.profile.profiles[profile.id] = profile; + state.profile.currentProfileId = profile.id; + + if ( + profile.showcasedSandboxShortid && + !state.editor.sandboxes[profile.showcasedSandboxShortid] + ) { + state.editor.sandboxes[ + profile.showcasedSandboxShortid + ] = await effects.api.getSandbox(profile.showcasedSandboxShortid); + } - if ( - profile.showcasedSandboxShortid && - !state.editor.sandboxes[profile.showcasedSandboxShortid] - ) { - state.editor.sandboxes[ - profile.showcasedSandboxShortid - ] = await effects.api.getSandbox(profile.showcasedSandboxShortid); + state.profile.isLoadingProfile = false; } - - state.profile.isLoadingProfile = false; -}); +); export const sandboxesPageChanged: AsyncAction<{ page: number; diff --git a/packages/app/src/app/pages/Profile/elements.js b/packages/app/src/app/pages/Profile/elements.ts similarity index 52% rename from packages/app/src/app/pages/Profile/elements.js rename to packages/app/src/app/pages/Profile/elements.ts index c8ee2ca2de1..7cce9427755 100644 --- a/packages/app/src/app/pages/Profile/elements.js +++ b/packages/app/src/app/pages/Profile/elements.ts @@ -1,5 +1,6 @@ -import styled from 'styled-components'; import Fullscreen from '@codesandbox/common/lib/components/flex/Fullscreen'; +import MarginBase from '@codesandbox/common/lib/components/spacing/Margin'; +import styled, { css } from 'styled-components'; export const Container = styled(Fullscreen)` color: white; @@ -11,6 +12,12 @@ export const Container = styled(Fullscreen)` `; export const Content = styled(Fullscreen)` - border-top: 1px solid ${props => props.theme.background3}; - flex: 0 0 70px; + ${({ theme }) => css` + border-top: 1px solid ${theme.background3}; + flex: 0 0 70px; + `}; +`; + +export const Margin = styled(MarginBase)` + min-height: 60vh; `; diff --git a/packages/app/src/app/pages/Profile/index.tsx b/packages/app/src/app/pages/Profile/index.tsx index 0906c2e3056..4b62a3be427 100644 --- a/packages/app/src/app/pages/Profile/index.tsx +++ b/packages/app/src/app/pages/Profile/index.tsx @@ -1,45 +1,39 @@ import MaxWidth from '@codesandbox/common/lib/components/flex/MaxWidth'; -import Margin from '@codesandbox/common/lib/components/spacing/Margin'; import { profileLikesUrl, profileSandboxesUrl, } from '@codesandbox/common/lib/utils/url-generator'; +import React, { FunctionComponent, useEffect } from 'react'; +import { Helmet } from 'react-helmet'; +import { Route, RouteComponentProps, Switch } from 'react-router-dom'; + import { useOvermind } from 'app/overmind'; import { NotFound } from 'app/pages/common/NotFound'; -import React, { useEffect } from 'react'; -import { Helmet } from 'react-helmet'; -import { Route, Switch } from 'react-router-dom'; -import { Container, Content } from './elements'; +import { Container, Content, Margin } from './elements'; import Header from './Header'; import Navigation from './Navigation'; import { Sandboxes } from './Sandboxes'; import { Showcase } from './Showcase'; -interface IProfileProps { - match: { - params: { username: string }; - url: string; - }; -} - -const Profile: React.FC = ({ +type Props = RouteComponentProps<{ username: string }>; +export const Profile: FunctionComponent = ({ match: { params: { username }, url, }, }) => { const { - state: { - profile: { current: user, notFound }, - }, actions: { profile: { profileMounted }, }, + state: { + profile: { current: user, notFound }, + }, } = useOvermind(); useEffect(() => { - profileMounted({ username }); + profileMounted(username); }, [profileMounted, username]); if (notFound) { @@ -47,7 +41,7 @@ const Profile: React.FC = ({ } if (!user) { - return
; + return null; } return ( @@ -55,37 +49,42 @@ const Profile: React.FC = ({ {user.name || user.username} - CodeSandbox +
+ + - + - } /> + + ( + render={({ match }: RouteComponentProps<{ page?: string }>) => ( )} /> + ( + render={({ match }: RouteComponentProps<{ page?: string }>) => ( )} /> @@ -95,5 +94,3 @@ const Profile: React.FC = ({ ); }; - -export default Profile; diff --git a/packages/app/src/app/pages/index.tsx b/packages/app/src/app/pages/index.tsx index d3994c80558..faee4f0d2fa 100644 --- a/packages/app/src/app/pages/index.tsx +++ b/packages/app/src/app/pages/index.tsx @@ -40,7 +40,9 @@ const NotFound = Loadable(() => import(/* webpackChunkName: 'page-not-found' */ './common/NotFound') ); const Profile = Loadable(() => - import(/* webpackChunkName: 'page-profile' */ './Profile') + import(/* webpackChunkName: 'page-profile' */ './Profile').then(module => ({ + default: module.Profile, + })) ); const Search = Loadable(() => import(/* webpackChunkName: 'page-search' */ './Search').then(module => ({