|
@@ -1,10 +1,85 @@
|
|
-import React from 'react'
|
|
|
|
|
|
+import React, {useState, useEffect} from 'react'
|
|
|
|
|
|
-import { ExampleComponent } from 'metaplate'
|
|
|
|
|
|
+import { MetaPlate } from 'metaplate'
|
|
import 'metaplate/dist/index.css'
|
|
import 'metaplate/dist/index.css'
|
|
|
|
|
|
-const App = () => {
|
|
|
|
- return <ExampleComponent text="Create React Library Example 😄" />
|
|
|
|
|
|
+
|
|
|
|
+const shopUrl = 'http://shop-roles.asmer.fs.a-level.com.ua/'
|
|
|
|
+
|
|
|
|
+const getGQL = (url=shopUrl + 'graphql', headers={}) =>
|
|
|
|
+ (query="", variables={}) =>
|
|
|
|
+ fetch(url,
|
|
|
|
+ {method: 'POST',
|
|
|
|
+ headers: {
|
|
|
|
+ 'Accept': 'application/json',
|
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
|
+ ...headers
|
|
|
|
+ },
|
|
|
|
+ body: JSON.stringify({query,variables})
|
|
|
|
+ })
|
|
|
|
+ .then(res => res.json())
|
|
|
|
+
|
|
|
|
+const Image = ({image:{url}}) => <img src={`${shopUrl}${url}`} />
|
|
|
|
+
|
|
|
|
+const Good = ({good, children}) =>
|
|
|
|
+good ?
|
|
|
|
+<div className='Good'>
|
|
|
|
+ <h2>{good.name}</h2>
|
|
|
|
+ <p>{good.description}</p>
|
|
|
|
+ <money>{good.price}</money>
|
|
|
|
+ {children}
|
|
|
|
+</div>
|
|
|
|
+: <h3>null</h3>
|
|
|
|
+
|
|
|
|
+const Category = ({category:{name, _id}, children}) =>
|
|
|
|
+<div className='Category'>
|
|
|
|
+ <h1>{name}</h1>
|
|
|
|
+ {children}
|
|
|
|
+</div>
|
|
|
|
+
|
|
|
|
+const MetaTest = () => {
|
|
|
|
+ const [data, setData] = useState()
|
|
|
|
+
|
|
|
|
+ const query =
|
|
|
|
+ `query MainCategories{
|
|
|
|
+ CategoryFind(query: "[{}]"){
|
|
|
|
+ _id name
|
|
|
|
+ image{
|
|
|
|
+ url
|
|
|
|
+ }
|
|
|
|
+ goods{
|
|
|
|
+ name description price images{
|
|
|
|
+ url
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ subCategories{ name }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ `
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ getGQL()(query).then(data => setData(data.data.CategoryFind))
|
|
|
|
+ },[])
|
|
|
|
+
|
|
|
|
+ return (
|
|
|
|
+ <MetaPlate data={data}>
|
|
|
|
+ <Category prop="category" keyDataKey="_id">
|
|
|
|
+ <Good sourceDataKey="goods" prop="good" keyDataKey="_id">
|
|
|
|
+ <div sourceDataKey="images">
|
|
|
|
+ <Image prop="image" keyDataKey="_id"/>
|
|
|
|
+ </div>
|
|
|
|
+ </Good>
|
|
|
|
+ <Category sourceDataKey="subCategories" prop="category" keyDataKey="_id">
|
|
|
|
+ </Category>
|
|
|
|
+ </Category>
|
|
|
|
+ </MetaPlate>)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+const App = () =>
|
|
|
|
+<>
|
|
|
|
+ <MetaTest />
|
|
|
|
+</>
|
|
|
|
+
|
|
|
|
+
|
|
export default App
|
|
export default App
|