Skip to content

Commit

Permalink
persistent challenges wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jan 31, 2016
1 parent 03c1b00 commit 6ca40a9
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
13 changes: 9 additions & 4 deletions app/controllers/Challenge.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ object Challenge extends LilaController {

def all = Auth { implicit ctx =>
me =>
env.api.findByDestId(me.id) zip
env.api.findByChallengerId(me.id) map {
case (out, in) => Ok(env.jsonView.all(in, out)) as JSON
}
renderAll(me)
}

private[controllers] def renderAll(me: lila.user.User)(implicit ctx: Context) =
env.api.findByDestId(me.id) zip
env.api.findByChallengerId(me.id) map {
case (out, in) => Ok(env.jsonView.all(in, out)) as JSON
}
private[controllers] def renderOne(challenge: ChallengeModel)(implicit ctx: Context) =
Ok(env.jsonView.one(challenge)) as JSON

private[controllers] def reach(id: String)(implicit ctx: Context): Fu[Result] =
env.api byId id flatMap {
case None => notFound
Expand Down
8 changes: 5 additions & 3 deletions app/controllers/Setup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ object Setup extends LilaController with TheftPrevention {
challenger = ctx.me,
destUserId = userId)
(Env.challenge.api insert challenge) >> negotiate(
html = fuccess(Redirect(routes.Challenge.all)),
api = apiVersion => ??? // TODO fix me!
)
html = fuccess(Redirect(routes.Round.watcher(challenge.id, "white"))),
api = _ => ctx.me match {
case None => Challenge.renderOne(challenge).fuccess
case Some(me) => Challenge.renderAll(me)
})
}
)
}
Expand Down
2 changes: 2 additions & 0 deletions modules/challenge/src/main/JsonView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ final class JsonView(getLightUser: String => Option[lila.common.LightUser]) {
"in" -> in.map(apply),
"out" -> out.map(apply))

def one(challenge: Challenge) = Json.obj("out" -> List(apply(challenge)))

def apply(c: Challenge) = Json.obj(
"id" -> c.id,
"challenger" -> c.challenger.right.toOption.map { u =>
Expand Down
2 changes: 1 addition & 1 deletion ui/challenge/src/ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function(env) {
this.vm.reloading = false;
}.bind(this);

xhr.load();
xhr.load().then(this.update);

this.trans = lichess.trans(env.i18n);
};
2 changes: 1 addition & 1 deletion ui/challenge/src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function user(u) {
},
children: [
fullName,
m('span.progress', [rating, ratingDiff])
m('span.progress', rating)
]
};
}
Expand Down
2 changes: 1 addition & 1 deletion ui/challenge/src/xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ module.exports = {
method: 'GET',
url: uncache('/challenge'),
config: xhrConfig,
}).then(ctrl.update);
});
}
};

0 comments on commit 6ca40a9

Please sign in to comment.