show latest blog post on coach page

pull/9756/head
Thibault Duplessis 2021-09-08 10:54:25 +02:00
parent 93cdf6be81
commit fcd3869da8
7 changed files with 48 additions and 21 deletions

View File

@ -33,15 +33,17 @@ final class Coach(env: Env) extends LilaController(env) {
Open { implicit ctx =>
OptionFuResult(api find username) { c =>
WithVisibleCoach(c) {
env.study.api.publicByIds {
c.coach.profile.studyIds.map(_.value).map(lila.study.Study.Id.apply)
} flatMap env.study.pager.withChaptersAndLiking(ctx.me, 4) flatMap { studies =>
api.reviews.approvedByCoach(c.coach) flatMap { reviews =>
ctx.me.?? { api.reviews.mine(_, c.coach) } map { myReview =>
lila.mon.coach.pageView.profile(c.coach.id.value).increment()
Ok(html.coach.show(c, reviews, studies, myReview))
}
for {
stu <- env.study.api.publicByIds {
c.coach.profile.studyIds.map(_.value).map(lila.study.Study.Id.apply)
}
studies <- env.study.pager.withChaptersAndLiking(ctx.me, 4)(stu)
posts <- env.ublog.api.latestPosts(lila.ublog.UblogBlog.Id.User(c.user.id), 4)
reviews <- api.reviews.approvedByCoach(c.coach)
myReview <- ctx.me.?? { api.reviews.mine(_, c.coach) }
} yield {
lila.mon.coach.pageView.profile(c.coach.id.value).increment()
Ok(html.coach.show(c, reviews, studies, posts, myReview))
}
}
}

View File

@ -15,7 +15,7 @@ object show {
private def section(title: Frag, text: Option[lila.coach.CoachProfile.RichText]) =
text.map { t =>
st.section(
h2(title),
h2(cls := "coach-show__title")(title),
div(cls := "content")(richText(t.value))
)
}
@ -24,6 +24,7 @@ object show {
c: lila.coach.Coach.WithUser,
coachReviews: lila.coach.CoachReview.Reviews,
studies: Seq[lila.study.Study.WithChaptersAndLiked],
posts: Seq[lila.ublog.UblogPost.PreviewPost],
myReview: Option[lila.coach.CoachReview]
)(implicit ctx: Context) = {
val profile = c.coach.profile
@ -73,8 +74,14 @@ object show {
section(bestSkills(), profile.skills),
section(teachingMethod(), profile.methodology)
),
posts.nonEmpty option st.section(cls := "coach-show__posts")(
h2(cls := "coach-show__title")(trans.ublog.latestBlogPosts()),
div(cls := "ublog-post-cards ")(
posts map { views.html.ublog.post.card(_, showAuthor = false) }
)
),
studies.nonEmpty option st.section(cls := "coach-show__studies")(
h2(publicStudies()),
h2(cls := "coach-show__title")(publicStudies()),
div(cls := "studies")(
studies.map { s =>
st.article(cls := "study")(study.bits.widget(s, h3))
@ -82,7 +89,7 @@ object show {
)
),
profile.youtubeUrls.nonEmpty option st.section(cls := "coach-show__youtube")(
h2(
h2(cls := "coach-show__title")(
profile.youtubeChannel.map { url =>
a(href := url, targetBlank, noFollow)(youtubeVideos())
} getOrElse youtubeVideos()

View File

@ -2269,6 +2269,7 @@ val `thisIsADraft` = new I18nKey("ublog:thisIsADraft")
val `moreBlogPostsBy` = new I18nKey("ublog:moreBlogPostsBy")
val `noPostsInThisBlogYet` = new I18nKey("ublog:noPostsInThisBlogYet")
val `noDrafts` = new I18nKey("ublog:noDrafts")
val `latestBlogPosts` = new I18nKey("ublog:latestBlogPosts")
val `publishedNbBlogPosts` = new I18nKey("ublog:publishedNbBlogPosts")
val `nbViews` = new I18nKey("ublog:nbViews")
}

View File

@ -63,12 +63,19 @@ final class UblogApi(
def findByIdAndBlog(id: UblogPost.Id, blog: UblogBlog.Id): Fu[Option[UblogPost]] =
colls.post.one[UblogPost]($id(id) ++ $doc("blog" -> blog))
def otherPosts(blog: UblogBlog.Id, post: UblogPost): Fu[List[UblogPost.PreviewPost]] =
def latestPosts(blog: UblogBlog.Id, nb: Int): Fu[List[UblogPost.PreviewPost]] =
colls.post
.find($doc("blog" -> blog, "live" -> true), previewPostProjection.some)
.sort($doc("lived.at" -> -1))
.cursor[UblogPost.PreviewPost]()
.list(nb)
def otherPosts(blog: UblogBlog.Id, post: UblogPost, nb: Int = 4): Fu[List[UblogPost.PreviewPost]] =
colls.post
.find($doc("blog" -> blog, "live" -> true, "_id" $ne post.id), previewPostProjection.some)
.sort($doc("live.at" -> -1))
.sort($doc("lived.at" -> -1))
.cursor[UblogPost.PreviewPost]()
.list(4)
.list(nb)
def countLiveByBlog(blog: UblogBlog.Id): Fu[Int] =
colls.post.countSel($doc("blog" -> blog, "live" -> true))

View File

@ -24,4 +24,5 @@
<string name="moreBlogPostsBy">More blog posts by %s</string>
<string name="noPostsInThisBlogYet">No posts in this blog, yet.</string>
<string name="noDrafts">No drafts to show.</string>
<string name="latestBlogPosts">Latest blog posts</string>
</resources>

View File

@ -1,4 +1,5 @@
@import '../../../common/css/plugin';
@import '../../../common/css/component/mselect';
@import '../../../analyse/css/study/list-widget';
@import '../ublog/card';
@import '../coach/coach';

View File

@ -36,10 +36,10 @@
}
}
h2 {
margin: 0 0 12px 0;
&__title {
margin: 0 0 1rem 0;
color: $c-brag;
font-size: 1.6em;
font-size: 1.8rem;
}
&__youtube {
@ -62,15 +62,23 @@
}
}
&__studies {
margin-top: 20px;
&__studies,
&__posts {
margin-top: 2em;
.coach-show__title {
padding: 1em var(--box-padding);
}
}
&__studies {
.studies {
border-top: $border;
}
}
h2 {
padding: 1em 0 0 2em;
&__posts {
.ublog-post-cards {
margin: 0 var(--box-padding);
}
}
}