This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.

CommentModel

This library is a comments library similar to that found on social media sites.

Types

type CommentIdModel = CommentIdModel CommentId

Union Wrapped CommentId

type alias CommentModel = { commentId : CommentIdModel , user : UserCommentModel , message : String , showReplyInput : Bool , protoMessage : String , autoexpand : AutoExpand.State }

CommentModel

type CommentMsg = ClickReplyButton CommentIdModel | TextInput CommentIdModel { textValue : String, state : AutoExpand.State } | GenerateCommentId UserCommentModel CommentIdModel | ClearValue CommentIdModel | CommentRouting String | CommentLogin

Comment Messages

type alias UserCommentModel = { userId : UserIdModel , userFullName : String , picture : String }

UserModel for comments

type UserIdModel = UserIdModel String

Union Wrapped UserId

config : Bool -> CommentId -> AutoExpand.Config CommentMsg

Comment config: accepts a isSignedIn boolean flag and a parentCommentId

Inital values

commentInitState : AutoExpand.State

Initial comment state

commentModelInit : CommentModel

CommentModel initial value

commentTreeInit : Tree CommentModel

CommentTree initial value

commentZipperInit : Maybe (Zipper CommentModel)

Zipper initial value

module CommentModel
    exposing
        ( CommentIdModel(CommentIdModel)
        , CommentModel
        , CommentMsg(..)
        , UserCommentModel
        , UserIdModel(UserIdModel)
        , commentInitState
        , commentModelInit
        , commentTreeInit
        , commentZipperInit
        , config
        )

{-| This library is a comments library similar to that found on social media sites.


# Types

@docs CommentIdModel, CommentModel, CommentMsg, UserCommentModel, UserIdModel, config


# Inital values

@docs commentInitState, commentModelInit, commentTreeInit, commentZipperInit

-}

import AutoExpand
import Internal.CommentModel exposing (CommentId)
import MultiwayTree exposing (Tree)
import MultiwayTreeZipper exposing (Zipper)


commentOrLogin :
    Bool
    -> CommentId
    -> { state : AutoExpand.State, textValue : String }
    -> CommentMsg
commentOrLogin isSignedIn parentCommentId state =
    if isSignedIn == True then
        TextInput (CommentIdModel parentCommentId) state
    else
        CommentLogin


{-| Initial comment state
-}
commentInitState : AutoExpand.State
commentInitState =
    AutoExpand.initState <| config False ""


{-| Comment config: accepts a isSignedIn boolean flag and a parentCommentId
-}
config : Bool -> CommentId -> AutoExpand.Config CommentMsg
config isSignedIn parentCommentId =
    AutoExpand.config
        { onInput = commentOrLogin isSignedIn parentCommentId
        , padding = 10
        , lineHeight = 20
        , minRows = 1
        , maxRows = 4
        }
        |> AutoExpand.withStyles [ ( "font-family", "sans-serif" ) ]
        |> AutoExpand.withPlaceholder "Write a Comment"


{-| Comment Messages
-}
type CommentMsg
    = ClickReplyButton CommentIdModel
    | TextInput CommentIdModel { textValue : String, state : AutoExpand.State }
    | GenerateCommentId UserCommentModel CommentIdModel
    | ClearValue CommentIdModel
    | CommentRouting String
    | CommentLogin


{-| Union Wrapped UserId
-}
type UserIdModel
    = UserIdModel String


{-| UserModel for comments
-}
type alias UserCommentModel =
    { userId : UserIdModel
    , userFullName : String
    , picture : String
    }


{-| Union Wrapped CommentId
-}
type CommentIdModel
    = CommentIdModel CommentId


{-| CommentModel
-}
type alias CommentModel =
    { commentId : CommentIdModel
    , user : UserCommentModel
    , message : String
    , showReplyInput : Bool
    , protoMessage : String
    , autoexpand : AutoExpand.State
    }


{-| CommentModel initial value
-}
commentModelInit : CommentModel
commentModelInit =
    CommentModel (CommentIdModel "") userCommentModelInit "" False "" (AutoExpand.initState <| config False "")


userCommentModelInit : UserCommentModel
userCommentModelInit =
    UserCommentModel (UserIdModel "") "" ""


{-| CommentTree initial value
-}
commentTreeInit : Tree CommentModel
commentTreeInit =
    MultiwayTree.Tree commentModelInit []


{-| Zipper initial value
-}
commentZipperInit : Maybe (Zipper CommentModel)
commentZipperInit =
    Just ( commentTreeInit, [] )