From 2dec76fbfd78df538278179f8505076d153254fd Mon Sep 17 00:00:00 2001 From: 3wc <3wc@doesthisthing.work> Date: Tue, 28 Mar 2023 01:54:26 -0400 Subject: [PATCH] elm-format --- src/Pages/App_String.elm | 9 +- src/Pages/Top.elm | 194 +++++++++++++++++++++++---------------- 2 files changed, 120 insertions(+), 83 deletions(-) diff --git a/src/Pages/App_String.elm b/src/Pages/App_String.elm index 4fd9870..8f79c7b 100644 --- a/src/Pages/App_String.elm +++ b/src/Pages/App_String.elm @@ -272,9 +272,9 @@ viewApp app readme = ] , div [ class "card-footer" ] [ h5 [] [ text "Versions" ] - , ul [] ( - List.map (\version -> li [] [ text (version) ]) app.versions - )] + , ul [] + (List.map (\version -> li [] [ text version ]) app.versions) + ] ] ] @@ -319,8 +319,6 @@ featuresDecoder = ] - - versionsDecoder : Decode.Decoder (List String) versionsDecoder = Decode.list (Decode.keyValuePairs Decode.value) @@ -332,7 +330,6 @@ buildVersions versions = List.concatMap (List.map (\( version, _ ) -> version)) versions - appDecoder : Decode.Decoder App appDecoder = Decode.succeed App diff --git a/src/Pages/Top.elm b/src/Pages/Top.elm index b6fc0cb..5293335 100644 --- a/src/Pages/Top.elm +++ b/src/Pages/Top.elm @@ -1,8 +1,8 @@ module Pages.Top exposing (Model, Msg, Params, page) import Enum exposing (Enum) -import Html exposing (Html, a, button, div, h2, h3, h5, i, img, li, p, span, text, ul, form, label, select, option, input) -import Html.Attributes exposing (alt, class, href, src, style, id, for, value) +import Html exposing (Html, a, button, div, form, h2, h3, h5, i, img, input, label, li, option, p, select, span, text, ul) +import Html.Attributes exposing (alt, class, for, href, id, src, style, value) import Html.Attributes.Aria exposing (ariaLabel) import Html.Events exposing (onClick, onInput) import Http @@ -27,6 +27,7 @@ page = } + -- INIT @@ -53,8 +54,8 @@ type alias Model = , filter_category : Maybe Category , filter_text : Maybe String , status : Status - , apps : (List App) - , results : (List App) + , apps : List App + , results : List App } @@ -78,11 +79,10 @@ categories = [ ( "Apps", Apps ) , ( "Utilities", Utilities ) , ( "Development", Development ) - , ("All", All) + , ( "All", All ) ] - init : Url Params -> ( Model, Cmd Msg ) init { params } = ( default_model, loadApps ) @@ -95,8 +95,14 @@ default_image = default_model : Model default_model = - { filter_score = Nothing, filter_category = Nothing, filter_text = Nothing, - status = Loading, apps = [], results = [] } + { filter_score = Nothing + , filter_category = Nothing + , filter_text = Nothing + , status = Loading + , apps = [] + , results = [] + } + -- UPDATE @@ -114,41 +120,55 @@ filterAppsScore : List App -> Maybe Int -> List App filterAppsScore apps score = case score of Just s -> - List.filter (\app -> + List.filter + (\app -> app.status >= s - ) apps + ) + apps + Nothing -> apps + filterAppsCategory : List App -> Maybe Category -> List App filterAppsCategory apps category = case category of Just c -> if c == All then apps + else - List.filter (\app -> - app.category == categories.toString c - ) apps + List.filter + (\app -> + app.category == categories.toString c + ) + apps + Nothing -> apps + filterAppsText : List App -> Maybe String -> List App filterAppsText apps text = case text of Just "" -> apps + Just t -> - List.filter (\app -> - String.contains (String.toLower t) ( - String.toLower app.name ++ String.toLower ( - Maybe.withDefault "" app.description - ) + List.filter + (\app -> + String.contains (String.toLower t) + (String.toLower app.name + ++ String.toLower + (Maybe.withDefault "" app.description) + ) ) - ) apps + apps + Nothing -> apps + update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = case msg of @@ -157,51 +177,71 @@ update msg model = FilterScore filter -> let - filter_score = String.toInt filter + filter_score = + String.toInt filter in - ( { model - | filter_score = filter_score - , results = filterAppsScore ( - filterAppsCategory ( - filterAppsText model.apps model.filter_text - ) model.filter_category - ) (String.toInt filter) - }, Cmd.none ) + ( { model + | filter_score = filter_score + , results = + filterAppsScore + (filterAppsCategory + (filterAppsText model.apps model.filter_text) + model.filter_category + ) + (String.toInt filter) + } + , Cmd.none + ) FilterCategory filter -> let - category = categories.fromString filter + category = + categories.fromString filter in ( { model | filter_category = category - , results = filterAppsCategory ( - filterAppsScore ( - filterAppsText model.apps model.filter_text - )model.filter_score - ) category - }, Cmd.none ) + , results = + filterAppsCategory + (filterAppsScore + (filterAppsText model.apps model.filter_text) + model.filter_score + ) + category + } + , Cmd.none + ) FilterText filter -> ( { model | filter_text = Just filter - , results = filterAppsText ( - filterAppsScore ( - filterAppsCategory model.apps model.filter_category - ) model.filter_score - ) (Just filter) - }, Cmd.none ) + , results = + filterAppsText + (filterAppsScore + (filterAppsCategory model.apps model.filter_category) + model.filter_score + ) + (Just filter) + } + , Cmd.none + ) GotApps result -> case result of Ok apps -> ( { default_model - | status = Success - , apps = apps - , results = apps }, Cmd.none ) + | status = Success + , apps = apps + , results = apps + } + , Cmd.none + ) Err _ -> ( { default_model - | status = Failure}, Cmd.none ) + | status = Failure + } + , Cmd.none + ) subscriptions : Model -> Sub Msg @@ -304,16 +344,14 @@ viewApp app = , p [ class "card-description" ] [ text (ellipsis 100 (withDefault "" app.description)) ] ] , div [ class "footer" ] - [ viewStatusBadge app, span [ class "badge app-category" ] [ text app.category ]] + [ viewStatusBadge app, span [ class "badge app-category" ] [ text app.category ] ] ] ] - -viewCategories : (String, Category) -> Html Msg +viewCategories : ( String, Category ) -> Html Msg viewCategories category = - div [ class "category-tile", onClick (FilterCategory (Tuple.first category)) ] [text (Tuple.first category)] - + div [ class "category-tile", onClick (FilterCategory (Tuple.first category)) ] [ text (Tuple.first category) ] viewApps : Model -> Html Msg @@ -336,36 +374,36 @@ viewApps model = Success -> div [ class "row justify-content-center" ] - [ div [ class "col-md-3", id "filter" ] [ - h2 [ class "app-headings" ] [text "Filter"] - , form [] [ - div [] [ - h3 [] [text "Categories"] - , div [] (List.map viewCategories categories.list) - ] - , div [] [ - h3 [] [text "Search"] - , input [ ariaLabel "search", id "text", onInput FilterText ] [] - ] - , div [] [ - h3 [] [text "Status"] - , label [ for "level" ] [ text "At least:" ] - , select [ class "search-dropdown", id "level", onInput FilterScore ] [ - option [ ] [ text "any" ] - , option [ value "5" ] [ text "5 (production)" ] - , option [ value "4" ] [ text "4 (beta)" ] - , option [ value "3" ] [ text "3 (alpha)" ] - , option [ value "2" ] [ text "2 (pre-alpha)" ] - , option [ value "1" ] [ text "1 (work-in-progress)" ] + [ div [ class "col-md-3", id "filter" ] + [ h2 [ class "app-headings" ] [ text "Filter" ] + , form [] + [ div [] + [ h3 [] [ text "Categories" ] + , div [] (List.map viewCategories categories.list) + ] + , div [] + [ h3 [] [ text "Search" ] + , input [ ariaLabel "search", id "text", onInput FilterText ] [] + ] + , div [] + [ h3 [] [ text "Status" ] + , label [ for "level" ] [ text "At least:" ] + , select [ class "search-dropdown", id "level", onInput FilterScore ] + [ option [] [ text "any" ] + , option [ value "5" ] [ text "5 (production)" ] + , option [ value "4" ] [ text "4 (beta)" ] + , option [ value "3" ] [ text "3 (alpha)" ] + , option [ value "2" ] [ text "2 (pre-alpha)" ] + , option [ value "1" ] [ text "1 (work-in-progress)" ] + ] + ] ] ] - ] - ] , div [ class "col-md-6 offset-md-3" ] [ div [ class "row" ] - [ div [ class "col-sm-12" ] [ - div [] [ - ] + [ div [ class "col-sm-12" ] + [ div [] + [] ] ] , h2 [ class "app-headings" ] [ text "Apps" ] @@ -379,9 +417,11 @@ viewApps model = ) ) ] - , div [class "col-md-3"] [] + , div [ class "col-md-3" ] [] ] + + -- HTTP