- fetchProblems: function(direction) {
- return; //TODO: re-activate after server side is implemented (see routes/all.js)
- if (this.problems.length == 0)
- return; //what could we do?!
- // Search for newest date (or oldest)
- let last_dt = this.problems[0].added;
- for (let i=0; i<this.problems.length; i++)
+ firstFetch: function() {
+ // Fetch most recent problems from server, for both lists
+ this.fetchProblems("others", "bacwkard");
+ this.fetchProblems("mine", "bacwkard");
+ this.listsInitialized = true;
+ },
+ showProblem: function(num) {
+ const pid = num || this.pbNum;
+ location.hash = "#" + pid;
+ const pIdx = this.singletons.findIndex(p => p.id == pid);
+ if (pIdx >= 0)
+ curProb = this.singletons[pIdx];
+ else
+ {
+ // Cannot find problem in current set; get from server, and add to singletons.
+ ajax(
+ "/problems/" + variant.name + "/" + pid, //TODO: use variant._id ?
+ "GET",
+ response => {
+ if (!!response.problem)
+ {
+ this.singletons.push(response.problem);
+ this.curProb = response.problem;
+ }
+ else
+ this.noMoreProblems("Sorry, problem " + pid + " does not exist");
+ }
+ );
+ }
+ },
+ translate: function(text) {
+ return translations[text];
+ },
+ curProblems: function() {
+ switch (this.display)
+ {
+ case "others":
+ return this.problems;
+ case "mine":
+ return this.myProblems;
+ }
+ },
+ // TODO?: get 50 from server but only show 10 at a time (for example)
+ showNext: function(direction) {
+ if (!this.curProb)
+ return this.fetchProblems(this.display, direction);
+ // Show next problem (older or newer):
+ let curProbs = this.curProblems();
+ // Try to find a neighbour problem in the direction, among current set
+ const neighbor = this.findClosestNeighbor(this.curProb, curProbs, direction);
+ if (!!neighbor)