Skip to content

Commit

Permalink
improve version picker
Browse files Browse the repository at this point in the history
dynamically fetch releases on Github and populate dropdown list
  • Loading branch information
andreasbrett authored Dec 26, 2024
1 parent e5f5c59 commit 01944af
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ <h1>Install Voice PE Latest Firmware</h1>
<br />
<details>
<summary>Install Specific Version</summary>
Version: <input /><br />
Select a Release: <select id="releases"></select><br />
<div class="link"></div>
</details>
<script>
Expand All @@ -76,11 +76,45 @@ <h1>Install Voice PE Latest Firmware</h1>
".link",
).innerHTML = `<a href="?version=${version}">Link to v${version}</a>`;
}

const fetchAndSetReleases = async () => {
try {
const response = await fetch("https://api.github.com/repos/esphome/home-assistant-voice-pe/releases");

document.querySelector("input").addEventListener("input", (ev) => {
if (!response.ok) {
throw new Error(`Error fetching releases: ${response.statusText}`);
}

const releases = await response.json();
const versions = releases.map(release => release.tag_name);

const e = document.getElementById("releases");
e.innerHTML = "";

const defaultOption = document.createElement("option");
defaultOption.text = "-- select version --";
defaultOption.value = "";
e.appendChild(defaultOption);

versions.forEach(version => {
const option = document.createElement("option");
option.text = version;
option.value = version;
e.appendChild(option);
});

} catch (error) {
console.error("Error:", error);
}
};

document.querySelector("#releases").addEventListener("change", (ev) => {
const version = ev.target.value;
setVersion(version);
});

fetchAndSetReleases();

var urlParams = new URLSearchParams(window.location.search);
if (urlParams.has("version")) {
const version = urlParams.get("version");
Expand Down

0 comments on commit 01944af

Please sign in to comment.