Skip to content

Commit

Permalink
Add Comments /
Browse files Browse the repository at this point in the history
Final tidy ups
  • Loading branch information
Ali-Sdg90 committed Mar 25, 2024
1 parent 0ec0325 commit fa17804
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion JS/categorySection.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion JS/initialAddCards.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion JS/sortSection.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion JS/sortSection.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions TS/categorySection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ catBtnsArray.map((catBtn) => {
catBtn.addEventListener("click", () => {
console.log("=>", catBtn.textContent);

// Reset sotBtn arrows
namePosition = sortBtnPositionHandler(2, 0);
pricePosition = sortBtnPositionHandler(2, 1);
ratePosition = sortBtnPositionHandler(2, 2);
Expand All @@ -17,6 +18,7 @@ catBtnsArray.map((catBtn) => {
return itemClass.category === catBtn.textContent?.toLowerCase();
});

// Reset selected category btn
if (!catBtn.classList.contains("selected-catbtn")) {
catBtnsArray.map((catBtn) => {
catBtn.classList.remove("selected-catbtn");
Expand All @@ -31,6 +33,7 @@ catBtnsArray.map((catBtn) => {

itemSection.innerHTML = "";

// Add categoryItem to HTML
for (let categoryItem in categoryItems) {
itemSection.innerHTML += categoryItems[categoryItem].createCard();
}
Expand Down
2 changes: 2 additions & 0 deletions TS/initialAddCards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const addCards = async () => {
itemSection.innerHTML = "";

items.map((item, index) => {
// Add classes into itemClasses array
itemClasses[index] = new Items(
item.id,
item.title,
Expand All @@ -16,6 +17,7 @@ const addCards = async () => {
item.rating
);

// Add Initial items to HTML
itemSection.innerHTML += itemClasses[index].createCard();
});

Expand Down
5 changes: 4 additions & 1 deletion TS/sortSection.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Sort number[] or string[] function
const sortFunc = (
sortType: "name" | "price" | "rating",
itemArray: (string | number | null)[]
Expand All @@ -22,7 +23,6 @@ const sortItemsFunc = (
itemPosition: number
) => {
const itemArray = categoryItems.map((card) => {
card.title;
switch (sortType) {
case "name":
return card.title;
Expand All @@ -39,6 +39,7 @@ const sortItemsFunc = (

console.log(">>", itemPosition);

// Different type of sort items (decrease, increase, normal)
switch (itemPosition) {
case 1:
sortedCardsItem = sortFunc(sortType, itemArray);
Expand Down Expand Up @@ -80,6 +81,7 @@ const sortItemsFunc = (
);
};

// Set different sort indicators for sort btns
const sortBtnPositionHandler = (
itemPosition: number,
sortArrowIndex: number
Expand Down Expand Up @@ -120,6 +122,7 @@ sortBtnsArray.map((sortBtn, index) => {
case 0:
console.log("=> Name");

// Reset other sort-btn-positions
namePosition = sortBtnPositionHandler(namePosition, 0);
pricePosition = sortBtnPositionHandler(2, 1);
ratePosition = sortBtnPositionHandler(2, 2);
Expand Down

0 comments on commit fa17804

Please sign in to comment.