Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates client starter code [Ready to merge] #296

Merged
merged 28 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bfb4ca1
updates client starter code
jpvajda Oct 4, 2022
77e29c5
cleans up index.js file
jpvajda Oct 4, 2022
8d0e0b2
more updates
jpvajda Oct 5, 2022
37c9185
a few more changes
jpvajda Oct 28, 2022
07c86ba
Update final to match starting code
rkoron007 Nov 7, 2022
6c6ec67
Update final code to match starter code
rkoron007 Nov 8, 2022
26d271d
Add comment for useParams
rkoron007 Nov 8, 2022
2668830
Update start/client/src/components/launch-tile.tsx
jpvajda Nov 8, 2022
009b876
Update start/client/src/components/loading.tsx
jpvajda Nov 8, 2022
5de78dd
Update start/client/src/components/login-form.tsx
jpvajda Nov 8, 2022
6a97b5c
Update start/client/src/pages/cart.tsx
jpvajda Nov 8, 2022
f3defe0
Update start/client/src/pages/launch.tsx
jpvajda Nov 8, 2022
b5f4e9c
Update start/client/src/pages/launches.tsx
jpvajda Nov 8, 2022
5e141a2
Update start/client/src/pages/launches.tsx
jpvajda Nov 8, 2022
aac2569
Update start/client/src/pages/profile.tsx
jpvajda Nov 8, 2022
2e5f880
resolves code review
jpvajda Nov 8, 2022
3cc1a1f
Fix tests for the final version
rkoron007 Nov 9, 2022
d967c5a
Update start folder tests to match final tests
rkoron007 Nov 9, 2022
25d150f
Remove changes to cart and launch
rkoron007 Nov 9, 2022
411ff4a
Update start/client/src/pages/launch.tsx
jpvajda Nov 9, 2022
1a80eb0
Update start/client/src/components/menu-item.tsx
jpvajda Nov 9, 2022
cfd9c2e
Update start/client/src/pages/profile.tsx
jpvajda Nov 9, 2022
e8c7e86
Update start/client/src/pages/cart.tsx
jpvajda Nov 9, 2022
f434c46
code review fixes
jpvajda Nov 9, 2022
6c77298
removed pack-lock file
jpvajda Nov 10, 2022
13a9e5c
Merge pull request #305 from apollographql/RK/working-through-client-…
rkoron007 Nov 12, 2022
f0f13a6
Fix small importing issues
rkoron007 Nov 14, 2022
5d786f0
Go through a pass
rkoron007 Nov 15, 2022
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Apollo tutorial

