type THash = {
id: number;
hash: string;
};
type TChannel = {
channelid: number;
childrenHash: THash[];
};
type TData = TChannel[];
type THashAcc = Record<THash["hash"], THash["id"][]>;
export const comparsion = (data: TData) =>
data.map((n) => {
const ids = Object.values(
n.childrenHash.reduce<THashAcc>((acc, m) => ((acc[m.hash] ??= []).push(m.id), acc), {})
).filter((m) => m.length > 1);
return {
...n,
childrenHash: ids.length ? ids : null,
};
});
const [email, setEmail] = useState("")
const [password, setPassword] = useState("")
import React from "react";
import { Products } from "../Products";
class Main extends React.Component {
state = {
products: [],
};
componentDidMount() {
fetch("./products.json")
.then((responce) => responce.json())
.then((data) => this.setState({ products: Object.values(data) }));
}
render() {
const { products } = this.state;
return (
<main className="container content">
<Products products={products} />
</main>
);
}
}
export { Main };
class OurCoffee extends Component {
constructor(props) {
super(props);
this.state = {
data: [
{ name: "AROMISTICO Coffee 1 kg", country: "Brazil", price: 6.99 },
{ name: "AROMISTICO Coffee 1 kg", country: "Kenya", price: 6.99 },
{ name: "AROMISTICO Coffee 1 kg", country: "Columbia", price: 6.99 }
],
term: ""
};
}
commitInputChanges = (e) => {
this.setState({ term: e.target.value });
};
render() {
const { data, term } = this.state;
return (
<div>
<div className="filter">
<div className="filter_first">
<h2>Looking for</h2>
<input
type="text"
placeholder="start typing here"
onChange={this.commitInputChanges}
/>
</div>
</div>
{data
.filter((item) =>
item.country.toLowerCase().includes(term.toLowerCase())
)
.map((item) => (
<div key={item.country} className="product">
<img src={"coffee"} alt="" />
<h2 className="item_name">{item.name}</h2>
<h2 className="item_from">{item.country}</h2>
<h2 className="item_price">{item.price}</h2>
</div>
))}
</div>
);
}
}
export default OurCoffee;
handleChangeInfoMain: (value: string) => void
import { gql } from "@apollo/client";
export const getChooseProductQuery = (id) => gql`
query {
product(id: ${id}) {
name
description
}
}
`;
import { useQuery } from "@apollo/client";
import { getChooseProductQuery } from "../graphql/Queries";
export default function Product(props) {
const { id } = props;
const { data } = useQuery(getChooseProductQuery(id));
if (data) {
console.log(data);
}
}