<commit_before>module Main exposing (..)

import Html exposing (..)
import Html.Attributes exposing (type_)
import Html.Events exposing (..)
import Http exposing (post)
import Json.Decode as Decode


---- MODEL ----


type alias Model =
    { post : Post
    , form : String
    }


type alias Post =
    { userId : Int
    , id : Int
    , title : String
    , body : String
    }


initialPost : Post
initialPost =
    { userId = 0
    , id = 0
    , title = "null"
    , body = "null"
    }


init : ( Model, Cmd Msg )
init =
    ( { post = initialPost, form = "" }, Cmd.none )



---- UPDATE ----


type Msg
    = GetPost
    | LoadPost (Result Http.Error Post)
    | Input String


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        GetPost ->
            ( model, sendRequest model.form )

        LoadPost (Ok post) ->
            ( { model | post = post }, Cmd.none )

        LoadPost (Err _) ->
            ( model, Cmd.none )

        Input string ->
            ( { model | form = string }, Cmd.none )


getPost : String -> Http.Request Post
getPost id =
    let
        url =
            "https://jsonplaceholder.typicode.com/posts/" ++ id
    in
    Http.get url decodePost


decodePost : Decode.Decoder Post
decodePost =
    Decode.map4 Post
        (Decode.field "userId" Decode.int)
        (Decode.field "id" Decode.int)
        (Decode.field "title" Decode.string)
        (Decode.field "body" Decode.string)


sendRequest : String -> Cmd Msg
sendRequest id =
    Http.send LoadPost (getPost id)



---- VIEW ----


view : Model -> Html Msg
view model =
    div
        []
        [ p
            []
            [ text <| "userId: " ++ toString model.post.userId ]
        , p
            []
            [ text <| "id: " ++ toString model.post.id ]
        , p
            []
            [ text <| "title: " ++ model.post.title ]
        , p
            []
            [ text <| "body: " ++ model.post.body ]
        , p
            []
            [ text <| "form: " ++ model.form ]
        , input
            [ type_ "text", onInput Input ]
            []
        , button
            [ onClick GetPost ]
            [ text "Get Post" ]
        ]



---- PROGRAM ----


main : Program Never Model Msg
main =<commit_msg>:+1: Split view functions<commit_after>module Main exposing (..)

import Html exposing (..)
import Html.Attributes exposing (type_)
import Html.Events exposing (..)
import Http exposing (post)
import Json.Decode as Decode


---- MODEL ----


type alias Model =
    { post : Post
    , form : String
    }


type alias Post =
    { userId : Int
    , id : Int
    , title : String
    , body : String
    }


initialPost : Post
initialPost =
    { userId = 0
    , id = 0
    , title = "null"
    , body = "null"
    }


init : ( Model, Cmd Msg )
init =
    ( { post = initialPost, form = "" }, Cmd.none )



---- UPDATE ----


type Msg
    = GetPost
    | LoadPost (Result Http.Error Post)
    | Input String


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        GetPost ->
            ( model, sendRequest model.form )

        LoadPost (Ok post) ->
            ( { model | post = post }, Cmd.none )

        LoadPost (Err _) ->
            ( model, Cmd.none )

        Input string ->
            ( { model | form = string }, Cmd.none )


getPost : String -> Http.Request Post
getPost id =
    let
        url =
            "https://jsonplaceholder.typicode.com/posts/" ++ id
    in
    Http.get url decodePost


decodePost : Decode.Decoder Post
decodePost =
    Decode.map4 Post
        (Decode.field "userId" Decode.int)
        (Decode.field "id" Decode.int)
        (Decode.field "title" Decode.string)
        (Decode.field "body" Decode.string)


sendRequest : String -> Cmd Msg
sendRequest id =
    Http.send LoadPost (getPost id)



---- VIEW ----


view : Model -> Html Msg
view model =
    div
        []
        [ postView model.post
        , input
            [ type_ "text", onInput Input ]
            []
        , p
            []
            [ text <| "form: " ++ model.form ]
        , button
            [ onClick GetPost ]
            [ text "Get Post" ]
        ]


postView : Post -> Html Msg
postView post =
    div []
        [ p
            []
            [ text <| "userId: " ++ toString post.userId ]
        , p
            []
            [ text <| "id: " ++ toString post.id ]
        , p
            []
            [ text <| "title: " ++ post.title ]
        , p
            []
            [ text <| "body: " ++ post.body ]
        ]



---- PROGRAM ----


main : Program Never Model Msg
main =
{'fraction_non_alphanumeric': 0.13025663144274316, 'fraction_numerical': 0.0015095967220185465, 'mean_word_length': 1.4657097288676235, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 22, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4797085', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1426, 'n_words': 398}