Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import { getSandboxName } from '@codesandbox/common/lib/utils/get-sandbox-name';
import { sandboxUrl } from '@codesandbox/common/lib/utils/url-generator';
import { Element, Link } from '@codesandbox/components';
import React from 'react';

export const SandboxCard = ({ sandbox }) => (
<Element>
<Link href={sandboxUrl({ id: sandbox.id, alias: sandbox.alias })}>
{sandbox.title || sandbox.alias || sandbox.id}
{getSandboxName(sandbox)}
</Link>
</Element>
);
8 changes: 3 additions & 5 deletions packages/app/src/app/pages/NewDashboard/Content/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Route, Switch, Redirect, withRouter } from 'react-router-dom';
import React, { FunctionComponent } from 'react';
import { Redirect, Route, Switch } from 'react-router-dom';

// import { RecentSandboxes } from './routes/RecentSandboxes';
// import PathedSandboxes from './routes/PathedSandboxes';
Expand All @@ -12,7 +12,7 @@ import { Element } from '@codesandbox/components';
import { StartSandboxes } from './routes/StartSandboxes';
import { Templates } from './routes/Templates';

const ContentComponent = () => (
export const Content: FunctionComponent = () => (
<Element style={{ width: 960, margin: '40px auto' }}>
<Switch>
<Route path="/new-dashboard/start" component={StartSandboxes} />
Expand All @@ -36,5 +36,3 @@ const ContentComponent = () => (
</Switch>
</Element>
);

export const Content = withRouter(ContentComponent);
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import React, { FunctionComponent } from 'react';
import css from '@styled-system/css';
import { Element, Text, Button } from '@codesandbox/components';
import { useQuery } from '@apollo/react-hooks';

import { useOvermind } from 'app/overmind';
import {
RecentSandboxesQuery,
Expand All @@ -13,7 +14,7 @@ import { LIST_PERSONAL_TEMPLATES } from 'app/components/CreateNewSandbox/queries
import { RECENT_SANDBOXES_CONTENT_QUERY } from '../../../queries';
import { SandboxCard } from '../../../Components/SandboxCard';

export const StartSandboxes = () => {
export const StartSandboxes: FunctionComponent = () => {
const {
state,
actions: { modalOpened },
Expand Down Expand Up @@ -49,11 +50,8 @@ export const StartSandboxes = () => {
return <Text>loading</Text>;
}

const sandboxes = data && data.me && data.me.sandboxes;
const templates =
templatesData &&
templatesData.me &&
templatesData.me.recentlyUsedTemplates.slice(0, 4);
const sandboxes = data.me.sandboxes;
const templates = templatesData.me.recentlyUsedTemplates.slice(0, 4);

return (
<Element>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { FunctionComponent } from 'react';
import css from '@styled-system/css';
import { Element, Text } from '@codesandbox/components';
import { useQuery } from '@apollo/react-hooks';
Expand All @@ -9,7 +9,7 @@ import {
import { LIST_OWNED_TEMPLATES } from 'app/components/CreateNewSandbox/queries';
import { SandboxCard } from '../../../Components/SandboxCard';

export const Templates = () => {
export const Templates: FunctionComponent = () => {
const { loading, error, data } = useQuery<
ListTemplatesQuery,
ListTemplatesQueryVariables
Expand All @@ -25,7 +25,7 @@ export const Templates = () => {
return <Text>loading</Text>;
}

const templates = data && data.me && data.me.templates;
const templates = data.me.templates;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this was an intentional check as we have seen crash reports. Also, in my opinion it will be good to have a defensive code so that it doesn't break in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like I said in my review (#3952 (comment)), we know we don't have an error or loading at this point.
This means data is present.
Since data is an object with a me object (which has a templates array), we can simplify the code to what I've done


return (
<Element>
Expand Down