@@ -10,8 +10,6 @@ import { SearchBar } from "../SearchBar/index";
1010
1111import { SWITCH_SELECTED_PRODUCT } from "../../graphql/mutation/Local/SWITCH_SELECTED_PRODUCT" ;
1212import { GET_SELECTED_PRODUCT } from "../../graphql/queries/Local/GET_SELECTED_PRODUCT" ;
13- import { GET_TODOS_BY_PRODUCT } from "../../graphql/queries/GET_TODOS_BY_PRODUCT" ;
14- import { GET_STATUS } from "../../graphql/queries/Local/GET_STATUS" ;
1513
1614import { state } from "../../utils/state" ;
1715
@@ -56,7 +54,7 @@ class ProductsContainer extends React.Component {
5654 const { products, theme } = this . props ;
5755
5856 return (
59- < >
57+ < React . Fragment >
6058 < SearchBar
6159 input = { input }
6260 onInputChange = { this . _onInputChange }
@@ -77,55 +75,39 @@ class ProductsContainer extends React.Component {
7775 return (
7876 < Container >
7977 { this . _filterProducts ( products , input ) . map ( ( product , i ) => (
80- < Query query = { GET_STATUS } key = { v4 ( ) } >
81- { ( { data : { status } } ) => {
82- if ( loading )
83- return (
84- < Loading
85- color = { theme . loading . color }
86- type = "bubbles"
87- width = { 50 }
88- height = { 50 }
89- />
90- ) ;
91- if ( error ) return < Error err = { error } /> ;
78+ < Mutation key = { v4 ( ) } mutation = { SWITCH_SELECTED_PRODUCT } >
79+ { mutate => {
80+ const highlightedProduct = selectedProduct
81+ ? product . name === selectedProduct . name
82+ : i === 0 ;
9283 return (
93- < Mutation mutation = { SWITCH_SELECTED_PRODUCT } >
94- { mutate => {
95- const highlightedProduct = selectedProduct
96- ? product . name === selectedProduct . name
97- : i === 0 ;
98- return (
99- < Product
100- onClick = { ( ) => {
101- if ( highlightedProduct ) return ;
102- const selectedProduct = {
103- id : product . id ,
104- name : product . name ,
105- __typename : "Product" ,
106- } ;
107- state . set ( { selectedProduct } ) ;
108- mutate ( {
109- variables : selectedProduct ,
110- } ) ;
111- } }
112- >
113- < Name highlight = { highlightedProduct } >
114- { product . name }
115- </ Name >
116- </ Product >
117- ) ;
84+ < Product
85+ onClick = { ( ) => {
86+ if ( highlightedProduct ) return ;
87+ const selectedProduct = {
88+ id : product . id ,
89+ name : product . name ,
90+ __typename : "Product" ,
91+ } ;
92+ state . set ( { selectedProduct } ) ;
93+ mutate ( {
94+ variables : selectedProduct ,
95+ } ) ;
11896 } }
119- </ Mutation >
97+ >
98+ < Name highlight = { highlightedProduct } >
99+ { product . name }
100+ </ Name >
101+ </ Product >
120102 ) ;
121103 } }
122- </ Query >
104+ </ Mutation >
123105 ) ) }
124106 </ Container >
125107 ) ;
126108 } }
127109 </ Query >
128- </ >
110+ </ React . Fragment >
129111 ) ;
130112 }
131113}
0 commit comments