Skip to content

Commit

Permalink
refactor: clean up imports and RemoteData
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Jan 24, 2024
1 parent 0a8015c commit 53a1dd2
Show file tree
Hide file tree
Showing 44 changed files with 75 additions and 235 deletions.
1 change: 0 additions & 1 deletion src/elm/Auth.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Auth.Session exposing (Session(..))
import Dict
import Route exposing (Route)
import Route.Path
import Route.Query
import Shared
import View exposing (View)

Expand Down
7 changes: 2 additions & 5 deletions src/elm/Components/Build.elm
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
module Components.Build exposing (..)

import Ansi
import Ansi.Log
import Components.Svgs
import DateFormat.Relative
import FeatherIcons
import Html exposing (Html, a, details, div, input, label, li, span, strong, summary, text, ul)
import Html.Attributes exposing (attribute, checked, class, classList, for, href, id, name, style, title, type_)
import Html.Events exposing (onClick)
import Html exposing (Html, a, details, div, label, li, span, strong, summary, text, ul)
import Html.Attributes exposing (attribute, class, classList, href, id, title)
import List.Extra
import RemoteData exposing (WebData)
import Route.Path
Expand Down
21 changes: 1 addition & 20 deletions src/elm/Components/Builds.elm
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
module Components.Builds exposing (view, viewHeader)

import Ansi
import Ansi.Log
import Components.Build
import DateFormat.Relative exposing (relativeTime)
import FeatherIcons
import Html
exposing
( Html
, a
, br
, code
, details
, div
, em
, h1
Expand All @@ -20,38 +15,24 @@ import Html
, li
, ol
, p
, span
, strong
, summary
, table
, td
, text
, tr
, ul
)
import Html.Attributes
exposing
( attribute
, checked
, class
, classList
, for
, href
, id
, name
, style
, title
, type_
)
import Html.Events exposing (onClick)
import List.Extra
import RemoteData exposing (WebData)
import Route.Path
import Shared
import String
import Time
import Utils.Errors as Errors
import Utils.Helpers as Util exposing (getNameFromRef)
import Utils.Helpers as Util
import Vela


Expand Down
6 changes: 3 additions & 3 deletions src/elm/Components/Favorites.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Html exposing (Html, button)
import Html.Attributes exposing (attribute, class)
import Html.Events exposing (onClick)
import List.Extra
import RemoteData exposing (RemoteData(..), WebData)
import RemoteData exposing (WebData)
import Utils.Helpers as Util
import Vela

Expand Down Expand Up @@ -79,7 +79,7 @@ isFavorited user favorite =
toggleFavorite : WebData Vela.CurrentUser -> String -> ( List String, Bool )
toggleFavorite user favorite =
case user of
Success u ->
RemoteData.Success u ->
let
favorited =
List.member favorite u.favorites
Expand All @@ -102,7 +102,7 @@ toggleFavorite user favorite =
addFavorite : WebData Vela.CurrentUser -> String -> ( List String, Bool )
addFavorite user favorite =
case user of
Success u ->
RemoteData.Success u ->
let
favorites =
List.Extra.unique <| favorite :: u.favorites
Expand Down
2 changes: 1 addition & 1 deletion src/elm/Components/Nav.elm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Html.Attributes
, classList
)
import Html.Events exposing (onClick)
import RemoteData exposing (RemoteData(..), WebData)
import RemoteData exposing (WebData)
import Route exposing (Route)
import Shared
import Utils.Helpers as Util
Expand Down
2 changes: 1 addition & 1 deletion src/elm/Components/RecentBuilds.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Components.RecentBuilds exposing (..)

import Components.Svgs
import Html exposing (Html, a, div, em, li, p, span, text, ul)
import Html.Attributes exposing (attribute, class, href)
import Html.Attributes exposing (attribute, class)
import RemoteData exposing (WebData)
import Route.Path
import Shared
Expand Down
2 changes: 0 additions & 2 deletions src/elm/Components/Secrets.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import Html exposing (Html, a, button, div, span, td, text, tr)
import Html.Attributes exposing (attribute, class, scope)
import Html.Events exposing (onClick)
import Http
import Maybe.Extra
import RemoteData exposing (WebData)
import Route.Path
import Shared
import Url
import Utils.Helpers as Util
import Vela

