Skip to content

Commit 2550785

Browse files
CompuIvesSaraVieira
authored andcommitted
Change dashboard templates to be 1 item (codesandbox#3195)
* Put templates under 1 item * Upgrade dependencies * Fix weird apollo caching bug * Fix type error * Remove need for teamId in unmakeTemplates * Fix cache update function
1 parent 4a8fc8d commit 2550785

File tree

20 files changed

+175
-227
lines changed

20 files changed

+175
-227
lines changed

packages/app/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
]
7171
},
7272
"dependencies": {
73-
"@apollo/react-hooks": "^3.0.1",
73+
"@apollo/react-hooks": "^3.1.3",
7474
"@babel/plugin-transform-destructuring": "^7.5.0",
7575
"@babel/preset-env": "^7.5.5",
7676
"@codesandbox/executors": "^0.1.0",
@@ -83,7 +83,7 @@
8383
"@types/rc-slider": "^8.6.5",
8484
"@vue/babel-preset-app": "^3.2.0",
8585
"airtable": "^0.5.8",
86-
"apollo-boost": "^0.4.3",
86+
"apollo-boost": "^0.4.4",
8787
"apollo-link-batch-http": "^1.2.12",
8888
"apollo-link-context": "^1.0.18",
8989
"axios": "^0.19.0",

packages/app/src/app/components/CreateNewSandbox/queries.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,14 @@ export const LIST_PERSONAL_TEMPLATES = gql`
8585
`;
8686

8787
export const LIST_OWNED_TEMPLATES = gql`
88-
query ListTemplates($teamId: ID, $showAll: Boolean) {
88+
query ListTemplates($showAll: Boolean) {
8989
me {
90-
templates(teamId: $teamId, showAll: $showAll) {
90+
templates(showAll: $showAll) {
9191
...Template
9292
}
9393
9494
teams {
95+
id
9596
name
9697
templates {
9798
...Template
@@ -138,7 +139,7 @@ export const UNMAKE_SANDBOXES_TEMPLATE_MUTATION = gql`
138139
}
139140
`;
140141

141-
export function unmakeTemplates(selectedSandboxes: string[], teamId?: string) {
142+
export function unmakeTemplates(selectedSandboxes: string[]) {
142143
return client.mutate<
143144
UnmakeSandboxesTemplateMutation,
144145
UnmakeSandboxesTemplateMutationVariables
@@ -157,7 +158,6 @@ export function unmakeTemplates(selectedSandboxes: string[], teamId?: string) {
157158
update: cache => {
158159
try {
159160
const variables: ListTemplatesQueryVariables = {
160-
teamId,
161161
showAll: false,
162162
};
163163

@@ -173,6 +173,13 @@ export function unmakeTemplates(selectedSandboxes: string[], teamId?: string) {
173173
draft.me.templates = draft.me.templates.filter(
174174
x => selectedSandboxes.indexOf(x.sandbox.id) === -1
175175
);
176+
177+
draft.me.teams = draft.me.teams.map(t => ({
178+
...t,
179+
templates: t.templates.filter(
180+
x => selectedSandboxes.indexOf(x.sandbox.id) === -1
181+
),
182+
}));
176183
});
177184

178185
cache.writeQuery<ListTemplatesQuery, ListTemplatesQueryVariables>({

packages/app/src/app/graphql/schema.graphql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# source: https://codesandbox.io/api/graphql
2-
# timestamp: Wed Dec 11 2019 16:37:29 GMT+0100 (Central European Standard Time)
1+
# source: https://codesandbox.stream/api/graphql
2+
# timestamp: Thu Dec 12 2019 17:24:06 GMT+0100 (Central European Standard Time)
33

44
schema {
55
query: RootQuery

packages/app/src/app/graphql/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,6 @@ export type ListPersonalTemplatesQuery = { __typename?: 'RootQueryType' } & {
388388
};
389389

390390
export type ListTemplatesQueryVariables = {
391-
teamId: Maybe<Scalars['ID']>;
392391
showAll: Maybe<Scalars['Boolean']>;
393392
};
394393

@@ -401,7 +400,7 @@ export type ListTemplatesQuery = { __typename?: 'RootQueryType' } & {
401400
teams: Maybe<
402401
Array<
403402
Maybe<
404-
{ __typename?: 'Team' } & Pick<Team, 'name'> & {
403+
{ __typename?: 'Team' } & Pick<Team, 'id' | 'name'> & {
405404
templates: Maybe<
406405
Array<Maybe<{ __typename?: 'Template' } & TemplateFragment>>
407406
>;

packages/app/src/app/pages/Dashboard/Content/index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Route, Switch, Redirect, withRouter } from 'react-router-dom';
33

44
import { RecentSandboxes } from './routes/RecentSandboxes';
55
import PathedSandboxes from './routes/PathedSandboxes';
6-
import { Templates, FollowedTemplates } from './routes/Templates';
6+
import { Templates } from './routes/Templates';
77
import DeletedSandboxes from './routes/DeletedSandboxes';
88
import SearchSandboxes from './routes/SearchSandboxes';
99
import CreateTeam from './routes/CreateTeam';
@@ -14,7 +14,6 @@ const Content = () => (
1414
<Route path="/dashboard/recent" component={RecentSandboxes} />
1515
<Route path="/dashboard/trash" component={DeletedSandboxes} />
1616
<Route path="/dashboard/templates" exact component={Templates} />
17-
<Route path="/dashboard/templates/followed" component={FollowedTemplates} />
1817
<Route path="/dashboard/sandboxes/:path*" component={PathedSandboxes} />
1918
<Route path="/dashboard/search" component={SearchSandboxes} />
2019
<Route path="/dashboard/teams/new" component={CreateTeam} />
@@ -28,10 +27,6 @@ const Content = () => (
2827
component={Templates}
2928
exact
3029
/>
31-
<Route
32-
path="/dashboard/teams/:teamId/templates/followed"
33-
component={FollowedTemplates}
34-
/>
3530
<Redirect to="/dashboard/recent" />
3631
</Switch>
3732
);

packages/app/src/app/pages/Dashboard/Content/routes/Templates/FollowedTemplates/elements.ts renamed to packages/app/src/app/pages/Dashboard/Content/routes/Templates/BookmarkedTemplates/elements.ts

File renamed without changes.

packages/app/src/app/pages/Dashboard/Content/routes/Templates/FollowedTemplates/index.tsx renamed to packages/app/src/app/pages/Dashboard/Content/routes/Templates/BookmarkedTemplates/index.tsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react';
1+
import React, { useEffect } from 'react';
22
import { sortBy } from 'lodash-es';
33
import { useQuery, useMutation, useApolloClient } from '@apollo/react-hooks';
44
import { DelayedAnimation } from 'app/components/DelayedAnimation';
@@ -18,15 +18,14 @@ import {
1818
import { useOvermind } from 'app/overmind';
1919
import { ButtonContainer } from './elements';
2020

21-
import { Container, Grid, EmptyTitle } from '../elements';
21+
import { Grid, EmptyTitle } from '../elements';
2222
import { Navigation } from '../Navigation';
2323
import { UNBOOKMARK_TEMPLATE_FROM_DASHBOARD } from './mutations';
2424

25-
export const FollowedTemplates = props => {
26-
const { teamId } = props.match.params;
27-
const [sortedTemplates, setSortedTemplates] = useState<
28-
ListPersonalBookmarkedTemplatesQuery['me']['bookmarkedTemplates']
29-
>();
25+
type BookmarkedTemplatesProps = { teamId?: string };
26+
27+
export const BookmarkedTemplates = (props: BookmarkedTemplatesProps) => {
28+
const { teamId } = props;
3029

3130
const { actions } = useOvermind();
3231

@@ -60,15 +59,17 @@ export const FollowedTemplates = props => {
6059
} Bookmarked Templates - CodeSandbox`;
6160
}, [teamId]);
6261

