From d6d420ae87c4857ee9225acf9eeea096ffe74a6c Mon Sep 17 00:00:00 2001 From: 3wc <3wc.git@doesthisthing.work> Date: Sat, 24 Apr 2021 15:36:56 +0200 Subject: [PATCH] Fix links, change sort, add Utils --- src/Pages/App_String.elm | 14 ++++++++------ src/Pages/Top.elm | 26 ++++++++++++++++++++++---- src/Util.elm | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 10 deletions(-) create mode 100644 src/Util.elm diff --git a/src/Pages/App_String.elm b/src/Pages/App_String.elm index 1c613e0..65438dc 100644 --- a/src/Pages/App_String.elm +++ b/src/Pages/App_String.elm @@ -63,7 +63,7 @@ init url = default_image : String -- FIXME: change to absolute URL, if this works? -default_image = "http://localhost:8000/logo.png" +default_image = "/logo.png" -- UPDATE @@ -146,9 +146,11 @@ body model = div [ class "pt-3" ] [ case model.status of Failure -> - div [ ] - [ text "I could not load a random cat for some reason. " - , button [ onClick MorePlease ] [ text "Try Again!" ] + div [] + [ div [ class "alert alert-danger" ] + [ p [] [ text "Unable to load app data" ] + , button [ class "btn btn-danger", onClick MorePlease ] [ text "Try Again!" ] + ] ] Loading -> @@ -242,7 +244,7 @@ loadApp = -- fetch app JSON and README in parallel Http.get -- FIXME: change to absolute URL, if this works? - { url = "http://localhost:8000/abra-apps-list.json" + { url = "/abra-apps-list.json" , expect = Http.expectJson GotApps appListDecoder } @@ -259,7 +261,7 @@ loadREADME app = text "" in Http.get - -- FIXME add branch name to apps.json, load actual README + -- FIXME use live Gitea link { url = "http://localhost:1234/coop-cloud/" ++ app.slug ++ "/raw/branch/" ++ app.default_branch ++ "/README.md" , expect = Http.expectString GotText } diff --git a/src/Pages/Top.elm b/src/Pages/Top.elm index e1ad8b4..88b9391 100644 --- a/src/Pages/Top.elm +++ b/src/Pages/Top.elm @@ -9,6 +9,7 @@ import Spa.Generated.Route as Route import Spa.Document exposing (Document) import Spa.Page as Page exposing (Page) import Spa.Url as Url exposing (Url) +import Util exposing (by, andThen, Direction(..)) page : Page Params Model Msg @@ -50,7 +51,7 @@ init { params } = default_image : String -default_image = "http://localhost:8000/logo.png" +default_image = "/logo.png" -- UPDATE @@ -98,6 +99,20 @@ body model = [ viewApps model ] +appScore : App -> Int +appScore app = + case app.status of + "1" -> + 1 + "2" -> + 2 + "3" -> + 3 + "4" -> + 4 + _ -> + 5 + viewStatusBadge : App -> Html Msg viewStatusBadge app = let @@ -119,7 +134,6 @@ viewStatusBadge app = "?" score -> score - in span [ class ("card-link badge " ++ status_class) ] [ text ("Score: " ++ status_score) ] @@ -178,6 +192,7 @@ viewApp app = ] ] + viewApps : Model -> Html Msg viewApps model = case model of @@ -193,7 +208,10 @@ viewApps model = Success apps -> div [] [ div [ class "row" ] - (List.map viewApp (List.sortBy (String.toLower << .name) apps)) + (List.map viewApp (apps |> List.sortWith + (by appScore ASC + |> andThen .name ASC)) + ) ] -- HTTP @@ -202,7 +220,7 @@ viewApps model = loadApps : Cmd Msg loadApps = Http.get - { url = "http://localhost:8000/abra-apps-list.json" + { url = "/abra-apps-list.json" , expect = Http.expectJson GotApps appListDecoder } diff --git a/src/Util.elm b/src/Util.elm new file mode 100644 index 0000000..3fbd480 --- /dev/null +++ b/src/Util.elm @@ -0,0 +1,34 @@ +module Util exposing (by, andThen, Direction(..)) + +type Direction + = ASC + | DESC + + +by : (a -> comparable) -> Direction -> (a -> a -> Order) +by toCmp direction a b = + case ( compare (toCmp a) (toCmp b), direction ) of + ( LT, ASC ) -> + LT + + ( LT, DESC ) -> + GT + + ( GT, ASC ) -> + GT + + ( GT, DESC ) -> + LT + + ( EQ, _ ) -> + EQ + + +andThen : (a -> comparable) -> Direction -> (a -> a -> Order) -> (a -> a -> Order) +andThen toCmp direction primary a b = + case primary a b of + EQ -> + by toCmp direction a b + + ineq -> + ineq