Skip to content

Commit 033eb43

Browse files
Implement search functionality in mod dashboard and update script type to module
1 parent fa816b8 commit 033eb43

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

ui/chrome/js/moddashboard.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
document.getElementById("search").addEventListener("click", async function() {
2+
let search = document.getElementById("searchText").value;
3+
let searchUrl = "https://mc-backend-six.vercel.app/api/search?q=" + encodeURIComponent(search)
4+
const searchResult = await fetch(searchUrl)
5+
const data = await searchResult.json()
6+
let result = data.hits
7+
let resultDiv = document.getElementById("result")
8+
resultDiv.innerHTML = ""
9+
for (var i = 0; i < result.length; i++) {
10+
let project = result[i]
11+
let projectDiv = document.createElement("div")
12+
projectDiv.className = "project"
13+
projectDiv.innerHTML = `
14+
<img src="${project.icon_url}" alt="${project.title}">
15+
<h3>${project.title}</h3>
16+
<p>${project.description}</p>
17+
<p>Downloads: ${project.downloads}</p>
18+
<p>Follows: ${project.follows}</p>
19+
<a href="https://modrinth.com/${project.project_type}/${project.slug}" target="_blank">View on Modrinth</a>
20+
`
21+
resultDiv.appendChild(projectDiv)
22+
}
23+
});

ui/chrome/moddashboard/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ <h2>Mod Details</h2>
2424
</div>
2525
</section>
2626
</main>
27-
<script src="../js/moddashboard.js" defer></script>
27+
<script src="../js/moddashboard.js" defer type="module"></script>
2828
</html>

0 commit comments

Comments
 (0)