63-
useEffect(() => {
62+
const sortedTemplates = React.useMemo(() => {
6463
if (data && data.me) {
6564
if (teamId) {
6665
const team = data.me.teams.find(t => t.id === teamId);
67-
setSortedTemplates(team.bookmarkedTemplates);
68-
} else {
69-
setSortedTemplates(data.me.bookmarkedTemplates);
66+
return team.bookmarkedTemplates;
7067
}
68+
69+
return data.me.bookmarkedTemplates;
7170
}
71+
72+
return undefined;
7273
}, [teamId, data]);
7374

7475
if (error) {
@@ -87,7 +88,7 @@ export const FollowedTemplates = props => {
8788
color: 'rgba(255, 255, 255, 0.5)',
8889
}}
8990
>
90-
Fetching Sandboxes...
91+
Fetching Templates...
9192
</DelayedAnimation>
9293
);
9394
}
@@ -96,7 +97,7 @@ export const FollowedTemplates = props => {
9697
);
9798

9899
return (
99-
<Container>
100+
<>
100101
<Navigation bookmarked teamId={teamId} number={orderedTemplates.length} />
101102
{!orderedTemplates.length && (
102103
<div>
@@ -157,6 +158,6 @@ export const FollowedTemplates = props => {
157158
</ContextMenu>
158159
))}
159160
</Grid>
160-
</Container>
161+
</>
161162
);
162163
};

