Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Commit

Permalink
[128] New thumbnail structure
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrgrundas committed Dec 27, 2018
1 parent 13fe7c2 commit bef52bf
Show file tree
Hide file tree
Showing 41 changed files with 417 additions and 260 deletions.
32 changes: 18 additions & 14 deletions src/components/CartOverlay/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import "./scss/index.scss";

import * as React from "react";
import { ApolloConsumer } from "react-apollo";
import { Link } from "react-router-dom";
import ReactSVG from "react-svg";

import { Button } from "..";
import { priceToString } from "../../core/utils";
import { maybe, priceToString } from "../../core/utils";
import { checkoutLoginUrl } from "../App/routes";
import { CartContext } from "../CartProvider/context";
import { Error } from "../Error";
Expand All @@ -21,7 +23,10 @@ import Offline from "../Offline";
import OfflinePlaceholder from "../OfflinePlaceholder";
import Online from "../Online";

import "./scss/index.scss";
const cartSvg = require("../../images/cart.svg");
const closeSvg = require("../../images/x.svg");
const noPhotoPng = require("../../images/nophoto.png");
const removeSvg = require("../../images/garbage.svg");

export const CartOverlay: React.SFC = () => (
<OverlayContext.Consumer>
Expand Down Expand Up @@ -50,7 +55,7 @@ export const CartOverlay: React.SFC = () => (
<div className="cart">
<div className="overlay__header">
<ReactSVG
path={require("../../images/cart.svg")}
path={cartSvg}
className="overlay__header__cart-icon"
/>
<div className="overlay__header-text">
Expand All @@ -60,7 +65,7 @@ export const CartOverlay: React.SFC = () => (
</span>
</div>
<ReactSVG
path={require("../../images/x.svg")}
path={closeSvg}
onClick={() => overlay.hide()}
className="overlay__header__close-icon"
/>
Expand All @@ -74,24 +79,23 @@ export const CartOverlay: React.SFC = () => (
className="cart__list__item"
>
<CachedImage
url={
line.variant.product.thumbnailUrl ||
require("../../images/nophoto.png")
}
url2x={line.variant.product.thumbnailUrl2x}
url={maybe(
() => line.variant.product.thumbnail.url,
noPhotoPng
)}
url2x={maybe(
() => line.variant.product.thumbnail2x.url
)}
/>
<div className="cart__list__item__details">
<p>{line.variant.price.localized}</p>
<p>{line.variant.product.name}</p>
<span className="cart__list__item__details__variant">
<span>{line.variant.name}</span>
<span>
Qty:
{line.quantity}
</span>
<span>{"Qty: " + line.quantity}</span>
</span>
<ReactSVG
path={require("../../images/garbage.svg")}
path={removeSvg}
className="cart__list__item__details__delete-icon"
onClick={() =>
cart.remove(line.variant.id)
Expand Down
29 changes: 18 additions & 11 deletions src/components/CartPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "./scss/index.scss";

import * as React from "react";
import { ApolloConsumer, Query } from "react-apollo";
import Media from "react-media";
Expand All @@ -6,18 +8,20 @@ import { Link } from "react-router-dom";
import ReactSVG from "react-svg";

import { Button, Loader } from "..";
import { getCheckout } from "../../core/types/saleor";
import { maybe } from "../../core/utils";
import { checkoutLoginUrl } from "../App/routes";
import { smallScreen } from "../App/scss/variables.scss";
import CachedImage from "../CachedImage";
import { CartContext } from "../CartProvider/context";
import { GET_CHECKOUT } from "../CheckoutApp/queries";
import { getCheckout } from "../CheckoutApp/types/getCheckout";
import { Error } from "../Error";
import { GoToCheckout } from "../GoToCheckout";
import { UserContext } from "../User/context";
import { EmptyCart } from "./EmptyCart";

import { smallScreen } from "../App/scss/variables.scss";
import CachedImage from "../CachedImage";
import "./scss/index.scss";
const noPhotoPng = require("../../images/nophoto.png");
const removeSvg = require("../../images/garbage.svg");

const canDisplay = (data: getCheckout) =>
data && data.checkout && data.checkout.lines && data.checkout.subtotalPrice;
Expand Down Expand Up @@ -67,11 +71,13 @@ const CartPage: React.SFC<RouteComponentProps<{ token }>> = ({
query={{ minWidth: smallScreen }}
render={() => (
<CachedImage
url={
line.variant.product.thumbnailUrl ||
require("../../images/nophoto.png")
}
url2x={line.variant.product.thumbnailUrl2x}
url={maybe(
() => line.variant.product.thumbnail.url,
noPhotoPng
)}
url2x={maybe(
() => line.variant.product.thumbnail2x.url
)}
/>
)}
/>
Expand All @@ -93,7 +99,7 @@ const CartPage: React.SFC<RouteComponentProps<{ token }>> = ({
<CartContext.Consumer>
{({ remove }) => (
<ReactSVG
path={require("../../images/garbage.svg")}
path={removeSvg}
className="cart__list__item__details__delete-icon"
onClick={() => remove(line.variant.id)}
/>
Expand Down Expand Up @@ -122,7 +128,8 @@ const CartPage: React.SFC<RouteComponentProps<{ token }>> = ({
<ApolloConsumer>
{client => (
<GoToCheckout apolloClient={client}>
Checkout
{" "}
Checkout{" "}
</GoToCheckout>
)}
</ApolloConsumer>
Expand Down
4 changes: 2 additions & 2 deletions src/components/CartProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react";

import { ApolloClient } from "apollo-client";
import { GET_CHECKOUT, UPDATE_CHECKOUT_LINE } from "../CheckoutApp/queries";
import { GET_PRODUCTS_VARIANTS } from "../ProductPage/queries";
import { productVariatnsQuery } from "../ProductPage/queries";
import { CartContext, CartInterface, CartLineInterface } from "./context";

export default class CartProvider extends React.Component<
Expand Down Expand Up @@ -93,7 +93,7 @@ export default class CartProvider extends React.Component<
let data: { [key: string]: any };
let lines;
const response = await apolloClient.query({
query: GET_PRODUCTS_VARIANTS,
query: productVariatnsQuery,
variables: { ids: cart.map(line => line.variantId) }
});
const quantityMapping = cart.reduce((obj, line) => {
Expand Down
15 changes: 9 additions & 6 deletions src/components/CartSummary/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import "./scss/index.scss";

import * as React from "react";

import { maybe } from "../../core/utils";
import { CheckoutContext } from "../CheckoutApp/context";

import "./scss/index.scss";
const noPhotoPng = require("../../images/nophoto.png");

const CartSummary: React.SFC<{}> = () => (
const CartSummary: React.SFC = () => (
<CheckoutContext.Consumer>
{({ checkout }) =>
checkout ? (
Expand All @@ -13,10 +16,10 @@ const CartSummary: React.SFC<{}> = () => (
{checkout.lines.map(product => (
<div key={product.id} className="cart-summary__product-item">
<img
src={
product.variant.product.thumbnailUrl ||
require("../../images/nophoto.png")
}
src={maybe(
() => product.variant.product.thumbnail.url,
noPhotoPng
)}
/>
<div>
<p>{product.variant.price.localized}</p>
Expand Down
4 changes: 2 additions & 2 deletions src/components/CheckoutApp/context.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { createContext } from "react";

import { CheckoutInterface } from "../../core/types";
import { Checkout } from "./types/Checkout";

export interface CheckoutContextInterface {
cardData?: {
lastDigits: string;
ccType: string;
token: string;
};
checkout?: CheckoutInterface;
checkout?: Checkout;
loading?: boolean;
shippingAsBilling?: boolean;
updateCheckout?(chekcoutData: CheckoutContextInterface): void;
Expand Down
9 changes: 7 additions & 2 deletions src/components/CheckoutApp/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,13 @@ export const CHECKOUT_FRAGMENT = gql`
product {
id
name
thumbnailUrl
thumbnailUrl2x: thumbnailUrl(size: 510)
thumbnail {
url
alt
}
thumbnail2x: thumbnail(size: 510){
url
}
}
}
quantity
Expand Down
15 changes: 13 additions & 2 deletions src/components/CheckoutApp/types/Checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,23 @@ export interface Checkout_lines_variant_price {
localized: string;
}

export interface Checkout_lines_variant_product_thumbnail {
__typename: "Image";
url: string;
alt: string | null;
}

export interface Checkout_lines_variant_product_thumbnail2x {
__typename: "Image";
url: string;
}

export interface Checkout_lines_variant_product {
__typename: "Product";
id: string;
name: string;
thumbnailUrl: string | null;
thumbnailUrl2x: string | null;
thumbnail: Checkout_lines_variant_product_thumbnail | null;
thumbnail2x: Checkout_lines_variant_product_thumbnail2x | null;
}

export interface Checkout_lines_variant {
Expand Down
15 changes: 13 additions & 2 deletions src/components/CheckoutApp/types/getCheckout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,23 @@ export interface getCheckout_checkout_lines_variant_price {
localized: string;
}

export interface getCheckout_checkout_lines_variant_product_thumbnail {
__typename: "Image";
url: string;
alt: string | null;
}

export interface getCheckout_checkout_lines_variant_product_thumbnail2x {
__typename: "Image";
url: string;
}

export interface getCheckout_checkout_lines_variant_product {
__typename: "Product";
id: string;
name: string;
thumbnailUrl: string | null;
thumbnailUrl2x: string | null;
thumbnail: getCheckout_checkout_lines_variant_product_thumbnail | null;
thumbnail2x: getCheckout_checkout_lines_variant_product_thumbnail2x | null;
}

export interface getCheckout_checkout_lines_variant {
Expand Down
17 changes: 14 additions & 3 deletions src/components/CheckoutApp/types/updateCheckoutLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,23 @@ export interface updateCheckoutLine_checkoutLinesUpdate_checkout_lines_variant_p
localized: string;
}

export interface updateCheckoutLine_checkoutLinesUpdate_checkout_lines_variant_product_thumbnail {
__typename: "Image";
url: string;
alt: string | null;
}

export interface updateCheckoutLine_checkoutLinesUpdate_checkout_lines_variant_product_thumbnail2x {
__typename: "Image";
url: string;
}

export interface updateCheckoutLine_checkoutLinesUpdate_checkout_lines_variant_product {
__typename: "Product";
id: string;
name: string;
thumbnailUrl: string | null;
thumbnailUrl2x: string | null;
thumbnail: updateCheckoutLine_checkoutLinesUpdate_checkout_lines_variant_product_thumbnail | null;
thumbnail2x: updateCheckoutLine_checkoutLinesUpdate_checkout_lines_variant_product_thumbnail2x | null;
}

export interface updateCheckoutLine_checkoutLinesUpdate_checkout_lines_variant {
Expand Down Expand Up @@ -202,7 +213,7 @@ export interface updateCheckoutLine_checkoutLinesUpdate_errors {
export interface updateCheckoutLine_checkoutLinesUpdate {
__typename: "CheckoutLinesUpdate";
checkout: updateCheckoutLine_checkoutLinesUpdate_checkout | null;
errors: (updateCheckoutLine_checkoutLinesUpdate_errors | null)[] | null;
errors: updateCheckoutLine_checkoutLinesUpdate_errors[] | null;
}

export interface updateCheckoutLine {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,23 @@ export interface updateCheckoutBillingAddress_checkoutBillingAddressUpdate_check
localized: string;
}

export interface updateCheckoutBillingAddress_checkoutBillingAddressUpdate_checkout_lines_variant_product_thumbnail {
__typename: "Image";
url: string;
alt: string | null;
}

export interface updateCheckoutBillingAddress_checkoutBillingAddressUpdate_checkout_lines_variant_product_thumbnail2x {
__typename: "Image";
url: string;
}

export interface updateCheckoutBillingAddress_checkoutBillingAddressUpdate_checkout_lines_variant_product {
__typename: "Product";
id: string;
name: string;
thumbnailUrl: string | null;
thumbnailUrl2x: string | null;
thumbnail: updateCheckoutBillingAddress_checkoutBillingAddressUpdate_checkout_lines_variant_product_thumbnail | null;
thumbnail2x: updateCheckoutBillingAddress_checkoutBillingAddressUpdate_checkout_lines_variant_product_thumbnail2x | null;
}

export interface updateCheckoutBillingAddress_checkoutBillingAddressUpdate_checkout_lines_variant {
Expand Down Expand Up @@ -201,7 +212,7 @@ export interface updateCheckoutBillingAddress_checkoutBillingAddressUpdate_check

export interface updateCheckoutBillingAddress_checkoutBillingAddressUpdate {
__typename: "CheckoutBillingAddressUpdate";
errors: (updateCheckoutBillingAddress_checkoutBillingAddressUpdate_errors | null)[] | null;
errors: updateCheckoutBillingAddress_checkoutBillingAddressUpdate_errors[] | null;
checkout: updateCheckoutBillingAddress_checkoutBillingAddressUpdate_checkout | null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/CheckoutPayment/types/createPayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface createPayment_checkoutPaymentCreate_errors {

export interface createPayment_checkoutPaymentCreate {
__typename: "CheckoutPaymentCreate";
errors: (createPayment_checkoutPaymentCreate_errors | null)[] | null;
errors: createPayment_checkoutPaymentCreate_errors[] | null;
}

export interface createPayment {
Expand Down
Loading

0 comments on commit bef52bf

Please sign in to comment.