Expand Down
3 changes: 1 addition & 2 deletions src/elm/Components/Tabs.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ module Components.Tabs exposing (Tab, view, viewBuildTabs, viewOrgTabs, viewRepo
import Api.Pagination as Pagination
import Html exposing (Html, a, div, span, text)
import Html.Attributes exposing (class, classList)
import RemoteData exposing (WebData)
import RemoteData
import Route.Path
import Shared
import Utils.Helpers as Util
import Vela


{-| Tab : record to represent information used by page navigation tab
Expand Down
2 changes: 1 addition & 1 deletion src/elm/Layouts/Default.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SPDX-License-Identifier: Apache-2.0

module Layouts.Default exposing (Model, Msg, Props, layout, map)

import Components.Alerts as Alerts exposing (Alert)
import Components.Alerts exposing (Alert)
import Components.Footer
import Components.Header
import Components.Nav
Expand Down
2 changes: 1 addition & 1 deletion src/elm/Layouts/Default/Build.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Components.Build
import Components.RecentBuilds
import Components.Tabs
import Effect exposing (Effect)
import Html exposing (..)
import Html exposing (Html)
import Http
import Http.Detailed
import Layout exposing (Layout)
Expand Down
2 changes: 0 additions & 2 deletions src/elm/Layouts/Default/Repo.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import Effect exposing (Effect)
import Html exposing (..)
import Layout exposing (Layout)
import Layouts.Default
import RemoteData exposing (WebData)
import Route exposing (Route)
import Shared
import Vela
import View exposing (View)


Expand Down
3 changes: 0 additions & 3 deletions src/elm/Main.elm
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{--
SPDX-License-Identifier: Apache-2.0
--}
--todo: known issues:
-- favicon fails to load sometimes on fresh visit
-- not found redirects are weird, refreshing 404 goes to the home page?


module Main exposing (main)
Expand Down
6 changes: 0 additions & 6 deletions src/elm/Pages/Account/Login.elm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Html
, div
, h1
, p
, span
, text
)
import Html.Attributes
Expand All @@ -27,7 +26,6 @@ import Html.Attributes
import Html.Events exposing (onClick)
import Layouts
import Page exposing (Page)
import RemoteData exposing (RemoteData(..), WebData)
import Route exposing (Route)
import Shared
import Utils.Helpers as Util
Expand Down Expand Up @@ -90,8 +88,6 @@ update shared msg model =
)

SignInRequested ->
-- Login on server needs to accept redirect URL and pass it along to as part of 'state' encoded as base64
-- so we can parse it when the source provider redirects back to the API
( model
, (Browser.Navigation.load <| Api.Endpoint.toUrl shared.velaAPI Api.Endpoint.Login) |> Effect.sendCmd
)
Expand All @@ -110,8 +106,6 @@ subscriptions model =
-- VIEW


