Skip to content

Commit

Permalink
Update files
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivansultan committed Jul 20, 2021
1 parent 0136412 commit 788c4de
Show file tree
Hide file tree
Showing 18 changed files with 14,932 additions and 477 deletions.
14,410 changes: 14,410 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
},
"license": "ISC",
"dependencies": {
"@apollo/client": "^3.3.21",
"@types/react-select": "^4.0.15",
"antd-mobile": "2.0.0-alpha.9",
"apollo-client": "1.9.2",
"dotenv": "^4.0.0",
"es6-promise": "^4.0.5",
"formik": "^0.9.4",
"graphql": "^15.5.1",
"graphql-tag": "^2.4.2",
"history": "^4.6.3",
"immutability-helper": "^2.2.0",
Expand Down Expand Up @@ -94,7 +96,7 @@
"tslint": "^5.4.3",
"tslint-config-prettier": "^1.1.0",
"tslint-react": "^3.0.0",
"typescript": "^4.2.4",
"typescript": "^4.3.5",
"url-loader": "^0.5.9",
"webpack": "^3.0.0",
"webpack-dev-server": "^2.5.0"
Expand Down
16 changes: 11 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import * as React from "react";
import { ApolloProvider } from "react-apollo";
// import { ApolloProvider } from "react-apollo";
import { ApolloProvider } from "@apollo/client";
import { Route } from "react-router";
import { ConnectedRouter } from "react-router-redux";
import { Provider } from "react-redux";

import client from "./graphqlClient";
import history from "./history";
import { RouteSwitch } from "./routes";
import store from "./store";

const App = (props) => {
console.log("client", client);
return (
<ApolloProvider store={store} client={client as any}>
<ConnectedRouter history={history}>
<Route component={RouteSwitch} />
</ConnectedRouter>
<ApolloProvider client={client as any}>
<Provider store={store}>
<ConnectedRouter history={history}>
{/* <div>hello</div> */}
<Route component={RouteSwitch} />
</ConnectedRouter>
</Provider>
</ApolloProvider>
);
};
Expand Down
43 changes: 29 additions & 14 deletions src/graphqlClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import ApolloClient, { createBatchingNetworkInterface } from "apollo-client";
import { createNetworkInterface } from "react-apollo";
// import ApolloClient, { createBatchingNetworkInterface } from "apollo-client";
// import { createNetworkInterface } from "react-apollo";

import {
ApolloClient,
InMemoryCache,
ApolloProvider,
useQuery,
gql
} from "@apollo/client";

// const USE_QUERY_BATCHING = true;
const USE_QUERY_BATCHING = false;
Expand All @@ -8,20 +16,27 @@ const opts = {
credentials: "include"
} as any;

const networkInterface = USE_QUERY_BATCHING
? createBatchingNetworkInterface({
uri: process.env.GRAPHQL_ENDPOINT!,
opts,
batchInterval: 10, // in milliseconds
batchMax: 10
})
: createNetworkInterface({
uri: process.env.GRAPHQL_ENDPOINT,
opts
});
// const networkInterface = USE_QUERY_BATCHING
// ? createBatchingNetworkInterface({
// uri: process.env.GRAPHQL_ENDPOINT!,
// opts,
// batchInterval: 10, // in milliseconds
// batchMax: 10
// })
// : createNetworkInterface({
// uri: process.env.GRAPHQL_ENDPOINT,
// opts
// });

// const client = new ApolloClient({
// networkInterface
// });

console.log("uri", process.env.GRAPHQL_ENDPOINT)
const client = new ApolloClient({
networkInterface
uri: process.env.GRAPHQL_ENDPOINT,
cache: new InMemoryCache()
});


export default client;
10 changes: 6 additions & 4 deletions src/modules/cart/AddCartItem/AddCartItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ const options: OperationOption<OwnProps, GraphQLProps> = {
attributeValueIds
},
update: (store, props: IAddCartItem) => {
const { data: { addCartItem: { cartItem } } } = props;
const {
data: {
addCartItem: { cartItem }
}
} = props;
const data: IDataCart = store.readQuery({ query: CART_QUERY });
if (!data.cart) {
data.cart = cartItem.cart;
Expand All @@ -63,6 +67,4 @@ const options: OperationOption<OwnProps, GraphQLProps> = {
}
};

export default graphql<GraphQLProps, OwnProps>(ADD_CART_ITEM_MUTATION, options)(
AddCartItem
);
export default graphql<GraphQLProps, OwnProps>(ADD_CART_ITEM_MUTATION, options)(AddCartItem);
20 changes: 9 additions & 11 deletions src/modules/cart/Cart/Cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Button, Flex } from "antd-mobile";
import gql from "graphql-tag";
import { History } from "history";
import * as React from "react";
import { graphql, QueryProps } from "react-apollo";
import { graphql } from "react-apollo";
import { connect } from "react-redux";
import { Link } from "react-router-dom";
import { compose } from "redux";
Expand All @@ -25,8 +25,9 @@ interface StateProps {
router: IRouterReducer;
}

export interface IDataCart extends QueryProps {
export interface IDataCart {
cart?: ICart;
loading?: any;
}

interface GraphQLProps {
Expand All @@ -41,7 +42,7 @@ interface OwnProps {
const getCartTotalPrice = (cart: ICart): number => {
let totalPrice = 0;
if (cart && cart.items) {
cart.items.forEach(item => {
cart.items.forEach((item) => {
const { price, amount } = item;
totalPrice += getCartItemTotalPrice(price, amount);
});
Expand Down Expand Up @@ -70,20 +71,17 @@ class Cart extends React.Component<StateProps & GraphQLProps & OwnProps, {}> {
const cart = data.cart as ICart;
const amount = getCartAmount(cart);
if (amount === 0) {
return finishedId
? <FinishedCart id={finishedId} />
: <EmptyCart history={history} />;
return finishedId ? <FinishedCart id={finishedId} /> : <EmptyCart history={history} />;
}

return (
<Flex direction="column" justify="between" className={styles.Cart}>
<div className={styles.section}>
<div className={styles.title}>
Итого к оплате:{" "}
<Price isSinglePrice={true} price={getCartTotalPrice(cart)} />
Итого к оплате: <Price isSinglePrice={true} price={getCartTotalPrice(cart)} />
</div>
<div className={styles.items}>
{cart.items.map((item, index) =>
{cart.items.map((item, index) => (
<CartItem
key={index}
id={item.id}
Expand All @@ -92,7 +90,7 @@ class Cart extends React.Component<StateProps & GraphQLProps & OwnProps, {}> {
price={item.price}
amount={item.amount}
/>
)}
))}
</div>
</div>

Expand All @@ -101,7 +99,7 @@ class Cart extends React.Component<StateProps & GraphQLProps & OwnProps, {}> {
);
}

handleClick = e => {
handleClick = (e) => {
e.stopPropagation();
const { isModal, history } = this.props;
if (isModal) {
Expand Down
9 changes: 6 additions & 3 deletions src/modules/cart/CartTrigger/CartTrigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,12 @@ class CartTrigger extends React.Component<Props, {}> {
}
}

const mapStateToProps = (state: IRootReducer): StateProps => ({
router: state.router
});
const mapStateToProps = (state: IRootReducer): StateProps => {
console.log("state.router", state.router);
return {
router: state.router
};
};

export default compose(
graphql<GraphQLProps, OwnProps>(CART_QUERY),
Expand Down
Loading

0 comments on commit 788c4de

Please sign in to comment.