- ajax("/problems", "GET", res => {
- // Show newest problem first:
- this.problems = res.problems.sort((p1, p2) => p2.added - p1.added);
- if (this.st.variants.length > 0)
- this.problems.forEach(p => this.setVname(p));
- // Retrieve all problems' authors' names
- let names = {};
- this.problems.forEach(p => {
- if (p.uid != this.st.user.id) names[p.uid] = "";
- //unknwon for now
- else p.uname = this.st.user.name;
- });
- const showOneIfPid = () => {
- const pid = this.$route.query["id"];
- if (pid) this.showProblem(this.problems.find(p => p.id == pid));
- };
- if (Object.keys(names).length > 0) {
- ajax("/users", "GET", { ids: Object.keys(names).join(",") }, res2 => {
- res2.users.forEach(u => {
- names[u.id] = u.name;
- });
- this.problems.forEach(p => (p.uname = names[p.uid]));
- showOneIfPid();
- });
- } else showOneIfPid();
- });
+ ajax(
+ "/problems",
+ "GET",
+ {
+ data: { cursor: this.cursor },
+ success: (res) => {
+ // The returned list is sorted from most recent to oldest
+ this.problems = res.problems;
+ const L = res.problems.length;
+ if (L > 0) this.cursor = res.problems[L - 1].added;
+ else this.hasMore = false;
+ const showOneIfPid = () => {
+ const pid = this.$route.query["id"];
+ if (!!pid) this.showProblem(this.problems.find(p => p.id == pid));
+ };
+ this.decorate(this.problems, showOneIfPid);
+ }
+ }
+ );