{-| view : takes current user, user input and action params and renders home page with favorited repos
-}
view : Shared.Model -> Model -> View Msg
view shared model =
let
Expand Down
16 changes: 7 additions & 9 deletions src/elm/Pages/Account/SourceRepos.elm
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import Http.Detailed
import Layouts
import List.Extra
import Page exposing (Page)
import RemoteData exposing (RemoteData(..), WebData)
import RemoteData exposing (WebData)
import Route exposing (Route)
import Shared
import Utils.Errors as Errors
Expand Down Expand Up @@ -80,11 +80,11 @@ toLayout user shared model =
, ( "-outline", True )
]
, onClick (GetUserSourceRepos True)
, disabled (model.sourceRepos == Loading)
, disabled (model.sourceRepos == RemoteData.Loading)
, Util.testAttribute "refresh-source-repos"
]
[ case model.sourceRepos of
Loading ->
RemoteData.Loading ->
text "Loading…"

_ ->
Expand All @@ -108,7 +108,7 @@ type alias Model =
init : () -> ( Model, Effect Msg )
init () =
( { searchFilters = Dict.empty
, sourceRepos = NotAsked
, sourceRepos = RemoteData.NotAsked
}
, Effect.batch
[ Effect.getCurrentUser {}
Expand Down Expand Up @@ -143,8 +143,8 @@ update shared msg model =
GetUserSourceRepos isReload ->
( { model
| sourceRepos =
if isReload || model.sourceRepos == NotAsked then
Loading
if isReload || model.sourceRepos == RemoteData.NotAsked then
RemoteData.Loading

else
model.sourceRepos
Expand Down Expand Up @@ -186,7 +186,7 @@ update shared msg model =

EnableRepo repo ->
( { model
| sourceRepos = Vela.enableUpdate repo Loading model.sourceRepos
| sourceRepos = Vela.enableUpdate repo RemoteData.Loading model.sourceRepos

-- todo: need this moved to the repo settings page
-- , repo = updateRepoEnabling Vela.Enabling rm
Expand Down Expand Up @@ -253,8 +253,6 @@ subscriptions model =
-- VIEW


{-| view : takes current user with repos fetched from source control
-}
view : Shared.Model -> Model -> View Msg
view shared model =
let
Expand Down
15 changes: 3 additions & 12 deletions src/elm/Pages/Home.elm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import Layouts
import List
import List.Extra
import Page exposing (Page)
import RemoteData exposing (RemoteData(..))
import RemoteData
import Route exposing (Route)
import Route.Path
import Shared
Expand Down Expand Up @@ -135,15 +135,13 @@ subscriptions model =
-- VIEW


{-| view : takes current user, user input and action params and renders home page with favorited repos
-}
view : Shared.Model -> Model -> View Msg
view shared model =
{ title = "Home"
, body =
[ div [ Util.testAttribute "overview" ] <|
case shared.user of
Success u ->
RemoteData.Success u ->
if List.length u.favorites > 0 then
[ homeSearchBar model.favoritesFilter SearchFavorites
, viewFavorites u.favorites model.favoritesFilter
Expand All @@ -162,17 +160,10 @@ view shared model =
]
]

Loading ->
[ h1 [] [ Util.largeLoader ] ]

NotAsked ->
_ ->
[ homeSearchBar model.favoritesFilter SearchFavorites
, viewFavorites [] model.favoritesFilter
]

-- [ text "not asked" ]
Failure _ ->
[ text "failed" ]
]
}

Expand Down
2 changes: 0 additions & 2 deletions src/elm/Pages/NotFound_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ subscriptions model =
-- VIEW


{-| view : takes current user, user input and action params and renders home page with favorited repos
-}
view : Shared.Model -> Model -> View Msg
view shared model =
{ title = "Not Found"
Expand Down
3 changes: 1 addition & 2 deletions src/elm/Pages/Org_/Builds.elm
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ import Components.Builds
import Components.Pager
import Dict
import Effect exposing (Effect)
import Html exposing (text)
import Http
import Http.Detailed
import Layouts
import LinkHeader exposing (WebLink)
import List
import Maybe.Extra
import Page exposing (Page)
import RemoteData exposing (RemoteData(..), WebData)
import RemoteData exposing (WebData)
import Route exposing (Route)
import Shared
import Utils.Errors as Errors
Expand Down
1 change: 0 additions & 1 deletion src/elm/Pages/Org_/Repo_.elm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import LinkHeader exposing (WebLink)
import List
import Maybe.Extra
import Page exposing (Page)
import RemoteData exposing (RemoteData(..))
import Route exposing (Route)
import Shared
import Utils.Helpers as Util
Expand Down
3 changes: 1 addition & 2 deletions src/elm/Pages/Org_/Repo_/Audit.elm
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ import Layouts
import LinkHeader exposing (WebLink)
import List
import Page exposing (Page)
import RemoteData exposing (RemoteData(..), WebData)
import RemoteData exposing (WebData)
import Route exposing (Route)
import Shared
import Time
import Utils.Ansi
import Utils.Errors as Errors
import Utils.Helpers as Util
import Vela
import View exposing (View)
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 @@ -20,7 +20,7 @@ import Http.Detailed
import Layouts
import List.Extra
import Page exposing (Page)
import RemoteData exposing (RemoteData(..), WebData)
import RemoteData exposing (WebData)
import Route exposing (Route)
import Route.Path
import Shared
Expand Down
2 changes: 1 addition & 1 deletion src/elm/Pages/Org_/Repo_/Build_/Graph.elm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Http.Detailed
import Layouts
import List.Extra
import Page exposing (Page)
import RemoteData exposing (RemoteData(..), WebData)
import RemoteData exposing (WebData)
import Route exposing (Route)
import Route.Path
import Shared
Expand Down
Loading

0 comments on commit 53a1dd2

Please sign in to comment.