Przeglądaj źródła

fetch exchanges and recipes

raylu 2 miesięcy temu
rodzic
commit
d70d0b8bee
4 zmienionych plików z 82 dodań i 9 usunięć
  1. 26 5
      dist/main.js
  2. 4 3
      dist/main.js.map
  3. 11 1
      index.html
  4. 41 0
      src/main.ts

+ 26 - 5
dist/main.js

@@ -1,7 +1,28 @@
 // src/main.ts
-var main_default = {};
-export {
-  main_default as default
-};
+async function fetchData() {
+  const [recipesResponse, exchangesResponse] = await Promise.all([
+    fetch("https://api.prunplanner.org/data/recipes"),
+    fetch("https://api.prunplanner.org/data/exchanges")
+  ]);
+  const [recipes, prices] = await Promise.all([
+    recipesResponse.json(),
+    exchangesResponse.json()
+  ]);
+  return { recipes, prices };
+}
+function render({ recipes, prices }) {
+  const tbody = document.querySelector("tbody");
+  for (const recipe of recipes) {
+    if (recipe.BuildingTicker !== "FRM")
+      continue;
+    const row = document.createElement("tr");
+    row.innerHTML = `
+			<td>${recipe.RecipeName}</td>
+			<td></td>
+		`;
+    tbody.appendChild(row);
+  }
+}
+fetchData().then(render);
 
-//# debugId=7ACBF329D9352D3964756E2164756E21
+//# debugId=87EA56A94163896264756E2164756E21

+ 4 - 3
dist/main.js.map

@@ -1,9 +1,10 @@
 {
   "version": 3,
-  "sources": [],
+  "sources": ["../src/main.ts"],
   "sourcesContent": [
+    "interface Recipe {\n\tRecipeId: string;\n\tBuildingTicker: string;\n\tRecipeName: string;\n\tTimeMs: number;\n\tInputs: Array<{Ticker: string; Amount: number}>;\n\tOutputs: Array<{Ticker: string; Amount: number}>;\n}\n\ninterface Price {\n\tMaterialTicker: string;\n\tPriceAverage: number;\n}\n\nasync function fetchData(): Promise<{recipes: Recipe[]; prices: Price[]}> {\n\tconst [recipesResponse, exchangesResponse] = await Promise.all([\n\t\tfetch('https://api.prunplanner.org/data/recipes'),\n\t\tfetch('https://api.prunplanner.org/data/exchanges'),\n\t]);\n\tconst [recipes, prices] = await Promise.all([\n\t\trecipesResponse.json(),\n\t\texchangesResponse.json(),\n\t]);\n\treturn {recipes, prices};\n}\n\nfunction render({recipes, prices}: {recipes: Recipe[], prices: Price[]}) {\n\tconst tbody = document.querySelector('tbody') as HTMLTableSectionElement;\n\tfor (const recipe of recipes) {\n\t\tif (recipe.BuildingTicker !== 'FRM')\n\t\t\tcontinue;\n\t\tconst row = document.createElement('tr');\n\t\trow.innerHTML = `\n\t\t\t<td>${recipe.RecipeName}</td>\n\t\t\t<td></td>\n\t\t`;\n\t\ttbody.appendChild(row);\n\t}\n}\n\nfetchData().then(render);\n"
   ],
-  "mappings": "",
-  "debugId": "7ACBF329D9352D3964756E2164756E21",
+  "mappings": ";AAcA,eAAe,SAAS,GAAkD;AAAA,EACzE,OAAO,iBAAiB,qBAAqB,MAAM,QAAQ,IAAI;AAAA,IAC9D,MAAM,0CAA0C;AAAA,IAChD,MAAM,4CAA4C;AAAA,EACnD,CAAC;AAAA,EACD,OAAO,SAAS,UAAU,MAAM,QAAQ,IAAI;AAAA,IAC3C,gBAAgB,KAAK;AAAA,IACrB,kBAAkB,KAAK;AAAA,EACxB,CAAC;AAAA,EACD,OAAO,EAAC,SAAS,OAAM;AAAA;AAGxB,SAAS,MAAM,GAAE,SAAS,UAA+C;AAAA,EACxE,MAAM,QAAQ,SAAS,cAAc,OAAO;AAAA,EAC5C,WAAW,UAAU,SAAS;AAAA,IAC7B,IAAI,OAAO,mBAAmB;AAAA,MAC7B;AAAA,IACD,MAAM,MAAM,SAAS,cAAc,IAAI;AAAA,IACvC,IAAI,YAAY;AAAA,SACT,OAAO;AAAA;AAAA;AAAA,IAGd,MAAM,YAAY,GAAG;AAAA,EACtB;AAAA;AAGD,UAAU,EAAE,KAAK,MAAM;",
+  "debugId": "87EA56A94163896264756E2164756E21",
   "names": []
 }

+ 11 - 1
index.html

@@ -7,7 +7,17 @@
 	<link rel="stylesheet" href="styles.css">
 </head>
 <body>
-	<main></main>
+	<main>
+		<table>
+			<thead>
+				<tr>
+					<th>recipe</th>
+					<th>daily cost</th>
+				</tr>
+			</thead>
+			<tbody></tbody>
+		</table>
+	</main>
 	<script type="module" src="./dist/main.js"></script>
 </body>
 </html>

+ 41 - 0
src/main.ts

@@ -0,0 +1,41 @@
+interface Recipe {
+	RecipeId: string;
+	BuildingTicker: string;
+	RecipeName: string;
+	TimeMs: number;
+	Inputs: Array<{Ticker: string; Amount: number}>;
+	Outputs: Array<{Ticker: string; Amount: number}>;
+}
+
+interface Price {
+	MaterialTicker: string;
+	PriceAverage: number;
+}
+
+async function fetchData(): Promise<{recipes: Recipe[]; prices: Price[]}> {
+	const [recipesResponse, exchangesResponse] = await Promise.all([
+		fetch('https://api.prunplanner.org/data/recipes'),
+		fetch('https://api.prunplanner.org/data/exchanges'),
+	]);
+	const [recipes, prices] = await Promise.all([
+		recipesResponse.json(),
+		exchangesResponse.json(),
+	]);
+	return {recipes, prices};
+}
+
+function render({recipes, prices}: {recipes: Recipe[], prices: Price[]}) {
+	const tbody = document.querySelector('tbody') as HTMLTableSectionElement;
+	for (const recipe of recipes) {
+		if (recipe.BuildingTicker !== 'FRM')
+			continue;
+		const row = document.createElement('tr');
+		row.innerHTML = `
+			<td>${recipe.RecipeName}</td>
+			<td></td>
+		`;
+		tbody.appendChild(row);
+	}
+}
+
+fetchData().then(render);