Skip to content

Commit

Permalink
Support starring formats
Browse files Browse the repository at this point in the history
  • Loading branch information
mia-pi-git committed Oct 25, 2023
1 parent 24d4229 commit ae55432
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 13 deletions.
69 changes: 56 additions & 13 deletions js/client-mainmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -1225,8 +1225,9 @@

var FormatPopup = this.FormatPopup = this.Popup.extend({
events: {
'keyup input': 'updateSearch',
'keyup input[name=search]': 'updateSearch',
'click details': 'updateOpen',
'click i.fa': 'updateStar',
},
initialize: function (data) {
this.data = data;
Expand All @@ -1239,10 +1240,14 @@
"Other Metagames": true, "Randomized Format Spotlight": true, "RoA Spotlight": true,
};
}
if (!this.starred) this.starred = Storage.prefs('starredformats') || {};
if (!this.search) this.search = "";
this.onselect = data.onselect;
this.selectType = data.selectType;
if (!this.selectType) this.selectType = (this.sourceEl.closest('form').data('search') ? 'search' : 'challenge');

var html = '<p><ul class="popupmenu"><li><input placeholder="Search formats" value="' + this.search + '"/>';

var html = '<p><ul class="popupmenu"><li><input name="search" placeholder="Search formats" value="' + this.search + '"/>';
html += '</li></ul></p><span name="formats">';
html += this.renderFormats();
html += '</span><div style="clear:left"></div><p></p>';
Expand All @@ -1251,25 +1256,38 @@
renderFormats: function () {
var data = this.data;
var curFormat = data.format;
var selectType = data.selectType;
if (!selectType) selectType = (this.sourceEl.closest('form').data('search') ? 'search' : 'challenge');

var bufs = [];
var curBuf = 0;
if (selectType === 'watch' && !this.search) {
if (this.selectType === 'watch' && !this.search) {
bufs[1] = '<li><button name="selectFormat" value=""' + (curFormat === '' ? ' class="sel"' : '') + '>(All formats)</button></li>';
}

for (var i in this.starred) {
if (!bufs[1]) bufs[1] = '';
var format = BattleFormats[i];
if (!format) {
delete this.starred[i];

This comment has been minimized.

Copy link
@urkerab

urkerab Oct 25, 2023

Contributor

Unfortunately stars are global, not per-server, so this prevents me from starring a custom format on a side server, as that will unstar all the formats I had starred that aren't available on that side server, plus any custom formats I do star on a side server will become unstarred as soon as I star a format on another server.

continue;
}
if (!this.shouldDisplayFormat(format)) continue;
if (this.search && !i.includes(toID(this.search))) {
continue;
}
// <i class="fa fa-star"></i>
var formatName = BattleLog.escapeFormat(BattleFormats[i].id);
bufs[1] += (
'<li><button name="selectFormat" value="' + i +
'"' + (curFormat === i ? ' class="sel"' : '') + '>' + formatName +
'<i class="fa fa-star" style="float: right; color: #FFD700; text-shadow: 0 0 1px #000;"></i></button></li>'
);
}

var curSection = '';
for (var i in BattleFormats) {
var format = BattleFormats[i];
if (selectType === 'teambuilder') {
if (!format.isTeambuilderFormat) continue;
} else {
if (format.effectType !== 'Format' || format.battleFormat) continue;
if (selectType != 'watch' && !format[selectType + 'Show']) continue;
}
if (!this.shouldDisplayFormat(format)) continue;
if (this.search && !format.id.includes(toID(this.search))) continue;
if (this.starred[i]) continue; // only show it in the starred section

if (format.section && format.section !== curSection) {
if (curSection) bufs[curBuf] += '</details></p>';
Expand All @@ -1293,7 +1311,11 @@
formatName = formatName.replace('[Gen 9 ', '[');
formatName = formatName.replace('[Gen 8 ', '[');
formatName = formatName.replace('[Gen 7 ', '[');
bufs[curBuf] += '<li><button name="selectFormat" value="' + i + '"' + (curFormat === i ? ' class="sel"' : '') + '>' + formatName + '</button></li>';
bufs[curBuf] += (
'<li><button name="selectFormat" value="' + i +
'"' + (curFormat === i ? ' class="sel"' : '') + '>' + formatName +
'<i class="fa fa-star subtle" style="float: right;"></i></button></li>'
);
}
var html = '';
if (!bufs.length) {
Expand All @@ -1319,6 +1341,18 @@
$formatEl.empty();
$formatEl.html(this.renderFormats());
},
updateStar: function (ev) {
ev.preventDefault();
ev.stopPropagation();
var format = $(ev.target).parent().attr('value');
if (this.starred[format]) {
delete this.starred[format];
} else {
this.starred[format] = true;
}
Storage.prefs('starredformats', this.starred);
this.update();
},
updateOpen: function (ev) {
var section = $(ev.currentTarget).attr('section');
this.open[section] = !this.open[section];
Expand All @@ -1328,6 +1362,15 @@
this.search = $(event.currentTarget).val();
this.update();
},
shouldDisplayFormat: function (format) {
if (this.selectType === 'teambuilder') {
if (!format.isTeambuilderFormat) return false;
} else {
if (format.effectType !== 'Format' || format.battleFormat) return false;
if (this.selectType != 'watch' && !format[this.selectType + 'Show']) return false;
}
return true;
},
selectFormat: function (format) {
if (this.onselect) {
this.onselect(format);
Expand Down
11 changes: 11 additions & 0 deletions style/client.css
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,17 @@ select {
content: "\f0e6";
}

i.subtle {
opacity: 0.25;
filter: alpha(opacity=25);
}

i.subtle:hover {
opacity: 1.0;
filter: alpha(opacity=100);
}


.tabbar li,
.tabbar ul {
display: block;
Expand Down

0 comments on commit ae55432

Please sign in to comment.