Skip to content

Commit

Permalink
refactor: implement auto refresh on a few pages
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Jan 26, 2024
1 parent 4646e23 commit e4dc4fa
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 8 deletions.
26 changes: 25 additions & 1 deletion src/elm/Layouts/Default/Build.elm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import RemoteData exposing (WebData)
import Route exposing (Route)
import Route.Path
import Shared
import Time
import Utils.Errors
import Utils.Interval as Interval
import Vela
import View exposing (View)

Expand Down Expand Up @@ -99,6 +101,7 @@ init props shared _ =
type Msg
= OnUrlChanged { from : Route (), to : Route () }
| GetBuildResponse (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Build ))
| Tick { time : Time.Posix, interval : Interval.Interval }


update : Props contentMsg -> Shared.Model -> Msg -> Model -> ( Model, Effect Msg )
Expand Down Expand Up @@ -139,10 +142,31 @@ update props shared msg model =
, Effect.handleHttpError { httpError = error }
)

Tick options ->
( model
, Effect.batch
[ Effect.getRepoBuildsShared
{ pageNumber = Nothing
, perPage = Nothing
, maybeEvent = Nothing
, org = props.org
, repo = props.repo
}
, Effect.getBuild
{ baseUrl = shared.velaAPI
, session = shared.session
, onResponse = GetBuildResponse
, org = props.org
, repo = props.repo
, buildNumber = props.buildNumber
}
]
)


subscriptions : Model -> Sub Msg
subscriptions model =
Sub.none
Interval.tickEveryFiveSeconds Tick



Expand Down
21 changes: 17 additions & 4 deletions src/elm/Pages/Org_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import RemoteData exposing (WebData)
import Route exposing (Route)
import Route.Path
import Shared
import Time
import Utils.Errors
import Utils.Helpers as Util
import Utils.Interval as Interval
import Vela
import View exposing (View)

Expand All @@ -27,7 +29,7 @@ page : Auth.User -> Shared.Model -> Route { org : String } -> Page Model Msg
page user shared route =
Page.new
{ init = init shared route
, update = update
, update = update shared route
, subscriptions = subscriptions
, view = view shared route
}
Expand Down Expand Up @@ -75,10 +77,11 @@ init shared route () =

type Msg
= GetOrgReposResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Repository ))
| Tick { time : Time.Posix, interval : Interval.Interval }


update : Msg -> Model -> ( Model, Effect Msg )
update msg model =
update : Shared.Model -> Route { org : String } -> Msg -> Model -> ( Model, Effect Msg )
update shared route msg model =
case msg of
GetOrgReposResponse response ->
case response of
Expand All @@ -92,14 +95,24 @@ update msg model =
, Effect.handleHttpError { httpError = error }
)

Tick options ->
( model
, Effect.getOrgRepos
{ baseUrl = shared.velaAPI
, session = shared.session
, onResponse = GetOrgReposResponse
, org = route.params.org
}
)



-- SUBSCRIPTIONS


subscriptions : Model -> Sub Msg
subscriptions model =
Sub.none
Interval.tickEveryFiveSeconds Tick



Expand Down
21 changes: 20 additions & 1 deletion src/elm/Pages/Org_/Builds.elm
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import Page exposing (Page)
import RemoteData exposing (WebData)
import Route exposing (Route)
import Shared
import Time
import Utils.Errors
import Utils.Helpers as Util
import Utils.Interval as Interval
import Vela
import View exposing (View)

Expand Down Expand Up @@ -98,6 +100,7 @@ type Msg
| OnEventQueryParameterChanged { from : Maybe String, to : Maybe String }
| FilterByEvent (Maybe String)
| ShowHideFullTimestamps
| Tick { time : Time.Posix, interval : Interval.Interval }


update : Shared.Model -> Route { org : String } -> Msg -> Model -> ( Model, Effect Msg )
Expand Down Expand Up @@ -218,14 +221,30 @@ update shared route msg model =
ShowHideFullTimestamps ->
( { model | showFullTimestamps = not model.showFullTimestamps }, Effect.none )

Tick options ->
( model
, Effect.getOrgBuilds
{ baseUrl = shared.velaAPI
, session = shared.session
, onResponse = GetOrgBuildsResponse
, pageNumber = Dict.get "page" route.query |> Maybe.andThen String.toInt
, perPage = Dict.get "perPage" route.query |> Maybe.andThen String.toInt
, maybeEvent = Dict.get "event" route.query
, org = route.params.org
}
)



-- SUBSCRIPTIONS


subscriptions : Model -> Sub Msg
subscriptions model =
Util.onMouseDownSubscription "build-actions" (List.length model.showActionsMenus > 0) (ShowHideActionsMenus Nothing)
Sub.batch
[ Util.onMouseDownSubscription "build-actions" (List.length model.showActionsMenus > 0) (ShowHideActionsMenus Nothing)
, Interval.tickEveryFiveSeconds Tick
]



Expand Down
2 changes: 1 addition & 1 deletion src/elm/Pages/Org_/Repo_/Build_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ update shared route msg model =

subscriptions : Model -> Sub Msg
subscriptions model =
Interval.tickEveryOneSecond Tick
Interval.tickEveryFiveSeconds Tick



Expand Down
2 changes: 1 addition & 1 deletion src/elm/Pages/Org_/Repo_/Build_/Services.elm
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ update shared route msg model =

subscriptions : Model -> Sub Msg
subscriptions model =
Interval.tickEveryOneSecond Tick
Interval.tickEveryFiveSeconds Tick



Expand Down

0 comments on commit e4dc4fa

Please sign in to comment.