+ noMoreProblems: function(message) {
+ this.nomoreMessage = message;
+ let modalNomore = document.getElementById("modalNomore");
+ modalNomore.checked = true;
+ setTimeout(() => modalNomore.checked = false, 2000);
+ },
+ displayList: function() {
+ this.curProb = null;
+ location.hash = "";
+ // Fetch problems if first call (if #num, and then lists)
+ if (!this.listsInitialized)
+ this.firstFetch();
+ },
+ toggleListDisplay: function() {
+ this.display = (this.display == "others" ? "mine" : "others");
+ },
+ fetchProblems: function(type, direction) {
+ let problems = (type == "others" ? this.problems : this.myProblems);
+ let last_dt = (direction=="forward" ? 0 : Number.MAX_SAFE_INTEGER);
+ if (this.problems.length > 0)
+ {
+ // Search for newest date (or oldest)
+ last_dt = problems[0].added;
+ for (let i=1; i<problems.length; i++)
+ {
+ if ((direction == "forward" && this.problems[i].added > last_dt) ||
+ (direction == "backward" && this.problems[i].added < last_dt))
+ {
+ last_dt = this.problems[i].added;
+ }
+ }
+ }
+ ajax(
+ "/problems/" + variant.name, //TODO: use variant._id ?
+ "GET",
+ {
+ type: type,
+ direction: direction,
+ last_dt: last_dt,
+ },
+ response => {
+ if (response.problems.length > 0)
+ {
+ Array.prototype.push.apply(problems,
+ response.problems.sort((p1,p2) => { return p1.added - p2.added; }));
+ // If one list is empty but not the other, show the non-empty
+ const otherArray = (type == "mine" ? this.problems : this.myProblems);
+ if (problems.length > 0 && otherArray.length == 0)
+ this.display = type;
+ }
+ }
+ );