Skip to content

Commit

Permalink
toSorted + delete unused props
Browse files Browse the repository at this point in the history
  • Loading branch information
soheil-moonesi committed Jul 15, 2023
1 parent b86122d commit a42237d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 33 deletions.
13 changes: 4 additions & 9 deletions src/All_Models.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,22 @@ import { useState } from "react";
import { _data } from "./App";

let listing_models = 1;
export function All_Models({ items, handleAddItems }) {
export function All_Models({ handleAddItems }) {
const [sortBy, setSortBy] = useState("product_list");

let sortedItems;

if (sortBy === "product_list") sortedItems = _data;

if (sortBy === "price_list")
sortedItems = _data.slice().sort((a, b) => a.price - b.price);
sortedItems = _data.toSorted((a, b) => a.price - b.price);

return (
<>
<h2 className="m-2 text-center">تمامی محصولات</h2>

<div className="w-80 flex border-2 broder-black">
<select
className="w-80"
onChange={(e) => setSortBy(e.target.value)}
value={sortBy}
>
<select className="w-80" onChange={(e) => setSortBy(e.target.value)}>
<option className="w-80" value="product_list">
بر اساس محصولات
</option>
Expand All @@ -38,7 +34,6 @@ export function All_Models({ items, handleAddItems }) {
{sortedItems.map((models) => (
<Models
modelsObj={models}
items={items}
handleAddItems={handleAddItems}
key={models.id}
/>
Expand All @@ -52,7 +47,7 @@ export function All_Models({ items, handleAddItems }) {
</>
);
}
function Models({ modelsObj, items, handleAddItems }) {
function Models({ modelsObj, handleAddItems }) {
const [buyCount, setBuyCount] = useState(0);

function buyCountIncrease() {
Expand Down
6 changes: 3 additions & 3 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const _data = [
name: "فتوسل 16 آمپر شیوا امواج",
price: "239000",
photo: "Models/فتوسل 16 آمپر شیوا امواج.jpg",
remaining: "1",
remaining: "10",
discountRate: "10",
finalPrice: 215000,
},
Expand All @@ -37,7 +37,7 @@ export const _data = [
name: "فتوسل 16 آمپر شیوا امواج",
price: "239000",
photo: "Models/فتوسل 16 آمپر شیوا امواج.jpg",
remaining: "1",
remaining: "10",
discountRate: "10",
finalPrice: 215000,
},
Expand Down Expand Up @@ -68,7 +68,7 @@ function App() {
return (
<div className=" w-auto h-auto bg-white flex flex-col justify-center items-center">
<Header />
<All_Models items={items} handleAddItems={handleAddItems} />
<All_Models handleAddItems={handleAddItems} />

<Buy_Section
items={items}
Expand Down
56 changes: 35 additions & 21 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,38 @@ let i = 5;
i < 6 ? console.log("i is less than 6") : console.log("i is greater than 6");

//test section 1
const items = [{ name: "wili" }, { name: "albert" }, { name: "jack" }];
const items0 = [{ name: "wili" }, { name: "albert" }, { name: "jack" }];

console.log(items0);

items0.push({ name: "Thomas" });

console.log(items0);

console.log(items);

items.push({ name: "Thomas" });

console.log(items);

let items2 = ['item 0'];


let items = [];

function handleAddItems(itemPass) {
items2 = [...items2, itemPass];
items = [items, itemPass];
}

handleAddItems("Item 0");
handleAddItems("Item 1");
handleAddItems("Item 2");

console.log(items2);
console.log(items);








//test section 1 end

//Spread Operator (...)
Expand Down Expand Up @@ -69,21 +83,21 @@ console.log(copiedArray);
console.log(originalArray === copiedArray);


function add(d, e, f) {
console.log(d);
console.log(e)
console.log(f)
}
// function add(d, e, f) {
// console.log(d);
// console.log(e)
// console.log(f)
// }

const numbers3 = [1, 2, 3];
// const numbers3 = [1, 2, 3];

add(...numbers3);
// add(...numbers3);


const some_numbers = [39, 12, 2]
console.log(some_numbers.sort());
//convert to utf-16
//https://convertcodes.com/utf16-encode-decode-convert-string/
//00330039 ---39
//00310032---12
//0032---2
// const some_numbers = [39, 12, 2]
// console.log(some_numbers.sort());
// convert to utf-16
// https://convertcodes.com/utf16-encode-decode-convert-string/
// 00330039 ---39
// 00310032---12
// 0032---2

0 comments on commit a42237d

Please sign in to comment.