Skip to content

Commit

Permalink
Use the GET /v3/recipes/ route to retrieve recipes.
Browse files Browse the repository at this point in the history
  • Loading branch information
caarmen committed Sep 26, 2024
1 parent 11154be commit 000a27e
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions example/geny-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ const stopInstance = async () => {
// Fetch recipe and add them to the select
const fetchRecipes = async () => {
try {
const response = await fetch(baseUrlToFetch + `/v1/recipes?limit=1000`, {
const response = await fetch(baseUrlToFetch + `/v3/recipes/?limit=1000`, {
...requestInit,
method: 'GET',
});
const recipes = await response.json();
const recipesResult = await response.json();

if (response.status !== 200) {
alert(recipes.message);
alert(recipesResult.message);
return;
}

Expand All @@ -166,30 +166,20 @@ const fetchRecipes = async () => {
placeholderOption.disabled = true;
placeholderOption.selected = true;
selectElement.add(placeholderOption, selectElement.firstChild);

for (const recipeType in recipes) {
addOptionsToGroup(recipeType, recipes[recipeType]);
const recipes = recipesResult.results;

for (let i = 0; i < recipes.length; i++) {
const recipe = recipes[i];
const optionElement = document.createElement('option');
optionElement.value = recipe.uuid;
optionElement.textContent = recipe.name;
selectElement.appendChild(optionElement);
}
} catch (error) {
alert(error);
}
};

const addOptionsToGroup = (recipeType, recipes) => {
const selectElement = document.querySelector('#listRecipes');

const optgroup = document.createElement('optgroup');
optgroup.label = recipeType;

recipes.forEach((recipe) => {
const optionElement = document.createElement('option');
optionElement.value = recipe.uuid;
optionElement.textContent = recipe.name;
optgroup.appendChild(optionElement);
});

selectElement.appendChild(optgroup);
};

// connect to an existing instance through an instance Uuid or an instance ws address
const connectInstance = async (wsAddress) => {
Expand Down

0 comments on commit 000a27e

Please sign in to comment.