Skip to content

Commit

Permalink
mod timeline reports UI wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Oct 26, 2024
1 parent 6eaf729 commit 9dba181
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
17 changes: 7 additions & 10 deletions modules/api/src/main/ModTimeline.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ case class ModTimeline(
import ModTimeline.{ *, given }

lazy val all: List[Event] =
val reportEvents: List[Event] = reports.flatMap: r =>
r.done.map(ReportClose(r, _)).toList ::: reportAtoms(r)
val reportEvents: List[Event] = reports.flatMap(reportAtoms)
val appealMsgs: List[Event] = appeal.so: a =>
a.msgs.toList.takeWhile: msg =>
a.mutedSince.fold(true)(msg.at.isBefore)
Expand All @@ -37,11 +36,11 @@ case class ModTimeline(

object ModTimeline:

case class ReportNewAtom(report: Report, atoms: NonEmptyList[Report.Atom])
case class ReportClose(report: Report, done: Report.Done)
case class ReportNewAtom(report: Report, atoms: NonEmptyList[Report.Atom]):
def like(r: Report): Boolean = report.room == r.room
case class PlayBans(list: NonEmptyList[TempBan])

type Event = Modlog | AppealMsg | Note | ReportNewAtom | ReportClose | PlayBans | PublicLine
type Event = Modlog | AppealMsg | Note | ReportNewAtom | PlayBans | PublicLine

def aggregateEvents(events: List[Event]): List[Event] =
events.foldLeft(List.empty[Event])(mergeMany)
Expand All @@ -54,7 +53,9 @@ object ModTimeline:
case (p: PublicLine, n: PublicLine) => PublicLine.merge(p, n)
case (p: PlayBans, n: PlayBans) => PlayBans(p.list ::: n.list).some
case (p: AppealMsg, n: AppealMsg) if p.by.is(n.by) => p.copy(text = s"${n.text}\n\n${p.text}").some
case _ => none
case (p: ReportNewAtom, n: ReportNewAtom) if n.like(p.report) =>
p.copy(atoms = n.atoms ::: p.atoms).some
case _ => none

private def reportAtoms(report: Report): List[ReportNewAtom | PublicLine] =
report.atoms
Expand All @@ -72,7 +73,6 @@ object ModTimeline:
case _: AppealMsg => "appeal"
case _: Note => "note"
case _: ReportNewAtom => "report-new"
case _: ReportClose => "report-close"
case _: PlayBans => "playban"
case _: PublicLine => "flagged-line"
def flair: Flair = Flair:
Expand All @@ -89,15 +89,13 @@ object ModTimeline:
case _: AppealMsg => "symbols.left-speech-bubble"
case _: Note => "objects.label"
case _: ReportNewAtom => "symbols.exclamation-mark"
case _: ReportClose => "objects.package"
case _: PlayBans => "objects.hourglass-not-done"
case _: PublicLine => "symbols.exclamation-mark"
def at: Instant = e match
case e: Modlog => e.date
case e: AppealMsg => e.at
case e: Note => e.date
case ReportNewAtom(_, atoms) => atoms.head.at
case ReportClose(_, done) => done.at
case e: PlayBans => e.list.head.date
case e: PublicLine => e.date
def url(u: User): String = e match
Expand All @@ -112,7 +110,6 @@ object ModTimeline:
object Angle:
def filter(e: Event)(using angle: Angle): Boolean = e match
case _: PlayBans => angle != Angle.Comm
case _: ReportClose => angle != Angle.Comm
case l: Modlog if l.action == Modlog.chatTimeout && angle != Angle.Comm => false
case l: Modlog if l.action == Modlog.modMessage =>
angle match
Expand Down
16 changes: 7 additions & 9 deletions modules/api/src/main/ui/ModTimelineUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ final class ModTimelineUi(helpers: Helpers)(
case e: AppealMsg => renderAppeal(t)(e)
case e: Note => renderNote(e)
case e: ReportNewAtom => renderReportNew(e)
case e: ReportClose => renderReportClose(e)
case e: PlayBans => renderPlayBans(e)
case e: PublicLine => renderPublicLine(e)

Expand Down Expand Up @@ -102,7 +101,7 @@ final class ModTimelineUi(helpers: Helpers)(
private def renderReportNew(r: ReportNewAtom)(using Translate) =
import r.*
frag(
if r.atoms.size == 1 && r.atoms.head.by.is(UserId.lichess)
if r.atoms.size == 1 && r.atoms.forall(_.by.is(UserId.lichess))
then renderMod(UserId.lichess.into(ModId))
else
strong(
Expand All @@ -113,18 +112,17 @@ final class ModTimelineUi(helpers: Helpers)(
div(cls := "mod-timeline__event__action")(
" opened a ",
postForm(action := s"${routes.Report.inquiry(report.id.value)}?onlyOpen=1")(
submitButton(strong(atoms.head.reason.name), " report")(cls := "button-link")
cls := List("mod-timeline__report-form" -> true, "mod-timeline__report-form--open" -> r.report.open)
)(
submitButton(strong(atoms.head.reason.name), " report")(
cls := "button button-thin",
title := r.report.done.fold("Open")(d => s"Closed by ${usernameOrId(d.by.id)}")
)
)
),
renderText(atoms.head.text, highlightBad = false)
)

private def renderReportClose(r: ReportClose)(using Translate) = frag(
renderMod(r.done.by),
" closed the report about ",
r.report.atoms.toList.map(_.reason.name).mkString(", ")
)

private def renderModlog(user: User)(e: Modlog)(using Translate) =
val author: Frag =
if e.action == Modlog.selfCloseAccount then renderUser(user.id)
Expand Down
5 changes: 4 additions & 1 deletion ui/mod/css/_mod-timeline.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@
flex: 0 0 auto;
gap: 1ch;
}
.mod-timeline__event__action .button-link {
.mod-timeline__report-form .button {
line-height: 1.2;
}
.mod-timeline__report-form:not(.mod-timeline__report-form--open) .button {
@extend %button-none;
}
.mod-timeline__text {
@extend %break-word-hard;
font-size: 0.9em;
Expand Down

0 comments on commit 9dba181

Please sign in to comment.