From f2d45a11b9dce5e4d6c601c51f2d4c15cc11c726 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Mon, 8 May 2023 09:54:56 -0500 Subject: [PATCH] Finish sorting algorithm and list displays --- src/App.js | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 2 deletions(-) diff --git a/src/App.js b/src/App.js index 615ad69..eb406c3 100755 --- a/src/App.js +++ b/src/App.js @@ -398,12 +398,85 @@ function ListApp(p){ return new Promise(resolve => setTimeout(resolve, ms)); } + async function itemComesBefore(retainer,item){ + let targetItem="" + let result=false; + switch(retainer){ + case 0:{ + targetItem=item1 + }break; + case 1:{ + targetItem=item2 + }break; + case 2:{ + targetItem=item3 + }break; + case 3:{ + targetItem=item4 + }break; + case 4:{ + targetItem=item5 + }break; + } + let itemData1={} + let itemData2={} + await axios.get(encodeURI("https://xivapi.com/search?string="+item)) + .then(async(data)=>{ + var results = data.data.Results + for (var r of results) { + if (r.Name===item&&r.UrlType==="Item") { + return await axios.get(encodeURI("https://xivapi.com"+r.Url)) + } + } + throw new Error("Item 1 Not Found!"); + } + ) + .then(async(data)=>{ + var results = data.data + itemData1={...results} + return await axios.get(encodeURI("https://xivapi.com/search?string="+targetItem)) + }) + .then(async(data)=>{ + var results = data.data.Results + for (var r of results) { + if (r.Name===targetItem&&r.UrlType==="Item") { + return await axios.get(encodeURI("https://xivapi.com"+r.Url)) + } + } + throw new Error("Item 2 Not Found!"); + } + ) + .then(async(data)=>{ + var results = data.data + itemData2={...results} + console.log(itemData1.Name+" vs "+itemData2.Name) + if (itemData1.ItemSortCategory.ID{console.log(err);setChecking(false)}) + + return [result,itemData1] + } + function submitForm(){ let classID=Number(selectedCrafter)+8 let filter="https://xivapi.com/search?filters=ClassJob.ID="+classID+",RecipeLevelTable.ClassJobLevel>="+minLevel+",RecipeLevelTable.ClassJobLevel<="+maxLevel let pageCount=0 let currentPage=1 let recipeData=[] + setChecking(true) axios.get(encodeURI(filter)) .then(async(resp)=>{ let data=resp.data @@ -429,8 +502,36 @@ function ListApp(p){ }) } }) - .finally(()=>{ - console.log(recipeData) + .finally(async()=>{ + //console.log(recipeData) + //setChecking(false) + let craftedItems={} + for(var recipe of recipeData){ + for (let i=0;i<5;i++){ + var ingredient=recipe["ItemIngredient"+i] + if (ingredient!==null){ + craftedItems[ingredient.Name]=1 + } + } + } + let retainerItems=[[],[],[],[],[],[]] + for (var item of Object.keys(craftedItems)){ + let found=false + for (var i=0;i<5;i++){ + let response = await itemComesBefore(i,item); + if (response[0]===true){ + retainerItems[i]=[response[1],...retainerItems[i]] + found=true + break; + } + } + if (found===false){ + retainerItems[5]=[item,...retainerItems[5]] + } + await sleep(250) + } + setGroceryList(retainerItems) + setChecking(false) }) } @@ -530,6 +631,13 @@ function ListApp(p){ + A + {groceryList.map((list,i)=><> +

{retainerNames[i]}

+
+
    + {list.map((item)=>
  • {item.Name}
  • )} +
)} }