+ setCurIndex: function(idx) {
+ this.curIdx = idx;
+ location.hash = "#" + idx;
+ },
+ translate: function(text) {
+ return translations[text];
+ },
+ curProblems: function() {
+ switch (this.display)
+ {
+ case "list":
+ return this.problems;
+ case "myList":
+ return this.myProblems;
+ }
+ },
+ // TODO?: get 50 from server but only show 10 at a time (for example)
+ showNext: function(direction) {
+ if (this.curIdx < 0)
+ return this.fetchProblems(direction);
+ // Show next problem (older or newer):
+ let curProbs = this.curProblems();
+ if ((this.curIdx > 0 && direction=="backward")
+ || (this.curIdx < curProbs.length-1 && direction=="forward"))
+ {
+ this.setCurIdx(this.curIdx + (direction=="forward" ? 1 : -1));
+ }
+ else //at boundary
+ {
+ const curSize = curProbs.length;
+ this.fetchProblems(direction);
+ const newSize = curProbs.length;
+ if (curSize == newSize) //no problems found
+ return;
+ switch (direction)
+ {
+ case "forward":
+ this.setCurIdx(this.curIdx+1);
+ break;
+ case "backward":
+ this.setCurIdx(newSize - curSize + this.curIdx-1);
+ break;
+ }
+ }
+ },
+ toggleListDisplay: function() {
+ this.display = (this.display == "list" ? "myList" : "list");
+ },
+ // TODO: modal "there are no more problems"