This is the fullstack app for the [Apollo tutorial](http://apollographql.com/docs/tutorial/introduction.html). 🚀
This is the fullstack app for the [Apollo tutorial](https://www.apollographql.com/tutorials/fullstack-quickstart/introduction). 🚀

## File structure

The app is split out into two folders:

- `start`: Starting point for the tutorial
- `final`: Final version

Expand Down
72,804 changes: 41,215 additions & 31,589 deletions final/client/package-lock.json

Large diffs are not rendered by default.

44 changes: 23 additions & 21 deletions final/client/package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
{
"name": "client",
"version": "0.1.0",
"version": "0.2.0",
"private": true,
"dependencies": {
"@apollo/client": "^3.4.6",
"@reach/router": "^1.2.1",
"@types/node": "^12.12.14",
"@types/reach__router": "^1.2.6",
"@types/react": "^16.9.15",
"@types/react-dom": "^16.9.4",
"emotion": "^9.2.12",
"graphql": "^14.7.0",
"polished": "^3.4.1",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-emotion": "^9.2.12",
"react-scripts": "^3.4.1",
"typescript": "^3.7.3"
"@apollo/client": "^3.7.0",
"@emotion/css": "^11.10.0",
"@emotion/react": "^11.10.4",
"@emotion/styled": "^11.10.4",
"graphql": "^16.5.0",
"history": "^5.3.0",
"polished": "^4.2.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router": "^6.4.1",
"react-router-dom": "^6.4.1",
"react-scripts": "^5.0.1",
"typescript": "^4.8.4"
},
"scripts": {
"start": "react-scripts start",
Expand All @@ -36,11 +35,14 @@
"not op_mini all"
],
"devDependencies": {
"@testing-library/jest-dom": "^4.0.0",
"@testing-library/react": "^8.0.7",
"@types/jest": "^24.0.23",
"apollo": "^2.32.5",
"artillery": "^1.6.0-26",
"npm-watch": "^0.6.0"
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@types/jest": "^29.1.1",
"@types/node": "^18.7.3",
"@types/react": "^18.0.21",
"@types/react-dom": "^18.0.6",
"@types/react-router": "^5.1.19",
"artillery": "^2.0.0-23",
"npm-watch": "^0.11.0"
}
}
3 changes: 2 additions & 1 deletion final/client/src/components/__tests__/launch-tile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import React from 'react';

import { render, cleanup } from '../../test-utils';
import LaunchTile from '../launch-tile';
import { renderApollo } from '../../test-utils';

describe('Launch Tile', () => {
// automatically unmount and cleanup DOM after the test is finished.
afterEach(cleanup);

it('renders without error', () => {
render(
renderApollo(
<LaunchTile
launch={{
__typename: 'Launch',
Expand Down
3 changes: 2 additions & 1 deletion final/client/src/components/__tests__/menu-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import React from 'react';

import { render, cleanup } from '../../test-utils';
import MenuItem from '../menu-item';
import { renderApollo } from '../../test-utils';

describe('Menu Item', () => {
// automatically unmount and cleanup DOM after the test is finished.
afterEach(cleanup);

it('renders without error', () => {
render(<MenuItem to="/wow" />);
renderApollo(<MenuItem to="/wow" />);
});
});
2 changes: 1 addition & 1 deletion final/client/src/components/button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import styled from 'react-emotion';
import styled from '@emotion/styled';
import { lighten } from 'polished';

import { unit, colors } from '../styles';
Expand Down
2 changes: 1 addition & 1 deletion final/client/src/components/footer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import styled from 'react-emotion';
import styled from '@emotion/styled';

import MenuItem from './menu-item';
import LogoutButton from '../containers/logout-button';
Expand Down
6 changes: 3 additions & 3 deletions final/client/src/components/header.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import styled from 'react-emotion';
import styled from '@emotion/styled';
import { size } from 'polished';

import { unit, colors } from '../styles';
Expand All @@ -24,7 +24,7 @@ interface HeaderProps {
}

const Header: React.FC<HeaderProps> = ({ image, children = 'Space Explorer' }) => {
const email = atob(localStorage.getItem('token') as string);
const email = window.atob(localStorage.getItem('token') as string);
const avatar = image || pickAvatarByEmail(email);

return (
Expand All @@ -36,7 +36,7 @@ const Header: React.FC<HeaderProps> = ({ image, children = 'Space Explorer' }) =
</div>
</Container>
);
}
};

export default Header;

Expand Down
4 changes: 2 additions & 2 deletions final/client/src/components/launch-detail.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';
import styled from 'react-emotion';
import styled from '@emotion/styled';

import { unit } from '../styles';
import { cardClassName, getBackgroundImage } from './launch-tile';
import { LaunchDetails_launch } from '../pages/__generated__/LaunchDetails';

type LaunchDetailProps = Partial<LaunchDetails_launch>
type LaunchDetailProps = Partial<LaunchDetails_launch>;

const LaunchDetail: React.FC<LaunchDetailProps> = ({ id, site, rocket }) => (
<Card
Expand Down
7 changes: 4 additions & 3 deletions final/client/src/components/launch-tile.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import styled, { css } from 'react-emotion';
import { Link } from '@reach/router';
import styled from '@emotion/styled';
import { css } from '@emotion/react';
import { Link } from 'react-router-dom';

import galaxy from '../assets/images/galaxy.jpg';
import iss from '../assets/images/iss.jpg';
Expand Down Expand Up @@ -30,7 +31,7 @@ const LaunchTile: React.FC<LaunchTileProps> = ({ launch }) => {
<h5>{rocket && rocket.name}</h5>
</StyledLink>
);
}
};

export default LaunchTile;

Expand Down
3 changes: 2 additions & 1 deletion final/client/src/components/loading.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled, { keyframes} from 'react-emotion';
import styled from '@emotion/styled';
import { keyframes } from '@emotion/react';
import { size } from 'polished';

import { ReactComponent as Logo } from '../assets/logo.svg';
Expand Down
70 changes: 38 additions & 32 deletions final/client/src/components/login-form.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Component } from 'react';
import styled, { css } from 'react-emotion';
import styled from '@emotion/styled';
import { css } from '@emotion/react';
import { size } from 'polished';

import Button from './button';
Expand All @@ -23,7 +24,7 @@ export default class LoginForm extends Component<LoginFormProps, LoginFormState>

onChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const email = (event.target as HTMLInputElement).value;
this.setState(s => ({ email }));
this.setState((s) => ({ email }));
};

onSubmit = (event: React.FormEvent<HTMLFormElement>) => {
Expand All @@ -41,14 +42,7 @@ export default class LoginForm extends Component<LoginFormProps, LoginFormState>
<StyledRocket />
<Heading>Space Explorer</Heading>
<StyledForm onSubmit={(e) => this.onSubmit(e)}>
<StyledInput
required
type="email"
name="email"
placeholder="Email"
data-testid="login-input"
onChange={(e) => this.onChange(e)}
/>
<StyledInput required type="email" name="email" placeholder="Email" data-testid="login-input" onChange={(e) => this.onChange(e)} />
<Button type="submit">Log in</Button>
</StyledForm>
</Container>
Expand Down Expand Up @@ -78,33 +72,45 @@ const svgClassName = css({
fill: 'currentColor',
});

const Header = styled('header')(svgClassName, {
width: '100%',
marginBottom: unit * 5,
padding: unit * 2.5,
position: 'relative',
});

const StyledLogo = styled(Logo)(size(56), {
display: 'block',
margin: '0 auto',
position: 'relative',
});

const StyledCurve = styled(Curve)(size('100%'), {
fill: colors.primary,
position: 'absolute',
top: 0,
left: 0,
});
const Header = styled('header')([
svgClassName,
{
width: '100%',
marginBottom: unit * 5,
padding: unit * 2.5,
position: 'relative',
},
]);

const StyledLogo = styled(Logo)([
size(56),
{
display: 'block',
margin: '0 auto',
position: 'relative',
},
]);

const StyledCurve = styled(Curve)([
size('100%'),
{
fill: colors.primary,
position: 'absolute',
top: 0,
left: 0,
},
]);

const Heading = styled('h1')({
margin: `${unit * 3}px 0 ${unit * 6}px`,
});

const StyledRocket = styled(Rocket)(svgClassName, {
width: 250,
});
const StyledRocket = styled(Rocket)([
svgClassName,
{
width: 250,
},
]);

const StyledForm = styled('form')({
width: '100%',
Expand Down
5 changes: 3 additions & 2 deletions final/client/src/components/menu-item.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import styled, { css } from 'react-emotion';
import { Link } from '@reach/router';
import styled from '@emotion/styled';
import { css } from '@emotion/react';
import { Link } from 'react-router-dom';
import { colors, unit } from '../styles';

export const menuItemClassName = css({
Expand Down
4 changes: 2 additions & 2 deletions final/client/src/components/page-container.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { Fragment } from 'react';
import styled from 'react-emotion';
import styled from '@emotion/styled';

import { unit, colors } from '../styles';

export default function PageContainer (props: any) {
export default function PageContainer(props: any) {
return (
<Fragment>
<Bar />
Expand Down
4 changes: 2 additions & 2 deletions final/client/src/containers/__tests__/action-button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { renderApollo, cleanup } from '../../test-utils';
import { renderApollo, cleanup, waitFor } from '../../test-utils';
import ActionButton from '../action-button';
import { cartItemsVar } from '../../cache';

Expand All @@ -18,7 +18,7 @@ describe('action button', () => {
getByText(/add to cart/i);

// rerender with different props to same container
cartItemsVar(['1']);
waitFor(() => cartItemsVar(['1']));
renderApollo(<ActionButton id="1" />, { container });
getByText(/remove from cart/i);
cartItemsVar([]);
Expand Down
16 changes: 4 additions & 12 deletions final/client/src/containers/__tests__/book-trips.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import React from 'react';

import {
renderApollo,
cleanup,
fireEvent,
waitForElement,
} from '../../test-utils';
import { renderApollo, cleanup, fireEvent, waitFor } from '../../test-utils';
import BookTrips, { BOOK_TRIPS } from '../book-trips';
import { GET_LAUNCH } from '../cart-item';

Expand Down Expand Up @@ -48,18 +43,15 @@ describe('book trips', () => {
result: { data: { launch: mockLaunch } },
},
];
const { getByTestId } = renderApollo(
<BookTrips cartItems={['1']} />,
{ mocks, addTypename: false },
);
const { getByTestId } = renderApollo(<BookTrips cartItems={['1']} />, { mocks, addTypename: false });

fireEvent.click(getByTestId('book-button'));

// Let's wait until our mocked mutation resolves and
// the component re-renders.
// getByTestId throws an error if it cannot find an element with the given ID
// and waitForElement will wait until the callback doesn't throw an error
await waitForElement(() => getByTestId('message'));
// and waitFor will wait until the callback doesn't throw an error
await waitFor(() => getByTestId('message'));
});

// >>>> TODO
Expand Down
12 changes: 4 additions & 8 deletions final/client/src/containers/__tests__/cart-item.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import React from 'react';

import {
renderApollo,
cleanup,
waitForElement,
} from '../../test-utils';
import { renderApollo, cleanup, waitFor } from '../../test-utils';
import CartItem, { GET_LAUNCH } from '../cart-item';

const mockLaunch = {
Expand Down Expand Up @@ -43,7 +39,7 @@ describe('cart item', () => {
// check the loading state
getByText(/loading/i);

return waitForElement(() => getByText(/test mission/i));
return waitFor(() => getByText(/test mission/i));
});

it('renders with error state', () => {
Expand All @@ -61,6 +57,6 @@ describe('cart item', () => {
addTypename: false,
});

waitForElement(() => getByText(/error: aw shucks/i));
waitFor(() => getByText(/aw shucks/i));
});
});
});
4 changes: 2 additions & 2 deletions final/client/src/containers/__tests__/logout-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ describe('logout button', () => {

it('complete logout', async () => {
isLoggedInVar(true);
localStorage.setItem('token', 'testTokenValue');
localStorage.setItem('userId', 'abc123');
localStorage.setItem('token', window.btoa('testTokenValue'));
localStorage.setItem('userId', window.btoa('abc123'));
const { getByTestId } = renderApollo(<LogoutButton />, { cache });
fireEvent.click(getByTestId('logout-button'));
expect(isLoggedInVar()).toBeFalsy();
Expand Down
Loading