diff of b56d8ee1d0b566911822b6385e377a407c381f2a
b56d8ee1d0b566911822b6385e377a407c381f2a
diff --git a/elm-frontti/src/Ajax_cmds.elm b/elm-frontti/src/Ajax_cmds.elm
index 016e786..57b7e00 100644
--- a/elm-frontti/src/Ajax_cmds.elm
+++ b/elm-frontti/src/Ajax_cmds.elm
@@ -54,28 +54,18 @@ getPostEditorData post_id =
{ url = "/api/posts/post/" ++ (String.fromInt post_id) ++ "/allow-hidden/true"
, expect = Http.expectJson EditorPostReceived Article.articleDecoder}
-postArticle : Article.Article -> Cmd Msg
-postArticle article =
- Http.post
- { url = "/api/posts/post"
- , body = Http.jsonBody <| Article.encode article
- , expect = Http.expectString HttpIgnoreResponse }
-
putArticle : Article.Article -> Cmd Msg
putArticle article =
- case article.id of
- Just id ->
- Http.request
- { method = "PUT"
- , headers = []
- , url = "/api/posts/post"
- , body = Http.jsonBody <| Article.encode article
- , expect = Http.expectString HttpGoHome
- , timeout = Nothing
- , tracker = Nothing
- }
- Nothing -> Cmd.none
-
+ Http.request
+ { method = "PUT"
+ , headers = []
+ , url = "/api/posts/post"
+ , body = Http.jsonBody <| Article.encode article
+ , expect = Http.expectString HttpGoHome
+ , timeout = Nothing
+ , tracker = Nothing
+ }
+
-- returns { :id :name }
getListOfImages : Bool -> Cmd Msg
getListOfImages managerCalled = Http.get
diff --git a/elm-frontti/src/Article.elm b/elm-frontti/src/Article.elm
index 86b6c12..533a048 100644
--- a/elm-frontti/src/Article.elm
+++ b/elm-frontti/src/Article.elm
@@ -42,7 +42,7 @@ type alias Article =
, comments : Maybe (List String)
-- , amount_of_comments : Int
, title : String
- , id : Maybe Int
+ , id : Int
, versions: Maybe (List Int)
, version : Maybe Int
, created_at: Maybe Time.Posix
@@ -61,7 +61,7 @@ encode article =
Just comments -> comments
Nothing -> [])))
, ( "title", string article.title)
- , ( "id", (maybe int) article.id)
+ , ( "id", int article.id)
, ( "version", (maybe int) article.version)
, ( "created_at", (maybe iso8601) article.created_at)
, ( "hidden", bool article.hidden)
@@ -77,7 +77,7 @@ contentDecoder = Decode.field "content" Decode.string
commentsDecoder = Decode.maybe (Decode.field "comments" (Decode.list Decode.string))
-- amount_of_commentsDecoder = Decode.field "amount-of-comments" Decode.int
titleDecoder = Decode.field "title" Decode.string
-idDecoder = Decode.maybe ( Decode.field "id" Decode.int)
+idDecoder = Decode.field "id" Decode.int
versionsDecoder = Decode.maybe (Decode.field "versions" (Decode.list Decode.int))
versionDecoder = Decode.maybe (Decode.field "version" Decode.int)
created_atDecoder = Decode.field "created_at" (Decode.maybe Extra.iso8601)
diff --git a/elm-frontti/src/Article_view.elm b/elm-frontti/src/Article_view.elm
index b252983..0a61041 100644
--- a/elm-frontti/src/Article_view.elm
+++ b/elm-frontti/src/Article_view.elm
@@ -17,34 +17,29 @@ formatDateTime formatString zone posixTime =
articleView settings loginstate zone the_actual_post =
let versions = Maybe.withDefault [] the_actual_post.versions
in
- div [class "post"] [ case the_actual_post.id of
- Just post_id -> a [href ("/blog/post/" ++ String.fromInt post_id)] [ text the_actual_post.title ]
- Nothing -> span [] [ text the_actual_post.title ]
- , div [class "meta"] (List.append [ User.user_avatar the_actual_post.creator
- , p [] [text ("By " ++ the_actual_post.creator.nickname)]
- , case the_actual_post.created_at of
- Just writing_time ->
- p [] [text ("Written at " ++ (formatDateTime settings.time_format zone writing_time))]
- Nothing ->
- p [] [text ("No idea when it's written")]]
- (case the_actual_post.id of
- Just post_id ->
- (List.map (\version -> a [ href ("/blog/post/" ++ String.fromInt post_id ++ "/version/" ++ String.fromInt version) ] [ text ((String.fromInt version) ++ ", ")]) versions)
- Nothing -> []))
+ div [class "post"] [ let post_id = the_actual_post.id in
+ a [href ("/blog/post/" ++ String.fromInt post_id)] [ text the_actual_post.title ]
+ , div [class "meta"] (List.append [ User.user_avatar the_actual_post.creator
+ , p [] [text ("By " ++ the_actual_post.creator.nickname)]
+ , case the_actual_post.created_at of
+ Just writing_time ->
+ p [] [text ("Written at " ++ (formatDateTime settings.time_format zone writing_time))]
+ Nothing ->
+ p [] [text ("No idea when it's written")]]
+ (let post_id = the_actual_post.id in
+ (List.map (\version -> a [ href ("/blog/post/" ++ String.fromInt post_id ++ "/version/" ++ String.fromInt version) ] [ text ((String.fromInt version) ++ ", ")]) versions)))
- , (case the_actual_post.id of
- Just post_id ->
- case loginstate of
- LoggedIn _ -> a [ href ("/blog/post/edit/" ++ String.fromInt post_id)
- , attribute "data-testid" "edit-post-btn"
- , onClick (OpenPostEditor post_id)] [text "Edit this post"]
- _ -> div [] []
- _ -> div [] [])
+ , (let post_id = the_actual_post.id in
+ case loginstate of
+ LoggedIn _ -> a [ href ("/blog/post/edit/" ++ String.fromInt post_id)
+ , attribute "data-testid" "edit-post-btn"
+ , onClick (OpenPostEditor post_id)] [text "Edit this post"]
+ _ -> div [] [])
- , article [ class "content"
- , dangerouslySetInnerHTML the_actual_post.content] []
- , div [] ( the_actual_post.tags
- |> List.filter ((/=) "")
- |> List.map ( \tag -> span [] [ a [ href ("/blog/tags/" ++ tag)
- , class "tag" ] [text tag]
- , text ", "]))]
+ , article [ class "content"
+ , dangerouslySetInnerHTML the_actual_post.content] []
+ , div [] ( the_actual_post.tags
+ |> List.filter ((/=) "")
+ |> List.map ( \tag -> span [] [ a [ href ("/blog/tags/" ++ tag)
+ , class "tag" ] [text tag]
+ , text ", "]))]
diff --git a/elm-frontti/src/Main.elm b/elm-frontti/src/Main.elm
index 8b647ce..fe216c3 100644
--- a/elm-frontti/src/Main.elm
+++ b/elm-frontti/src/Main.elm
@@ -269,10 +269,9 @@ update msg model =
HttpIgnoreResponse result ->
(model, Cmd.none)
SavePost article ->
- let new_post_p = article.id == Nothing in
doGoHome_
{ model | postEditorSettings = Nothing}
- [ if new_post_p then postArticle article else putArticle article ]
+ [ putArticle article ]
GoHome -> doGoHome model