Skip to content

Commit

Permalink
organize library selector
Browse files Browse the repository at this point in the history
  • Loading branch information
advaith1 committed Feb 22, 2025
1 parent 72b2722 commit 027fa5d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/Routes/bots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ router.get(
subtitle: res.__("common.nav.me.submitBot.subtitle"),
showResubmitNote,
libraries: libraryCache.getLibs(),
languages: libraryCache.getLanguages(),
req,
joinServerNotice: res.__("common.form.joinServer.full", {
a: '<a href="https://discord.gg/WeCer3J" rel="noopener" target="_blank">',
Expand Down Expand Up @@ -1139,6 +1140,7 @@ router.get(
title: res.__("page.bots.edit.title"),
subtitle: res.__("page.bots.edit.subtitle", botExists.name),
libraries: libraryCache.getLibs(),
languages: libraryCache.getLanguages(),
settings,
bot: botExists,
editors: botExists.editors ? botExists.editors.join(" ") : "",
Expand Down Expand Up @@ -2552,6 +2554,7 @@ router.get(
title: res.__("page.bots.resubmit.title"),
subtitle: res.__("page.bots.resubmit.subtitle", botExists.name),
libraries: libraryCache.getLibs(),
languages: libraryCache.getLanguages(),
settings,
bot: botExists,
editors: botExists.editors ? botExists.editors.join(" ") : "",
Expand Down
4 changes: 4 additions & 0 deletions src/Util/Services/libCaching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export function getLibs() {
return global.libs?.sort((a, b) => a._id.localeCompare(b._id));
}

export function getLanguages() {
return new Set(global.libs?.map(l => l.language).sort());
}

export function hasLib(name: string) {
return global.libs?.find((x) => x._id === name);
}
Expand Down
14 changes: 11 additions & 3 deletions views/templates/bots/edit.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,17 @@
<div class="control has-icons-left">
<div class="select is-rounded">
<select id="form_library" name="library" required>
<option value="" disabled selected><%= __("common.select") %></option>
<option value="<%= bot.library %>" selected><%= bot.library %></option>
<% for (const lib of libraries) { %><option value="<%- lib._id %>"><%- lib._id %></option><% } %>
<% if (!libraries.some(lib => lib._id === bot.library)) { %>
<option value="<%= bot.library %>" selected><%= bot.library %></option>
<hr>
<% } %>
<% for (const lang of languages) { %>
<optgroup label="<%= lang %>">
<% for (const lib of libraries.filter(l => l.language === lang)) { %>
<option value="<%= lib._id %>" <% if (lib._id === bot.library) { %>selected<% } %>><%= lib._id %></option>
<% } %>
</optgroup>
<% } %>
</select>
</div>
<div class="icon is-small is-left">
Expand Down
9 changes: 8 additions & 1 deletion views/templates/bots/submit.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,14 @@
<div class="select is-rounded">
<select id="form_library" name="library" required>
<option value="" disabled selected><%= __("common.select") %></option>
<% for (const lib of libraries) { %><option value="<%- lib._id %>"><%- lib._id %></option><% } %>
<hr>
<% for (const lang of languages) { %>
<optgroup label="<%= lang %>">
<% for (const lib of libraries.filter(l => l.language === lang)) { %>
<option value="<%= lib._id %>"><%= lib._id %></option>
<% } %>
</optgroup>
<% } %>
</select>
</div>
<div class="icon is-small is-left">
Expand Down

0 comments on commit 027fa5d

Please sign in to comment.