Skip to content

Commit

Permalink
some more refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rpiaggio committed Sep 18, 2024
1 parent 03e4d36 commit a1ef822
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 210 deletions.
43 changes: 43 additions & 0 deletions explore/src/main/scala/explore/proposal/CallDeadline.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2016-2023 Association of Universities for Research in Astronomy, Inc. (AURA)
// For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause

package explore.proposal

import cats.effect.IO
import crystal.react.hooks.*
import explore.components.ui.ExploreStyles
import explore.model.Proposal
import fs2.Stream
import japgolly.scalajs.react.*
import japgolly.scalajs.react.vdom.html_<^.*
import lucuma.core.util.Timestamp
import lucuma.react.common.ReactFnProps
import lucuma.react.primereact.Message

import java.time.Instant
import scala.concurrent.duration.*

case class CallDeadline(deadline: Timestamp) extends ReactFnProps(CallDeadline.component)

object CallDeadline:
private type Props = CallDeadline

private val component =
ScalaFnComponent
.withHooks[Props]
.useStreamOnMount:
Stream.eval(IO(Instant.now())) ++
Stream
.awakeDelay[IO](1.seconds)
.flatMap(_ => Stream.eval(IO(Instant.now())))
.render: (p, n) =>
n.toOption.map: n =>
val (deadlineStr, left) = Proposal.deadlineAndTimeLeft(n, p.deadline)
val text = left.fold(deadlineStr)(l => s"$deadlineStr [$l]")

<.span(ExploreStyles.ProposalDeadline)(
Message(
text = s"Deadline: $text",
severity = Message.Severity.Info
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

package explore.proposal

import cats.data.NonEmptyList
import cats.data.NonEmptySet
import cats.syntax.all.*
import crystal.react.*
Expand All @@ -12,40 +11,34 @@ import explore.components.Tile
import explore.model.ProgramUserWithRole
import explore.model.ProposalTabTileIds
import explore.model.UserInvitation
import explore.users.CreateInviteProcess
import explore.users.ProgramUserInvitations
import explore.users.ProgramUsersTable
import japgolly.scalajs.react.*
import japgolly.scalajs.react.vdom.html_<^.*
import lucuma.core.enums.InvitationStatus
import lucuma.core.enums.ProgramUserRole
import lucuma.core.model.Program
import lucuma.core.util.Enumerated
import lucuma.core.util.NewType
import lucuma.react.common.ReactFnProps
import lucuma.react.primereact.Button
import lucuma.react.primereact.OverlayPanelRef
import lucuma.ui.primereact.*
import lucuma.ui.syntax.all.given

enum CreateInviteProcess(private val tag: String) derives Enumerated:
case Idle extends CreateInviteProcess("idle")
case Running extends CreateInviteProcess("running")
case Error extends CreateInviteProcess("error")
case Done extends CreateInviteProcess("done")
case class InvestigatorUsers private (
pid: Program.Id,
readOnly: Boolean,
users: View[List[ProgramUserWithRole]],
invitations: View[List[UserInvitation]],
private val state: View[InvestigatorUsers.ProgramUsersState]
) extends ReactFnProps(InvestigatorUsers.component)

object ProgramUsersState extends NewType[CreateInviteProcess]
type ProgramUsersState = ProgramUsersState.Type
object InvestigatorUsers:
private type Props = InvestigatorUsers

case class ProgramUsers(
pid: Program.Id,
readOnly: Boolean,
users: View[List[ProgramUserWithRole]],
invitations: View[List[UserInvitation]],
state: View[ProgramUsersState]
) extends ReactFnProps(ProgramUsers.component)

object ProgramUsers:
private type Props = ProgramUsers
protected object ProgramUsersState extends NewType[CreateInviteProcess]
private type ProgramUsersState = ProgramUsersState.Type

private def inviteControl(
readOnly: Boolean,
Expand Down Expand Up @@ -73,7 +66,9 @@ object ProgramUsers:
ProposalTabTileIds.UsersId.id,
"Investigators",
ProgramUsersState(CreateInviteProcess.Idle)
)(ProgramUsers(pid, readOnly, users, invitations, _), (s, _) => inviteControl(readOnly, ref, s))
)(InvestigatorUsers(pid, readOnly, users, invitations, _),
(s, _) => inviteControl(readOnly, ref, s)
)

private val component =
ScalaFnComponent[Props]: props =>
Expand Down
3 changes: 2 additions & 1 deletion explore/src/main/scala/explore/proposal/ProposalEditor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import explore.model.UserInvitation
import explore.model.enums.GridLayoutSection
import explore.model.layout.LayoutsMap
import explore.undo.*
import explore.users.InviteUserPopup
import japgolly.scalajs.react.*
import japgolly.scalajs.react.vdom.html_<^.*
import lucuma.core.enums.ProgramUserRole
Expand Down Expand Up @@ -130,7 +131,7 @@ object ProposalEditor:
)

val usersTile =
ProgramUsers.programUsersTile(
InvestigatorUsers.programUsersTile(
props.programId,
props.readonly,
props.users,
Expand Down
Loading

0 comments on commit a1ef822

Please sign in to comment.