Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing styling issue with friends list and opponents #15560 #15562

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
59 changes: 36 additions & 23 deletions app/controllers/Relation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,34 @@ final class Relation(env: Env, apiC: => Api) extends LilaController(env):

val api = env.relation.api

private def renderActions(username: UserName, mini: Boolean)(using ctx: Context) = for
user <- env.user.lightUserApi.asyncFallbackName(username)
relation <- ctx.userId.so(api.fetchRelation(_, user.id))
followable <- ctx.isAuth.so(env.pref.api.followable(user.id))
blocked <- ctx.userId.so(api.fetchBlocks(user.id, _))
res <- negotiate(
Ok.snip:
if mini
then views.relation.mini(user.id, blocked = blocked, followable = followable, relation)
else views.relation.actions(user, relation, blocked = blocked, followable = followable)
,
Ok:
Json.obj(
"followable" -> followable,
"following" -> relation.contains(true),
"blocking" -> relation.contains(false)
)
)
yield res
private def renderActions(username: UserName, mini: Boolean, showText: Boolean = true)(using ctx: Context) =
for
user <- env.user.lightUserApi.asyncFallbackName(username)
relation <- ctx.userId.so(api.fetchRelation(_, user.id))
followable <- ctx.isAuth.so(env.pref.api.followable(user.id))
blocked <- ctx.userId.so(api.fetchBlocks(user.id, _))
res <- negotiate(
Ok.snip:
if mini
then views.relation.mini(user.id, blocked = blocked, followable = followable, relation)
else
views.relation.actions(
user,
relation,
blocked = blocked,
followable = followable,
signup = false,
showText = showText
)
,
Ok:
Json.obj(
"followable" -> followable,
"following" -> relation.contains(true),
"blocking" -> relation.contains(false)
)
)
yield res

private def RatelimitWith(
str: UserStr
Expand All @@ -51,7 +60,7 @@ final class Relation(env: Env, apiC: => Api) extends LilaController(env):
env.msg.api.postPreset(me, msg) >> rateLimited(msg.name)
else
api.follow(me, user.id).recoverDefault >> negotiate(
renderActions(user.name, getBool("mini")),
renderActions(user.name, getBool("mini"), getBool("showText")),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?? Why is showText read from the HTTP request query parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my initial fix I had not realised that when toggling e.g. follow/unfollow the text captions would re-appear as logic at runtime would not have the info if presented for paginated results or single user. Looking at the approach done for mini layout of the relation UI, I copied that approach.

Perhaps I could also attempt fixing this via introducing some additional routes?
e.g (/api/rel/follow/${user}/partial)

jsonOkResult
)
}
Expand All @@ -61,20 +70,24 @@ final class Relation(env: Env, apiC: => Api) extends LilaController(env):
def unfollow(username: UserStr) = AuthOrScoped(_.Follow.Write, _.Web.Mobile) { ctx ?=> me ?=>
RatelimitWith(username): user =>
api.unfollow(me, user.id).recoverDefault >> negotiate(
renderActions(user.name, getBool("mini")),
renderActions(user.name, getBool("mini"), getBool("showText")),
jsonOkResult
)
}
def unfollowBc = unfollow

def block(username: UserStr) = AuthOrScoped(_.Follow.Write, _.Web.Mobile) { ctx ?=> me ?=>
RatelimitWith(username): user =>
api.block(me, user.id).recoverDefault >> renderActions(user.name, getBool("mini"))
api.block(me, user.id).recoverDefault >> renderActions(user.name, getBool("mini"), getBool("showText"))
}

def unblock(username: UserStr) = AuthOrScoped(_.Follow.Write, _.Web.Mobile) { ctx ?=> me ?=>
RatelimitWith(username): user =>
api.unblock(me, user.id).recoverDefault >> renderActions(user.name, getBool("mini"))
api.unblock(me, user.id).recoverDefault >> renderActions(
user.name,
getBool("mini"),
getBool("showText")
)
}

def following(username: UserStr, page: Int) = Open:
Expand Down
36 changes: 23 additions & 13 deletions modules/relation/src/main/ui/RelationUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ final class RelationUi(helpers: Helpers):
relation: Option[Relation],
followable: Boolean,
blocked: Boolean,
signup: Boolean = false
signup: Boolean = false,
showText: Boolean = true
)(using ctx: Context) =
val blocks = relation.contains(Relation.Block)
div(cls := "relation-actions")(
Expand All @@ -58,7 +59,7 @@ final class RelationUi(helpers: Helpers):
cls := "text",
href := s"${routes.Lobby.home}?user=${user.name}#friend",
dataIcon := Icon.Swords
)(trans.challenge.challengeToPlay.txt())
)(showText.option(trans.challenge.challengeToPlay.txt()))
),
ctx.userId
.map: myId =>
Expand All @@ -70,43 +71,43 @@ final class RelationUi(helpers: Helpers):
cls := "text",
href := routes.Msg.convo(user.name),
dataIcon := Icon.BubbleSpeech
)(trans.site.composeMessage.txt())
)(showText.option(showText.option(trans.site.composeMessage.txt())))
),
(!blocked && !blocks && !user.isPatron).option(
a(
cls := "text",
href := s"${routes.Plan.list}?dest=gift&giftUsername=${user.name}",
dataIcon := Icon.Wings
)(trans.patron.giftPatronWingsShort.txt())
)(showText.option(trans.patron.giftPatronWingsShort.txt()))
),
relation match
case None =>
frag(
(followable && !blocked).option(
a(
cls := "text relation-button",
href := routes.Relation.follow(user.name),
href := s"${routes.Relation.follow(user.name)}?showText=${showText}",
dataIcon := Icon.ThumbsUp
)(trans.site.follow.txt())
)(showText.option(trans.site.follow.txt()))
),
a(
cls := "text relation-button",
href := routes.Relation.block(user.name),
href := s"${routes.Relation.block(user.name)}?showText=${showText}",
dataIcon := Icon.NotAllowed
)(trans.site.block.txt())
)(showText.option(trans.site.block.txt()))
)
case Some(Relation.Follow) =>
a(
cls := "text relation-button",
href := routes.Relation.unfollow(user.name),
href := s"${routes.Relation.unfollow(user.name)}?showText=${showText}",
dataIcon := Icon.ThumbsUp
)(trans.site.unfollow.txt())
)(showText.option(trans.site.unfollow.txt()))
case Some(Relation.Block) =>
a(
cls := "text relation-button",
href := routes.Relation.unblock(user.name),
href := s"${routes.Relation.unblock(user.name)}?showText=${showText}",
dataIcon := Icon.NotAllowed
)(trans.site.unblock.txt())
)(showText.option(trans.site.unblock.txt()))
)
)
.getOrElse:
Expand Down Expand Up @@ -193,7 +194,16 @@ final class RelationUi(helpers: Helpers):
td(r.user.seenAt.map: seen =>
trans.site.lastSeenActive(momentFromNow(seen))),
withActions.option:
td(actions(r.user.light, relation = r.relation, followable = r.followable, blocked = false))
td(
actions(
r.user.light,
relation = r.relation,
followable = r.followable,
blocked = false,
signup = false,
showText = false
)
)
),
pagerNextTable(pager, np => addQueryParam(call.url, "page", np.toString))
)
Expand Down