Skip to content

Commit

Permalink
Converting to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
rbboimer committed Jan 16, 2019
1 parent 6286a7f commit 41ff359
Show file tree
Hide file tree
Showing 44 changed files with 469 additions and 211 deletions.
20 changes: 17 additions & 3 deletions assets/package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
{
"name": "marvin-2.0",
"name": "aws-bookstore-demo-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@types/jest": "^23.3.10",
"@types/node": "^10.12.12",
"@types/react": "^16.7.12",
"@types/react-bootstrap": "^0.32.15",
"@types/react-dom": "^16.0.11",
"@types/react-router-bootstrap": "^0.24.5",
"@types/react-router-dom": "^4.3.1",
"aws-amplify": "^1.0.10",
"bootstrap": "^3.3.7",
"react": "^16.5.0",
"react-bootstrap": "^0.32.4",
"react-dom": "^16.5.0",
"react-router-bootstrap": "^0.24.4",
"react-router-dom": "^4.3.1",
"react-scripts": "1.1.5"
"react-scripts": "^2.1.0",
"typescript": "^3.2.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"devDependencies": {}
"devDependencies": {},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
File renamed without changes.
23 changes: 16 additions & 7 deletions assets/src/App.js → assets/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@ import { LinkContainer } from "react-router-bootstrap";
import { Link, withRouter } from "react-router-dom";
import { Nav, Navbar, NavItem } from "react-bootstrap";
import "./App.css";
import Routes from "./Routes";
import { Routes } from "./Routes";

const bookstoreIcon = "data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTYuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvb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MC41MzgsMC4wNDItMC43OTEsMC4xMjIgICAgbC0xMS4xNDgsMy4xMjFsLTEwNi4xNDgsMjkuNzY0bC0xLjI5OC00MC4yODlsMzQuODI2LTExLjM1OWw4NC4zMjctMjcuNTAxYzAuMDExLTAuMDA1LDQuNDM2LTAuOTg4LDcuNjg0LDIuMzE1ICAgIGMzLjE0NCwzLjIxNCw0LjcwNCw5LjUzNyw0LjUyLDE4LjI4QzMxMy44NDgsMTg0LjAzNSwzMDIuODI3LDE4NS4wNTMsMzAyLjQyNiwxODUuMDg0eiIgZmlsbD0iI2Y2OTgyNyIvPgoJPC9nPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+Cjwvc3ZnPgo=";

class App extends Component {
constructor(props) {
interface AppProps {
history: any;
}

interface AppState {
isAuthenticated: boolean;
isAuthenticating: boolean;
}

class App extends Component<AppProps, AppState> {
constructor(props: AppProps) {
super(props);

this.state = {
Expand All @@ -35,11 +44,11 @@ class App extends Component {
this.setState({ isAuthenticating: false });
}

userHasAuthenticated = authenticated => {
userHasAuthenticated = (authenticated: boolean) => {
this.setState({ isAuthenticated: authenticated });
}

handleLogout = async (event) => {
handleLogout = async () => {
await Auth.signOut();

this.userHasAuthenticated(false);
Expand Down Expand Up @@ -100,10 +109,10 @@ class App extends Component {
</Nav>
</Navbar.Collapse>
</Navbar>
<Routes childProps={childProps} />
<Routes isAuthenticated={childProps.isAuthenticated} userHasAuthenticated={childProps.userHasAuthenticated} />
</div>
);
}
}

export default withRouter(App);
export default withRouter(App as any);
29 changes: 0 additions & 29 deletions assets/src/Routes.js

This file was deleted.

34 changes: 34 additions & 0 deletions assets/src/Routes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from "react";
import { Route, Switch } from "react-router-dom";
import Checkout from "./modules/checkout/Checkout";
import CheckoutConfirm from "./modules/checkout/CheckoutConfirm";
import Home from "./modules/signup/Home";
import Login from "./modules/signup/Login";
import NotFound from "./modules/notFound/NotFound";
import Signup from "./modules/signup/Signup";
import CategoryView from "./modules/category/CategoryView";
import ShoppingCart from "./modules/cart/ShoppingCart";
import PastPurchases from "./modules/pastPurchases/PastPurchases";
import BestSellers from "./modules/bestSellers/BestSellers";
import SearchView from "./modules/search/SearchView";
import PropsRoute from "./common/PropsRoute";

interface RouteProps {
isAuthenticated: boolean;
userHasAuthenticated: (authenticated: boolean) => void;
}

export const Routes: React.SFC<RouteProps> = (childProps) =>
<Switch>
<PropsRoute path="/" exact component={Home} props={childProps} />
<PropsRoute path="/login" exact component={Login} props={childProps} />
<PropsRoute path="/signup" exact component={Signup} props={childProps} />
<Route path="/best" exact component={BestSellers} />
<Route path="/cart" exact component={ShoppingCart} />
<Route path="/category/:id" exact component={CategoryView} />
<Route path="/past" exact component={PastPurchases} />
<Route path="/checkout" exact component={Checkout} />
<Route path="/checkout-confirm" exact component={CheckoutConfirm} />
<Route path="/search/:id" exact component={SearchView} />
<Route component={NotFound} />
</Switch>;
17 changes: 14 additions & 3 deletions assets/src/common/AddToCart.js → assets/src/common/AddToCart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@ import { API } from 'aws-amplify';
import { Redirect } from 'react-router';
import { Glyphicon } from 'react-bootstrap';

class AddToCart extends React.Component {
constructor(props) {
interface AddToCartProps {
bookId: string;
price: number;
variant?: string;
}

interface AddToCartState {
loading: boolean;
toCart: boolean;
}

class AddToCart extends React.Component<AddToCartProps, AddToCartState> {
constructor(props: AddToCartProps) {
super(props);

this.state = {
Expand All @@ -15,7 +26,7 @@ class AddToCart extends React.Component {

onAddToCart = async () => {
this.setState({ loading: true });
const bookInCart = await API.get("cart", `/cart/${this.props.bookId}`);
const bookInCart = await API.get("cart", `/cart/${this.props.bookId}`, null);

// if the book already exists in the cart, increase the quantity
if (bookInCart) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import { Route } from "react-router-dom";
import { Route } from "react-router";

//@ts-ignore
export default ({ component: C, props: cProps, ...rest }) =>
<Route {...rest} render={props => <C {...props} {...cProps} />} />;
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ import { API } from 'aws-amplify';
import React from 'react';
import { FriendThumb } from './FriendThumb';

class FriendRecommendations extends React.Component {
constructor(props) {
interface FriendRecommendationsProps {
bookId: string;
}

interface FriendRecommendationsState {
friends: any[];
}

class FriendRecommendations extends React.Component<FriendRecommendationsProps, FriendRecommendationsState> {
constructor(props: FriendRecommendationsProps) {
super(props);

this.state = {
Expand All @@ -12,7 +20,7 @@ class FriendRecommendations extends React.Component {
}

getFriends = () => {
return API.get("recommendations", `/recommendations/${this.props.bookId}`);
return API.get("recommendations", `/recommendations/${this.props.bookId}`, null);
}

async componentDidMount() {
Expand All @@ -36,7 +44,7 @@ class FriendRecommendations extends React.Component {
<div>
<div>Friends who bought this book</div>
<p>
{friends.slice(0, 3).map(friend => <FriendThumb key={friend} />)}
{friends.slice(0, 3).map((friend: any) => <FriendThumb key={friend} />)}
{numFriendsPurchased > 3 && <span className="orange">{` +${numFriendsPurchased - 3} ${(numFriendsPurchased - 3) > 1 ? "others" : "other"}`}</span>}
</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import Sarah from "../../images/avatars/Sarah.png";

const friends = [Brenda, Erin, Jacob, Jeff, Jennifer, John, Sarah];

export class FriendThumb extends React.Component {
interface FriendThumbProps {}

export class FriendThumb extends React.Component<FriendThumbProps> {
render() {
const randomFriend = friends[Math.floor(Math.random() * friends.length)];
return (
Expand Down
File renamed without changes.
9 changes: 0 additions & 9 deletions assets/src/common/loaderButton/LoaderButton.css

This file was deleted.

20 changes: 0 additions & 20 deletions assets/src/common/loaderButton/LoaderButton.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import React from 'react';
import { Glyphicon } from 'react-bootstrap';
import "./starRating.css";

class StarRating extends React.Component {
interface StarRatingProps {
stars: number
}

class StarRating extends React.Component<StarRatingProps> {
render() {
return (
<span>
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,30 @@ import FriendRecommendations from "../../common/friendRecommendations/FriendReco
import StarRating from "../../common/starRating/StarRating";
import "../../common/styles/productRow.css";

export class ProductRow extends React.Component {
constructor(props) {
interface ProductRowProps {
bookId: string;
}

export interface Book {
id: string;
cover: string;
price: number;
category: string;
name: string;
rating: number;
author: string;
}

interface ProductRowState {
book: Book | undefined;
}

export class ProductRow extends React.Component<ProductRowProps, ProductRowState> {
constructor(props: ProductRowProps) {
super(props);

this.state = {
book: null,
book: undefined,
};
}

Expand All @@ -25,7 +43,7 @@ export class ProductRow extends React.Component {
}

getBook() {
return API.get("books", `/books/${this.props.bookId}`);
return API.get("books", `/books/${this.props.bookId}`, null);
}

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ import BestSellerProductRow from "./BestSellerProductRow";
import { CategoryNavBar } from "../category/categoryNavBar/CategoryNavBar";
import { SearchBar } from "../search/searchBar/SearchBar";

export default class BestSellers extends React.Component {
constructor(props) {
interface BestSellersProps {}

interface BestSellersState {
isLoading: boolean;
books: { bookId: any; }[];
}

export default class BestSellers extends React.Component<BestSellersProps, BestSellersState> {
constructor(props: BestSellersProps) {
super(props);

this.state = {
Expand All @@ -18,7 +25,7 @@ export default class BestSellers extends React.Component {
async componentDidMount() {
try {
const books = [];
const bestSellers = await API.get("bestsellers", "/bestsellers");
const bestSellers = await API.get("bestsellers", "/bestsellers", null);

// Map the elasticache results to a book object
for (var i = 0; i < bestSellers.length; i++) {
Expand Down
Loading

0 comments on commit 41ff359

Please sign in to comment.