2017-05-02 02:27:01 -04:00
|
|
|
module View.Common
|
|
|
|
exposing
|
2021-12-01 03:50:51 -05:00
|
|
|
( accountAcctView
|
|
|
|
, accountAvatar
|
2017-05-09 12:43:12 -04:00
|
|
|
, accountAvatarLink
|
2022-01-19 01:11:07 -05:00
|
|
|
, accountDisplayName
|
2022-03-30 01:18:18 -04:00
|
|
|
, accountDisplayNameRich
|
2017-05-02 02:27:01 -04:00
|
|
|
, accountLink
|
2021-01-10 17:09:11 -05:00
|
|
|
, accountLinkSmall
|
2021-01-11 19:12:13 -05:00
|
|
|
, accountLinkLarge
|
2021-12-01 03:50:51 -05:00
|
|
|
, instanceIconsView
|
2017-05-22 18:25:28 -04:00
|
|
|
, appLink
|
2017-05-02 02:27:01 -04:00
|
|
|
, closeablePanelheading
|
|
|
|
, icon
|
|
|
|
, justifiedButtonGroup
|
2017-05-05 11:26:49 -04:00
|
|
|
, loadMoreBtn
|
2017-05-12 16:41:11 -04:00
|
|
|
, confirmView
|
2017-06-01 06:01:13 -04:00
|
|
|
, formatDate
|
2017-05-02 02:27:01 -04:00
|
|
|
)
|
|
|
|
|
2017-06-01 06:01:13 -04:00
|
|
|
import Date
|
2021-01-11 17:55:40 -05:00
|
|
|
import Date.Extra.Config.Config_en_us as DateEn
|
2017-06-01 06:01:13 -04:00
|
|
|
import Date.Extra.Format as DateFormat
|
2017-05-02 02:27:01 -04:00
|
|
|
import Html exposing (..)
|
|
|
|
import Html.Attributes exposing (..)
|
2017-05-12 16:41:11 -04:00
|
|
|
import Html.Events exposing (..)
|
2017-05-05 17:35:54 -04:00
|
|
|
import Mastodon.Http exposing (Links)
|
2017-05-02 02:27:01 -04:00
|
|
|
import Mastodon.Model exposing (..)
|
|
|
|
import Types exposing (..)
|
|
|
|
import View.Events exposing (..)
|
2022-03-30 01:18:18 -04:00
|
|
|
import View.Formatter exposing (formatContent)
|
2017-05-02 02:27:01 -04:00
|
|
|
|
|
|
|
|
2017-05-09 12:43:12 -04:00
|
|
|
accountAvatar : String -> Account -> Html Msg
|
|
|
|
accountAvatar avatarClass account =
|
|
|
|
img [ class avatarClass, src account.avatar ] []
|
|
|
|
|
|
|
|
|
2021-12-01 03:50:51 -05:00
|
|
|
accountDisplayName : Account -> String
|
|
|
|
accountDisplayName account =
|
|
|
|
if account.display_name == "" then
|
|
|
|
account.username
|
|
|
|
else
|
|
|
|
account.display_name
|
|
|
|
|
|
|
|
|
2022-03-30 01:18:18 -04:00
|
|
|
accountDisplayNameRich : Account -> List (Html Msg)
|
|
|
|
accountDisplayNameRich account =
|
|
|
|
formatContent (accountDisplayName account) [] account.emojis
|
|
|
|
|
|
|
|
|
2017-05-03 09:08:10 -04:00
|
|
|
accountLink : Bool -> Account -> Html Msg
|
|
|
|
accountLink external account =
|
2021-12-01 03:50:51 -05:00
|
|
|
if external then
|
2017-05-03 09:08:10 -04:00
|
|
|
a
|
|
|
|
[ href account.url
|
2021-12-01 03:50:51 -05:00
|
|
|
, target "_blank"
|
|
|
|
]
|
|
|
|
[ text <| "@" ++ account.acct
|
|
|
|
, instanceIconsView <| account.url
|
|
|
|
]
|
|
|
|
else
|
|
|
|
a
|
|
|
|
[ href account.url
|
|
|
|
, href <| "#account/" ++ account.id
|
|
|
|
]
|
2022-03-30 01:18:18 -04:00
|
|
|
[ span [ class "display-name" ] <| accountDisplayNameRich account
|
2021-12-01 03:50:51 -05:00
|
|
|
, accountAcctView False account
|
2017-05-03 09:08:10 -04:00
|
|
|
]
|
2017-05-02 02:27:01 -04:00
|
|
|
|
|
|
|
|
2021-01-10 17:09:11 -05:00
|
|
|
accountLinkSmall : Bool -> Account -> Html Msg
|
|
|
|
accountLinkSmall external account =
|
|
|
|
let
|
|
|
|
accountHref =
|
|
|
|
if external then
|
|
|
|
target "_blank"
|
|
|
|
else
|
|
|
|
href <| "#account/" ++ account.id
|
|
|
|
in
|
|
|
|
a
|
|
|
|
[ href account.url
|
|
|
|
, accountHref
|
|
|
|
]
|
2022-03-30 01:18:18 -04:00
|
|
|
[ span [ class "display-name" ] <| accountDisplayNameRich account
|
2021-01-10 17:09:11 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2021-01-11 19:12:13 -05:00
|
|
|
accountLinkLarge : Bool -> Account -> Html Msg
|
|
|
|
accountLinkLarge external account =
|
|
|
|
let
|
|
|
|
accountHref =
|
|
|
|
if external then
|
|
|
|
target "_blank"
|
|
|
|
else
|
|
|
|
href <| "#account/" ++ account.id
|
|
|
|
in
|
|
|
|
a
|
|
|
|
[ href <| "#account/" ++ account.id
|
|
|
|
]
|
2022-03-30 01:18:18 -04:00
|
|
|
[ span [ class "display-name" ] <| accountDisplayNameRich account
|
2021-01-11 19:12:13 -05:00
|
|
|
, br [] []
|
2021-12-01 03:50:51 -05:00
|
|
|
, accountAcctView True account
|
2021-01-11 19:12:13 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2021-12-01 03:50:51 -05:00
|
|
|
instanceIconsView : String -> Html Msg
|
|
|
|
instanceIconsView url =
|
|
|
|
let
|
|
|
|
instUrl = String.join "/" ( List.take 3 ( String.split "/" url ) )
|
|
|
|
instIcon = img [ class "acct-instance-icon", src ( instUrl ++ "/favicon.png" ), alt "" ] []
|
|
|
|
instIcon2 = img [ class "acct-instance-icon", src ( instUrl ++ "/favicon.ico" ), alt "" ] []
|
|
|
|
in
|
|
|
|
span [] [ instIcon, instIcon2 ]
|
|
|
|
|
|
|
|
|
|
|
|
accountAcctView : Bool -> Account -> Html Msg
|
|
|
|
accountAcctView showIcons account =
|
|
|
|
let
|
2022-01-19 01:11:07 -05:00
|
|
|
acctText = text <| "@" ++ account.acct
|
2021-12-01 03:50:51 -05:00
|
|
|
icons =
|
|
|
|
if showIcons then
|
|
|
|
instanceIconsView <| account.url
|
|
|
|
else
|
|
|
|
text ""
|
|
|
|
in
|
|
|
|
span [ class "acct" ] [ acctText, icons ]
|
|
|
|
|
|
|
|
|
2017-05-03 09:08:10 -04:00
|
|
|
accountAvatarLink : Bool -> Account -> Html Msg
|
|
|
|
accountAvatarLink external account =
|
|
|
|
let
|
|
|
|
accountHref =
|
|
|
|
if external then
|
|
|
|
target "_blank"
|
|
|
|
else
|
2017-11-29 08:06:08 -05:00
|
|
|
href <| "#account/" ++ account.id
|
2017-05-03 09:08:10 -04:00
|
|
|
|
2021-01-10 14:45:01 -05:00
|
|
|
avatarClass = "avatar"
|
2017-05-03 09:08:10 -04:00
|
|
|
in
|
|
|
|
a
|
|
|
|
[ href account.url
|
|
|
|
, accountHref
|
|
|
|
, title <| "@" ++ account.username
|
|
|
|
]
|
2017-05-09 12:43:12 -04:00
|
|
|
[ accountAvatar avatarClass account ]
|
2017-05-02 02:27:01 -04:00
|
|
|
|
|
|
|
|
2017-05-22 18:25:28 -04:00
|
|
|
appLink : String -> Maybe Application -> Html Msg
|
|
|
|
appLink classes app =
|
|
|
|
case app of
|
|
|
|
Nothing ->
|
|
|
|
text ""
|
|
|
|
|
|
|
|
Just { name, website } ->
|
|
|
|
case website of
|
|
|
|
Nothing ->
|
|
|
|
span [ class classes ] [ text name ]
|
|
|
|
|
|
|
|
Just website ->
|
|
|
|
a [ href website, target "_blank", class classes ] [ text name ]
|
|
|
|
|
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
closeablePanelheading : String -> String -> String -> Html Msg
|
|
|
|
closeablePanelheading context iconName label =
|
2017-05-02 02:27:01 -04:00
|
|
|
div [ class "panel-heading" ]
|
|
|
|
[ div [ class "row" ]
|
|
|
|
[ a
|
|
|
|
[ href "", onClickWithPreventAndStop <| ScrollColumn ScrollTop context ]
|
|
|
|
[ div [ class "col-xs-9 heading" ] [ icon iconName, text label ] ]
|
|
|
|
, div [ class "col-xs-3 text-right" ]
|
|
|
|
[ a
|
2017-05-29 10:28:01 -04:00
|
|
|
[ href "", onClickWithPreventAndStop Back ]
|
2017-05-02 02:27:01 -04:00
|
|
|
[ icon "remove" ]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
icon : String -> Html Msg
|
|
|
|
icon name =
|
|
|
|
i [ class <| "glyphicon glyphicon-" ++ name ] []
|
|
|
|
|
|
|
|
|
2017-05-03 11:24:31 -04:00
|
|
|
justifiedButtonGroup : String -> List (Html Msg) -> Html Msg
|
|
|
|
justifiedButtonGroup cls buttons =
|
|
|
|
div [ class <| "btn-group btn-group-justified " ++ cls ] <|
|
2017-05-02 02:27:01 -04:00
|
|
|
List.map (\b -> div [ class "btn-group" ] [ b ]) buttons
|
2017-05-05 11:26:49 -04:00
|
|
|
|
|
|
|
|
2017-05-06 05:38:56 -04:00
|
|
|
loadMoreBtn : { timeline | id : String, links : Links, loading : Bool } -> Html Msg
|
|
|
|
loadMoreBtn { id, links, loading } =
|
|
|
|
if loading then
|
|
|
|
li [ class "list-group-item load-more text-center" ]
|
|
|
|
[ text "Loading..." ]
|
|
|
|
else
|
|
|
|
case links.next of
|
|
|
|
Just next ->
|
2017-05-07 03:58:17 -04:00
|
|
|
a
|
|
|
|
[ class "list-group-item load-more text-center"
|
|
|
|
, href next
|
|
|
|
, onClickWithPreventAndStop <| TimelineLoadNext id next
|
2017-05-05 11:26:49 -04:00
|
|
|
]
|
2017-05-07 03:58:17 -04:00
|
|
|
[ text "Load more" ]
|
2017-05-05 11:26:49 -04:00
|
|
|
|
2017-05-06 05:38:56 -04:00
|
|
|
Nothing ->
|
|
|
|
text ""
|
2017-05-12 16:41:11 -04:00
|
|
|
|
|
|
|
|
|
|
|
confirmView : Confirm -> Html Msg
|
|
|
|
confirmView { message, onConfirm, onCancel } =
|
|
|
|
div []
|
|
|
|
[ div [ class "modal-backdrop" ] []
|
|
|
|
, div
|
|
|
|
[ class "modal fade in", style [ ( "display", "block" ) ], tabindex -1 ]
|
|
|
|
[ div
|
|
|
|
[ class "modal-dialog" ]
|
|
|
|
[ div
|
|
|
|
[ class "modal-content" ]
|
|
|
|
[ div [ class "modal-header" ] [ h4 [] [ text "Confirmation required" ] ]
|
|
|
|
, div [ class "modal-body" ] [ p [] [ text message ] ]
|
|
|
|
, div
|
|
|
|
[ class "modal-footer" ]
|
|
|
|
[ button
|
|
|
|
[ type_ "button", class "btn btn-default", onClick (ConfirmCancelled onCancel) ]
|
|
|
|
[ text "Cancel" ]
|
|
|
|
, button
|
|
|
|
[ type_ "button", class "btn btn-primary", onClick (Confirmed onConfirm) ]
|
|
|
|
[ text "OK" ]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
2017-06-01 06:01:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
formatDate : String -> String
|
|
|
|
formatDate dateString =
|
|
|
|
Date.fromString dateString
|
|
|
|
|> Result.withDefault (Date.fromTime 0)
|
2021-01-11 17:55:40 -05:00
|
|
|
|> DateFormat.format DateEn.config "%Y-%m-%d %H:%M"
|