packages/app/src/app/pages/Dashboard/Content/routes/Templates/FollowedTemplates/mutations.ts renamed to packages/app/src/app/pages/Dashboard/Content/routes/Templates/BookmarkedTemplates/mutations.ts

File renamed without changes.
Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { Container, NavigationLink, Number } from './elements';
2+
import { Container, NavigationTitle, Number } from './elements';
33

44
interface INavigationProps {
55
teamId?: string;
@@ -14,27 +14,15 @@ export const Navigation = ({
1414
}: INavigationProps) => (
1515
<Container>
1616
{bookmarked ? (
17-
<NavigationLink
18-
to={
19-
teamId
20-
? `/dashboard/teams/${teamId}/templates/bookmarked`
21-
: `/dashboard/templates/bookmarked`
22-
}
23-
>
24-
{teamId ? 'Team Bookmarked Templates' : 'Bookmarked Templates'}
25-
</NavigationLink>
17+
<NavigationTitle>
18+
{teamId ? 'Bookmarked Templates' : 'Bookmarked Templates'}
19+
</NavigationTitle>
2620
) : (
27-
<NavigationLink
28-
to={
29-
teamId
30-
? `/dashboard/teams/${teamId}/templates`
31-
: `/dashboard/templates`
32-
}
33-
>
21+
<NavigationTitle>
3422
{teamId ? 'Team Templates' : 'My Templates'}
35-
</NavigationLink>
23+
</NavigationTitle>
3624
)}
3725

38-
{number == null && <Number>{number}</Number>}
26+
{number != null && <Number>{number}</Number>}
3927
</Container>
4028
);

packages/app/src/app/pages/Dashboard/Content/routes/Templates/Navigation/elements.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import styled from 'styled-components';
2-
import { Link } from 'react-router-dom';
32

43
export const Container = styled.div`
54
position: relative;
65
display: flex;
76
align-items: center;
87
`;
98

10-
export const NavigationLink = styled(Link)`
9+
export const NavigationTitle = styled.h2`
10+
display: inline-flex;
1111
margin-right: 0.5rem;
12-
color: rgba(255, 255, 255, 0.6);
1312
text-decoration: none;
1413
transition: 0.3s ease color;
1514
font-size: 1.25rem;
1615
margin-left: 0;
1716
color: white;
17+
margin-top: 0;
18+
margin-bottom: 0;
19+
font-weight: 400;
1820
1921
&:last-child {
2022
margin-right: 0;

0 commit comments

Comments
 (0)