From 2244f38348086538736d81ea3496414cf96c39f3 Mon Sep 17 00:00:00 2001 From: efim Date: Tue, 25 Apr 2023 10:25:36 +0400 Subject: [PATCH] scalafmt all --- .scalafmt.conf | 1 + .../sunshine/planningpoker/Auth.scala | 12 +- .../planningpoker/MyHttpService.scala | 8 +- .../sunshine/planningpoker/RoomService.scala | 3 +- build.sbt | 6 +- .../sunshine/planningpoker/Models.scala | 4 +- .../sunshine/planningpoker/Requests.scala | 3 +- .../sunshine/planningpoker/TestModels.scala | 196 +++++++++--------- .../sunshine/planningpoker/FrontendMain.scala | 4 +- .../sunshine/planningpoker/TableView.scala | 25 ++- 10 files changed, 133 insertions(+), 129 deletions(-) diff --git a/.scalafmt.conf b/.scalafmt.conf index fd76373..edf3886 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,2 +1,3 @@ runner.dialect = scala3 version = 3.7.3 +maxColumn = 100 diff --git a/backend/src/main/scala/industries/sunshine/planningpoker/Auth.scala b/backend/src/main/scala/industries/sunshine/planningpoker/Auth.scala index 59d5f9f..7aae41d 100644 --- a/backend/src/main/scala/industries/sunshine/planningpoker/Auth.scala +++ b/backend/src/main/scala/industries/sunshine/planningpoker/Auth.scala @@ -14,15 +14,14 @@ trait Auth[F[_]] { /** for middleware that converts sessionId into PlayerId */ - def authUser - : Kleisli[[A] =>> cats.data.OptionT[F, A], Request[F], (PlayerID, RoomID)] + def authUser: Kleisli[[A] =>> cats.data.OptionT[F, A], Request[F], (PlayerID, RoomID)] /** Get sessionId for accessing a room * @param roomPassword * \- requirement to get access to the room * - * check that room exists, password is valid call to add user to the players - * create session mapping and return cookie + * check that room exists, password is valid call to add user to the players create session + * mapping and return cookie */ def joinRoom( roomName: String, @@ -75,9 +74,8 @@ object Auth { ??? } - override def authUser: Kleisli[[A] =>> cats.data.OptionT[F, A], Request[ - F - ], (PlayerID, RoomID)] = { + override def authUser + : Kleisli[[A] =>> cats.data.OptionT[F, A], Request[F], (PlayerID, RoomID)] = { // check authcookie presence, exchange it for playerID ad roomID ??? } diff --git a/backend/src/main/scala/industries/sunshine/planningpoker/MyHttpService.scala b/backend/src/main/scala/industries/sunshine/planningpoker/MyHttpService.scala index 4ed1308..6322431 100644 --- a/backend/src/main/scala/industries/sunshine/planningpoker/MyHttpService.scala +++ b/backend/src/main/scala/industries/sunshine/planningpoker/MyHttpService.scala @@ -24,9 +24,11 @@ object MyHttpService { AuthedRoutes.of { case GET -> Root / "subscribe" as (playerId, roomId) => { val send: Stream[IO, WebSocketFrame] = - Stream + Stream .emits(TestModels.testChangesList) - .covary[IO].metered(1.second).map(state => WebSocketFrame.Text(state.asJson.noSpaces)) + .covary[IO] + .metered(1.second) + .map(state => WebSocketFrame.Text(state.asJson.noSpaces)) val receive: Pipe[IO, WebSocketFrame, Unit] = _.evalMap { case WebSocketFrame.Text(text, _) => Sync[IO].delay(println(text)) @@ -64,7 +66,7 @@ object MyHttpService { Forbidden(error) case Right(authCookie) => { IO(println(s"> logging in ${data.nickname} to ${data.roomName}")) >> - Ok().map(_.addCookie(authCookie)) + Ok().map(_.addCookie(authCookie)) } } } yield resp diff --git a/backend/src/main/scala/industries/sunshine/planningpoker/RoomService.scala b/backend/src/main/scala/industries/sunshine/planningpoker/RoomService.scala index 04b6823..88e425f 100644 --- a/backend/src/main/scala/industries/sunshine/planningpoker/RoomService.scala +++ b/backend/src/main/scala/industries/sunshine/planningpoker/RoomService.scala @@ -15,8 +15,7 @@ trait RoomService[F[_]] { def getRoom(roomID: RoomID): F[Option[Room]] } -class InMemoryRoomService[F[_]: Sync](stateRef: Ref[F, Map[RoomID, Room]]) - extends RoomService[F] { +class InMemoryRoomService[F[_]: Sync](stateRef: Ref[F, Map[RoomID, Room]]) extends RoomService[F] { override def createRoom(newRoom: Room): F[Either[RoomError, Room]] = { stateRef.modify { rooms => rooms.get(newRoom.id) match { diff --git a/build.sbt b/build.sbt index 838f1f6..7f5e1e9 100644 --- a/build.sbt +++ b/build.sbt @@ -55,7 +55,7 @@ lazy val backend = project libraryDependencies += "co.fs2" %% "fs2-core" % "3.6.1", libraryDependencies += "org.typelevel" %% "cats-core" % "2.9.0", libraryDependencies += "org.typelevel" %% "cats-effect" % "3.4.9", - assembly / mainClass := Some("industries.sunshine.planningpoker.BackendApp"), + assembly / mainClass := Some("industries.sunshine.planningpoker.BackendApp") ) .dependsOn(common.jvm) @@ -76,6 +76,8 @@ lazy val commonJS = common.js.settings( // scalaJS specific settings scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.ESModule) - .withModuleSplitStyle(ModuleSplitStyle.SmallModulesFor(List("industries.sunshine.planningpoker"))) + .withModuleSplitStyle( + ModuleSplitStyle.SmallModulesFor(List("industries.sunshine.planningpoker")) + ) } ) diff --git a/common/src/main/scala/industries/sunshine/planningpoker/Models.scala b/common/src/main/scala/industries/sunshine/planningpoker/Models.scala index 13b068a..d179786 100644 --- a/common/src/main/scala/industries/sunshine/planningpoker/Models.scala +++ b/common/src/main/scala/industries/sunshine/planningpoker/Models.scala @@ -37,8 +37,8 @@ object Models { enum RoundState derives Codec.AsObject: - /** view state for round before votes are open player can know their vote - * and who of the other players have voted + /** view state for round before votes are open player can know their vote and who of the other + * players have voted */ case Voting( myCard: Option[String], diff --git a/common/src/main/scala/industries/sunshine/planningpoker/Requests.scala b/common/src/main/scala/industries/sunshine/planningpoker/Requests.scala index 7f750a2..5349a9c 100644 --- a/common/src/main/scala/industries/sunshine/planningpoker/Requests.scala +++ b/common/src/main/scala/industries/sunshine/planningpoker/Requests.scala @@ -4,5 +4,6 @@ import io.circe.generic.semiauto._ import io.circe._ object Requests { - final case class LogIn(roomName: String, nickname: String, password: String) derives Codec.AsObject + final case class LogIn(roomName: String, nickname: String, password: String) + derives Codec.AsObject } diff --git a/common/src/main/scala/industries/sunshine/planningpoker/TestModels.scala b/common/src/main/scala/industries/sunshine/planningpoker/TestModels.scala index d922cc1..c1e8d55 100644 --- a/common/src/main/scala/industries/sunshine/planningpoker/TestModels.scala +++ b/common/src/main/scala/industries/sunshine/planningpoker/TestModels.scala @@ -3,104 +3,104 @@ package industries.sunshine.planningpoker import industries.sunshine.planningpoker.common.Models.* object TestModels { - val me = Player("wormy", PlayerID(1)) - val pony = Player("pony", PlayerID(10)) - val birdy = Player("birdy", PlayerID(11)) - val horsey = Player("horsey", PlayerID(12)) + val me = Player("wormy", PlayerID(1)) + val pony = Player("pony", PlayerID(10)) + val birdy = Player("birdy", PlayerID(11)) + val horsey = Player("horsey", PlayerID(12)) - val testRoom = { - RoomStateView( - players = List(me, birdy, pony), - me = me.id, - allowedCards = List("xs", "s", "m", "l", "xl"), - round = RoundState.Voting(myCard = Some("s"), alreadyVoted = List(me, pony)), - canCloseRound = true - ) - } - val testOpenedRoom = { - RoomStateView( - players = List(me, birdy, pony, horsey), - me = me.id, - allowedCards = List("xs", "s", "m", "l", "xl"), - round = RoundState.Viewing( - List(me.id -> "xs", pony.id -> "l", birdy.id -> "s", horsey.id -> "m") - ), - canCloseRound = true - ) - } - - val testChangesList = List( - RoomStateView( - players = List(me), - me = me.id, - allowedCards = List("xs", "s", "m", "l", "xl"), - round = RoundState.Voting(myCard = None, alreadyVoted = List.empty), - canCloseRound = true - ), - RoomStateView( - players = List(me, pony), - me = me.id, - allowedCards = List("xs", "s", "m", "l", "xl"), - round = RoundState.Voting(myCard = None, alreadyVoted = List.empty), - canCloseRound = true - ), - RoomStateView( - players = List(me, birdy, pony), - me = me.id, - allowedCards = List("xs", "s", "m", "l", "xl"), - round = RoundState.Voting(myCard = None, alreadyVoted = List.empty), - canCloseRound = true - ), - RoomStateView( - players = List(me, birdy, pony), - me = me.id, - allowedCards = List("xs", "s", "m", "l", "xl"), - round = RoundState.Voting(myCard = None, alreadyVoted = List(birdy)), - canCloseRound = true - ), - RoomStateView( - players = List(me, birdy, pony), - me = me.id, - allowedCards = List("xs", "s", "m", "l", "xl"), - round = RoundState.Voting(myCard = Some("m"), alreadyVoted = List(birdy)), - canCloseRound = true - ), - RoomStateView( - players = List(me, birdy, pony), - me = me.id, - allowedCards = List("xs", "s", "m", "l", "xl"), - round = RoundState.Voting(myCard = Some("m"), alreadyVoted = List(birdy)), - canCloseRound = true - ), - RoomStateView( - players = List(me, birdy, pony, horsey), - me = me.id, - allowedCards = List("xs", "s", "m", "l", "xl"), - round = RoundState.Voting(myCard = Some("m"), alreadyVoted = List(birdy)), - canCloseRound = true - ), - RoomStateView( - players = List(me, birdy, pony, horsey), - me = me.id, - allowedCards = List("xs", "s", "m", "l", "xl"), - round = RoundState.Voting(myCard = Some("m"), alreadyVoted = List(birdy, horsey)), - canCloseRound = true - ), - RoomStateView( - players = List(me, birdy, pony, horsey), - me = me.id, - allowedCards = List("xs", "s", "m", "l", "xl"), - round = RoundState.Voting(myCard = Some("m"), alreadyVoted = List(birdy, horsey, pony)), - canCloseRound = true - ), - RoomStateView( - players = List(me, birdy, pony, horsey), - me = me.id, - allowedCards = List("xs", "s", "m", "l", "xl"), - round = RoundState.Viewing( - List(me.id -> "m", pony.id -> "l", birdy.id -> "s", horsey.id -> "m") - ), - canCloseRound = true - ) + val testRoom = { + RoomStateView( + players = List(me, birdy, pony), + me = me.id, + allowedCards = List("xs", "s", "m", "l", "xl"), + round = RoundState.Voting(myCard = Some("s"), alreadyVoted = List(me, pony)), + canCloseRound = true ) + } + val testOpenedRoom = { + RoomStateView( + players = List(me, birdy, pony, horsey), + me = me.id, + allowedCards = List("xs", "s", "m", "l", "xl"), + round = RoundState.Viewing( + List(me.id -> "xs", pony.id -> "l", birdy.id -> "s", horsey.id -> "m") + ), + canCloseRound = true + ) + } + + val testChangesList = List( + RoomStateView( + players = List(me), + me = me.id, + allowedCards = List("xs", "s", "m", "l", "xl"), + round = RoundState.Voting(myCard = None, alreadyVoted = List.empty), + canCloseRound = true + ), + RoomStateView( + players = List(me, pony), + me = me.id, + allowedCards = List("xs", "s", "m", "l", "xl"), + round = RoundState.Voting(myCard = None, alreadyVoted = List.empty), + canCloseRound = true + ), + RoomStateView( + players = List(me, birdy, pony), + me = me.id, + allowedCards = List("xs", "s", "m", "l", "xl"), + round = RoundState.Voting(myCard = None, alreadyVoted = List.empty), + canCloseRound = true + ), + RoomStateView( + players = List(me, birdy, pony), + me = me.id, + allowedCards = List("xs", "s", "m", "l", "xl"), + round = RoundState.Voting(myCard = None, alreadyVoted = List(birdy)), + canCloseRound = true + ), + RoomStateView( + players = List(me, birdy, pony), + me = me.id, + allowedCards = List("xs", "s", "m", "l", "xl"), + round = RoundState.Voting(myCard = Some("m"), alreadyVoted = List(birdy)), + canCloseRound = true + ), + RoomStateView( + players = List(me, birdy, pony), + me = me.id, + allowedCards = List("xs", "s", "m", "l", "xl"), + round = RoundState.Voting(myCard = Some("m"), alreadyVoted = List(birdy)), + canCloseRound = true + ), + RoomStateView( + players = List(me, birdy, pony, horsey), + me = me.id, + allowedCards = List("xs", "s", "m", "l", "xl"), + round = RoundState.Voting(myCard = Some("m"), alreadyVoted = List(birdy)), + canCloseRound = true + ), + RoomStateView( + players = List(me, birdy, pony, horsey), + me = me.id, + allowedCards = List("xs", "s", "m", "l", "xl"), + round = RoundState.Voting(myCard = Some("m"), alreadyVoted = List(birdy, horsey)), + canCloseRound = true + ), + RoomStateView( + players = List(me, birdy, pony, horsey), + me = me.id, + allowedCards = List("xs", "s", "m", "l", "xl"), + round = RoundState.Voting(myCard = Some("m"), alreadyVoted = List(birdy, horsey, pony)), + canCloseRound = true + ), + RoomStateView( + players = List(me, birdy, pony, horsey), + me = me.id, + allowedCards = List("xs", "s", "m", "l", "xl"), + round = RoundState.Viewing( + List(me.id -> "m", pony.id -> "l", birdy.id -> "s", horsey.id -> "m") + ), + canCloseRound = true + ) + ) } diff --git a/frontend/src/main/scala/industries/sunshine/planningpoker/FrontendMain.scala b/frontend/src/main/scala/industries/sunshine/planningpoker/FrontendMain.scala index e122abd..9535dba 100644 --- a/frontend/src/main/scala/industries/sunshine/planningpoker/FrontendMain.scala +++ b/frontend/src/main/scala/industries/sunshine/planningpoker/FrontendMain.scala @@ -30,7 +30,9 @@ object Main { import io.laminext.websocket.circe.WebSocket._ import io.laminext.websocket.circe.webSocketReceiveBuilderSyntax - val roomStateWSStream = io.laminext.websocket.WebSocket.path("/api/subscribe").json[RoomStateView, Unit] + val roomStateWSStream = io.laminext.websocket.WebSocket + .path("/api/subscribe") + .json[RoomStateView, Unit] .build( managed = true, autoReconnect = false, diff --git a/frontend/src/main/scala/industries/sunshine/planningpoker/TableView.scala b/frontend/src/main/scala/industries/sunshine/planningpoker/TableView.scala index b88e039..279293a 100644 --- a/frontend/src/main/scala/industries/sunshine/planningpoker/TableView.scala +++ b/frontend/src/main/scala/industries/sunshine/planningpoker/TableView.scala @@ -13,17 +13,16 @@ object TableView { // so, it's more efficient to share an observable, than to create multiple copies... def renderTable(roundSignal: Signal[RoomStateView]): Element = { val playerIdToCardTypeSignal = - roundSignal.combineWith(Main.appStateSignal.map(_.myId)).map((state, myIdOpt) => - state.players.map(p => - p.id -> getPlayerCardType(p.id, state.round, p.name, myIdOpt) + roundSignal + .combineWith(Main.appStateSignal.map(_.myId)) + .map((state, myIdOpt) => + state.players.map(p => p.id -> getPlayerCardType(p.id, state.round, p.name, myIdOpt)) ) - ) div( className := "w-full h-full border-2 border-amber-700 flex flex-row justify-center items-center bg-green-100", - children <-- playerIdToCardTypeSignal.split(_._1) { - (id, initial, cardTypeSignal) => - renderPlayerCard(cardTypeSignal.map(_._2)) + children <-- playerIdToCardTypeSignal.split(_._1) { (id, initial, cardTypeSignal) => + renderPlayerCard(cardTypeSignal.map(_._2)) } ) } @@ -57,8 +56,8 @@ object TableView { def renderPlayerCard(state: Signal[CardState]): Element = { val cardTypeStyle = state.map { case NoCard(_) => "bg-green-100 text-black border-2 border-black" - case CardBack => "bg-green-500 border-4 border-green-700" - case Open(_) => "text-black bg-gray-50 border-black border-2" + case CardBack => "bg-green-500 border-4 border-green-700" + case Open(_) => "text-black bg-gray-50 border-black border-2" } div( @@ -67,11 +66,11 @@ object TableView { div( className := "-rotate-45 text-xl", child.text <-- state.map { - case NoCard(name) => name - case CardBack => "" - case Open(vote) => vote + case NoCard(name) => name + case CardBack => "" + case Open(vote) => vote } - ), + ) ) }