diff of 135d257737217b6770ff564ce383a56dc8b7743e

135d257737217b6770ff564ce383a56dc8b7743e
diff --git a/elm-frontti/src/Ajax_cmds.elm b/elm-frontti/src/Ajax_cmds.elm
index e260121..7d2845e 100644
--- a/elm-frontti/src/Ajax_cmds.elm
+++ b/elm-frontti/src/Ajax_cmds.elm
@@ -133,3 +133,9 @@ searchPreviouslyPosts search_term =
         { url = "/api/posts/search-previously"
         , body = Http.stringBody "application/json" search_term
         , expect = Http.expectJson PreviouslySearchResult (Json.list Article.previouslyDocDecoder)}
+
+
+loadPreviousArticle post_id =
+    Http.get
+        { url = "/api/posts/post/" ++ (String.fromInt post_id)
+        , expect = Http.expectJson PreviousPostReceived Article.articleDecoder}
diff --git a/elm-frontti/src/Main.elm b/elm-frontti/src/Main.elm
index 7aeb21a..937e042 100644
--- a/elm-frontti/src/Main.elm
+++ b/elm-frontti/src/Main.elm
@@ -127,6 +127,7 @@ port prompt : String -> Cmd msg
 port alert : String -> Cmd msg
 port showPreviousPostsModal: (() -> Cmd msg)
 port closePreviousPostsModal: (() -> Cmd msg)
+port showPreviousPostPreviewModal: (() -> Cmd msg)
 port tags : (String -> msg) -> Sub msg
 port aceStateUpdate : (String -> msg) -> Sub msg
 
