Revert "Add some parsing stuff to finished/ for Tag"
This reverts commit 2bd0c78583.
This commit is contained in:
@@ -3,12 +3,15 @@ module Data.Article
|
||||
( Article
|
||||
, Body
|
||||
, Slug
|
||||
, Tag
|
||||
, bodyToHtml
|
||||
, bodyToMarkdownString
|
||||
, decoder
|
||||
, decoderWithBody
|
||||
, slugParser
|
||||
, slugToString
|
||||
, tagDecoder
|
||||
, tagToString
|
||||
)
|
||||
|
||||
import Data.Article.Author as Author exposing (Author)
|
||||
@@ -107,6 +110,24 @@ slugToString (Slug slug) =
|
||||
|
||||
|
||||
|
||||
-- TAGS --
|
||||
|
||||
|
||||
type Tag
|
||||
= Tag String
|
||||
|
||||
|
||||
tagToString : Tag -> String
|
||||
tagToString (Tag slug) =
|
||||
slug
|
||||
|
||||
|
||||
tagDecoder : Decoder Tag
|
||||
tagDecoder =
|
||||
Decode.map Tag Decode.string
|
||||
|
||||
|
||||
|
||||
-- BODY --
|
||||
|
||||
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
module Data.Article.Tag
|
||||
exposing
|
||||
( Tag
|
||||
, decoder
|
||||
, encode
|
||||
, listParser
|
||||
, toString
|
||||
)
|
||||
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Encode as Encode exposing (Value)
|
||||
import Parser exposing ((|.), (|=), Parser, end, ignore, keep, oneOrMore, repeat, zeroOrMore)
|
||||
|
||||
|
||||
type Tag
|
||||
= Tag String
|
||||
|
||||
|
||||
toString : Tag -> String
|
||||
toString (Tag str) =
|
||||
str
|
||||
|
||||
|
||||
encode : Tag -> Value
|
||||
encode (Tag str) =
|
||||
Encode.string str
|
||||
|
||||
|
||||
decoder : Decoder Tag
|
||||
decoder =
|
||||
Decode.map Tag Decode.string
|
||||
|
||||
|
||||
listParser : Parser (List Tag)
|
||||
listParser =
|
||||
Parser.succeed (List.map Tag)
|
||||
|. ignore zeroOrMore isWhitespace
|
||||
|= repeat zeroOrMore tag
|
||||
|. end
|
||||
|
||||
|
||||
|
||||
-- INTERNAL --
|
||||
|
||||
|
||||
tag : Parser String
|
||||
tag =
|
||||
keep oneOrMore (\char -> not (isWhitespace char))
|
||||
|. ignore zeroOrMore isWhitespace
|
||||
|
||||
|
||||
isWhitespace : Char -> Bool
|
||||
isWhitespace char =
|
||||
-- Treat hashtags and commas as effectively whitespace; ignore them.
|
||||
char == '#' || char == ',' || char == ' '
|
||||
@@ -1,7 +1,6 @@
|
||||
module Page.Article.Editor exposing (Model, Msg, initEdit, initNew, update, view)
|
||||
|
||||
import Data.Article as Article exposing (Article, Body)
|
||||
import Data.Article.Tag as Tag exposing (Tag)
|
||||
import Data.Session exposing (Session)
|
||||
import Data.User exposing (User)
|
||||
import Html exposing (..)
|
||||
@@ -9,7 +8,6 @@ import Html.Attributes exposing (attribute, class, defaultValue, disabled, href,
|
||||
import Html.Events exposing (onInput, onSubmit)
|
||||
import Http
|
||||
import Page.Errored exposing (PageLoadError, pageLoadError)
|
||||
import Parser
|
||||
import Request.Article
|
||||
import Route
|
||||
import Task exposing (Task)
|
||||
@@ -28,7 +26,7 @@ type alias Model =
|
||||
, title : String
|
||||
, body : String
|
||||
, description : String
|
||||
, tags : String
|
||||
, tags : List String
|
||||
, isSaving : Bool
|
||||
}
|
||||
|
||||
@@ -40,7 +38,7 @@ initNew =
|
||||
, title = ""
|
||||
, body = ""
|
||||
, description = ""
|
||||
, tags = ""
|
||||
, tags = []
|
||||
, isSaving = False
|
||||
}
|
||||
|
||||
@@ -62,7 +60,7 @@ initEdit session slug =
|
||||
, title = article.title
|
||||
, body = Article.bodyToMarkdownString article.body
|
||||
, description = article.description
|
||||
, tags = String.join " " article.tags
|
||||
, tags = article.tags
|
||||
, isSaving = False
|
||||
}
|
||||
)
|
||||
@@ -123,7 +121,7 @@ viewForm model =
|
||||
, Form.input
|
||||
[ placeholder "Enter tags"
|
||||
, onInput SetTags
|
||||
, defaultValue model.tags
|
||||
, defaultValue (String.join " " model.tags)
|
||||
]
|
||||
[]
|
||||
, button [ class "btn btn-lg pull-xs-right btn-primary", disabled model.isSaving ]
|
||||
@@ -154,24 +152,10 @@ update user msg model =
|
||||
[] ->
|
||||
case model.editingArticle of
|
||||
Nothing ->
|
||||
case Parser.run Tag.listParser model.tags of
|
||||
Ok tags ->
|
||||
let
|
||||
request =
|
||||
Request.Article.create
|
||||
{ tags = tags
|
||||
, title = model.title
|
||||
, body = model.body
|
||||
, description = model.description
|
||||
}
|
||||
user.token
|
||||
in
|
||||
request
|
||||
|> Http.send CreateCompleted
|
||||
|> pair { model | errors = [], isSaving = True }
|
||||
|
||||
Err _ ->
|
||||
( { model | errors = [ ( Tags, "Invalid tags." ) ] }, Cmd.none )
|
||||
user.token
|
||||
|> Request.Article.create model
|
||||
|> Http.send CreateCompleted
|
||||
|> pair { model | errors = [], isSaving = True }
|
||||
|
||||
Just slug ->
|
||||
user.token
|
||||
@@ -189,7 +173,7 @@ update user msg model =
|
||||
( { model | description = description }, Cmd.none )
|
||||
|
||||
SetTags tags ->
|
||||
( { model | tags = tags }, Cmd.none )
|
||||
( { model | tags = tagsFromString tags }, Cmd.none )
|
||||
|
||||
SetBody body ->
|
||||
( { model | body = body }, Cmd.none )
|
||||
@@ -233,7 +217,6 @@ type Field
|
||||
= Form
|
||||
| Title
|
||||
| Body
|
||||
| Tags
|
||||
|
||||
|
||||
type alias Error =
|
||||
@@ -252,6 +235,14 @@ modelValidator =
|
||||
-- INTERNAL --
|
||||
|
||||
|
||||
tagsFromString : String -> List String
|
||||
tagsFromString str =
|
||||
str
|
||||
|> String.split " "
|
||||
|> List.map String.trim
|
||||
|> List.filter (not << String.isEmpty)
|
||||
|
||||
|
||||
redirectToArticle : Article.Slug -> Cmd msg
|
||||
redirectToArticle =
|
||||
Route.modifyUrl << Route.Article
|
||||
|
||||
@@ -3,7 +3,7 @@ module Page.Home exposing (Model, Msg, init, update, view)
|
||||
{-| The homepage. You can get here via either the / or /#/ routes.
|
||||
-}
|
||||
|
||||
import Data.Article.Tag as Tag exposing (Tag)
|
||||
import Data.Article as Article exposing (Tag)
|
||||
import Data.Session exposing (Session)
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (attribute, class, classList, href, id, placeholder)
|
||||
@@ -100,7 +100,7 @@ viewTag tagName =
|
||||
, href "javascript:void(0)"
|
||||
, onClick (SelectTag tagName)
|
||||
]
|
||||
[ text (Tag.toString tagName) ]
|
||||
[ text (Article.tagToString tagName) ]
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -14,9 +14,8 @@ module Request.Article
|
||||
, update
|
||||
)
|
||||
|
||||
import Data.Article as Article exposing (Article, Body, slugToString)
|
||||
import Data.Article as Article exposing (Article, Body, Tag, slugToString)
|
||||
import Data.Article.Feed as Feed exposing (Feed)
|
||||
import Data.Article.Tag as Tag exposing (Tag)
|
||||
import Data.AuthToken exposing (AuthToken, withAuthorization)
|
||||
import Data.User as User exposing (Username)
|
||||
import Http
|
||||
@@ -69,7 +68,7 @@ defaultListConfig =
|
||||
|
||||
list : ListConfig -> Maybe AuthToken -> Http.Request Feed
|
||||
list config maybeToken =
|
||||
[ ( "tag", Maybe.map Tag.toString config.tag )
|
||||
[ ( "tag", Maybe.map Article.tagToString config.tag )
|
||||
, ( "author", Maybe.map User.usernameToString config.author )
|
||||
, ( "favorited", Maybe.map User.usernameToString config.favorited )
|
||||
, ( "limit", Just (toString config.limit) )
|
||||
@@ -115,7 +114,7 @@ feed config token =
|
||||
|
||||
tags : Http.Request (List Tag)
|
||||
tags =
|
||||
Decode.field "tags" (Decode.list Tag.decoder)
|
||||
Decode.field "tags" (Decode.list Article.tagDecoder)
|
||||
|> Http.get (apiUrl "/tags")
|
||||
|
||||
|
||||
@@ -170,7 +169,7 @@ type alias CreateConfig record =
|
||||
| title : String
|
||||
, description : String
|
||||
, body : String
|
||||
, tags : List Tag
|
||||
, tags : List String
|
||||
}
|
||||
|
||||
|
||||
@@ -195,7 +194,7 @@ create config token =
|
||||
[ ( "title", Encode.string config.title )
|
||||
, ( "description", Encode.string config.description )
|
||||
, ( "body", Encode.string config.body )
|
||||
, ( "tagList", Encode.list (List.map Tag.encode config.tags) )
|
||||
, ( "tagList", Encode.list (List.map Encode.string config.tags) )
|
||||
]
|
||||
|
||||
body =
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module Request.Article.Comments exposing (delete, list, post)
|
||||
|
||||
import Data.Article as Article exposing (Article, slugToString)
|
||||
import Data.Article as Article exposing (Article, Tag, slugToString)
|
||||
import Data.Article.Comment as Comment exposing (Comment, CommentId)
|
||||
import Data.AuthToken exposing (AuthToken, withAuthorization)
|
||||
import Http
|
||||
|
||||
@@ -16,9 +16,8 @@ overkill, so we use simpler APIs instead.
|
||||
|
||||
-}
|
||||
|
||||
import Data.Article as Article exposing (Article)
|
||||
import Data.Article as Article exposing (Article, Tag)
|
||||
import Data.Article.Feed exposing (Feed)
|
||||
import Data.Article.Tag as Tag exposing (Tag)
|
||||
import Data.AuthToken exposing (AuthToken)
|
||||
import Data.Session exposing (Session)
|
||||
import Data.User exposing (Username)
|
||||
@@ -127,7 +126,7 @@ sourceName source =
|
||||
"Global Feed"
|
||||
|
||||
TagFeed tagName ->
|
||||
"#" ++ Tag.toString tagName
|
||||
"#" ++ Article.tagToString tagName
|
||||
|
||||
FavoritedFeed username ->
|
||||
"Favorited Articles"
|
||||
|
||||
Reference in New Issue
Block a user