@@ -238,7 +239,7 @@ update msg model =
             case result of
                 Ok post ->
                     ({ model | view_state = PostEditor
-                     , postEditorSettings = Just (PostEditorSettings post "" False)}
+                     , postEditorSettings = Just (PostEditorSettings post "" False Nothing)}
                     , Cmd.none)
                 Err error ->
                     ( model
@@ -542,8 +543,27 @@ update msg model =
             ({ model | settings = Maybe.map (\settings ->
                                                  { settings | previously_label = label})
                    model.settings}
-            , Cmd.none)                       
-            
+            , Cmd.none)
+        LoadPreviouslyPreview prev_article ->
+            ( model
+            , loadPreviousArticle prev_article.id )
+        PreviousPostReceived result ->
+            case result of
+                Ok article ->
+                    let postEditorSettings = model.postEditorSettings
+                    in
+                        ({ model
+                             | postEditorSettings = Maybe.map (\settings ->
+                                                                   { settings
+                                                                         | previewing_previously = Just article}) postEditorSettings}
+                        , showPreviousPostPreviewModal ())
+                Err err ->
+                    ( model
+                    , alert ("Failed to load a previosly-post with error: " ++ (errToString err)))
+        ClosePreviousPostPreviewModal ->
+            ( model
+            , closePreviousPostsModal ())
+
 doGoHome_ model other_cmds =
     (model, Cmd.batch (List.append [ getSettings
                                    , getTitles
diff --git a/elm-frontti/src/Message.elm b/elm-frontti/src/Message.elm
index 9c39456..67837cf 100644
--- a/elm-frontti/src/Message.elm
+++ b/elm-frontti/src/Message.elm
@@ -58,7 +58,8 @@ type alias MediaListState =
 type alias PostEditorSettings =
     { article : Article.Article
     , selected_tag : String
-    , show_preview : Bool}
+    , show_preview : Bool
+    , previewing_previously : Maybe Article.Article}
     
 type alias Model =
     { view_state : ViewState
@@ -138,6 +139,9 @@ type Msg
   | SelectPreviouslyPost Article.PreviousArticle
   | DropPreviously Article.PreviousArticle
   | SetPreviouslyLabel String
+  | LoadPreviouslyPreview Article.PreviousArticle
+  | PreviousPostReceived (Result Http.Error Article.Article)
+  | ClosePreviousPostPreviewModal
 
 -- ports
 port reallySetupAce : String -> Cmd msg
diff --git a/elm-frontti/src/PostEditor.elm b/elm-frontti/src/PostEditor.elm
index 98c99c7..411604e 100644
--- a/elm-frontti/src/PostEditor.elm
+++ b/elm-frontti/src/PostEditor.elm
@@ -59,12 +59,28 @@ filesDecoder : D.Decoder (List File)
 filesDecoder =
   D.at ["target","files"] (D.list File.decoder)
 
-previouslyButtons post loadedPosts =
+previously_row p
+    = li [] [ murja_button [ onClick (LoadPreviouslyPreview p) ] [ text p.title]
+            , button [ onClick (DropPreviously p)] [ text "X"]]
+
+previouslyButtons post loadedPosts previewingArticle article_settings =
+    let { app_settings, loginState , tz} = article_settings
+    in
     div [ class "previously-buttons" ]
         [ murja_button [ onClick ShowPreviousPostsModal ] [ text "Link previous posts"]
         , ul []
             ( post.previously
-            |> List.map (\p -> li [] [ text p.title, button [ onClick (DropPreviously p)] [ text "X"]]))
+            |> List.map previously_row)
+        , node "dialog" [ id "previewPreviouslyModal" ]
+            (case previewingArticle of
+                Just article ->
+                    [ div [ class "dialog" ]
+                          [ header [ class "previouslyHeader" ] [ button [ onClick ClosePreviousPostPreviewModal ] [ text "X"]]
+                          , case loginState of
+                                LoggedIn user ->
+                                    Article_view.articleView app_settings loginState tz article
+                                _ -> div [] [text "You're not logged in"]]]
+                Nothing -> [])
         , node "dialog" [ id "previouslyModal" ]
             [ div [ class "dialog" ]
                   [ header [ class "previouslyHeader" ] [ button [ onClick ClosePreviousPostsModel ] [ text "X"]]
@@ -97,7 +113,10 @@ postEditor post tag showImageModal loadedImages draggingImages editorSettings ap
                                  , onClick GetListOfImages]
                         [text "Insert image"]]
             , tagView post tag
-            , previouslyButtons post searchedPosts
+            , previouslyButtons post searchedPosts editorSettings.previewing_previously
+                { app_settings = app_settings
+                , loginState = loginState
+                , tz = tz }
             , div [ class "editor-grouper" ]
                 [ label [ for "hidden"]
                       [ text "Hidden article"]
diff --git a/resources/css/murja.css b/resources/css/murja.css
index 094259f..feefc04 100644
--- a/resources/css/murja.css
+++ b/resources/css/murja.css
@@ -92,7 +92,7 @@ html, body {
     width: 100%;
 }
 
-body {
+body, dialog {
     background-color: #000000;
     font-family: 'Helvetica Neue', Verdana, Helvetica, Arial, sans-serif;
     color: #00CC00;
diff --git a/resources/js/murja-helper.js b/resources/js/murja-helper.js
index 0006998..dd655e1 100644
--- a/resources/js/murja-helper.js
+++ b/resources/js/murja-helper.js
@@ -48,7 +48,13 @@ app.ports.showPreviousPostsModal.subscribe(_ => {
     document.getElementById('previouslyModal').showModal();
 });
 
+app.ports.showPreviousPostPreviewModal.subscribe(_ => {
+    document.getElementById('previewPreviouslyModal').showModal();
+});
+
 
 app.ports.closePreviousPostsModal.subscribe(_ => {
-    document.getElementById('previouslyModal').close();
+    document.querySelectorAll('dialog').forEach(dialog => {
+	dialog.close();
+    });
 });
diff --git a/src/posts/post-db.lisp b/src/posts/post-db.lisp
index dacda5d..d2ad49a 100644
--- a/src/posts/post-db.lisp
+++ b/src/posts/post-db.lisp
@@ -26,8 +26,10 @@
 	    (parse (gethash key post)))))
 
   (setf (gethash "previously" post)
-	(or 
-	 (remove-if-not #'hash-table-p (coerce (gethash "previously" post) 'list))
+	(or
+	 (remove-duplicates
+	  (remove-if-not #'hash-table-p (coerce (gethash "previously" post) 'list))
+	  :test 'equalp)
 	 #()))
 
   (setf (gethash "created_at" post)