Skip to content

Commit

Permalink
Full user ByAt
Browse files Browse the repository at this point in the history
  • Loading branch information
hojberg committed Aug 24, 2023
1 parent 6e67e9f commit d99d531
Showing 1 changed file with 43 additions and 11 deletions.
54 changes: 43 additions & 11 deletions src/UI/ByAt.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,67 @@
A small module to help consistently render when a user did something.
For example:
Release 2.1.3 - @hopper 2 days ago
╰─────────────────╯
This module renders that
Release 2.1.3 - (H) @hopper 2 days ago
╰──────────┬───────────╯
This module renders that
-}


module UI.ByAt exposing (ByAt, byAt, view)
module UI.ByAt exposing (ByAt, byAt, handleOnly, view)

import Html exposing (Html, span, strong, text)
import Html exposing (Html, span, text)
import Html.Attributes exposing (class)
import Html.Keyed as Keyed
import Lib.UserHandle as UserHandle exposing (UserHandle)
import UI.DateTime as DateTime exposing (DateTime)
import UI.ProfileSnippet as ProfileSnippet
import Url exposing (Url)


type ByAt
= ByAt UserHandle DateTime
type alias User u =
{ u
| handle : UserHandle
, name : Maybe String
, avatarUrl : Maybe Url
}


byAt : UserHandle -> DateTime -> ByAt
type ByAt u
= ByAt (User u) DateTime



-- CREATE


byAt : User u -> DateTime -> ByAt u
byAt =
ByAt


view : ByAt -> Html msg
handleOnly : UserHandle -> DateTime -> ByAt {}
handleOnly handle dateTime =
ByAt { handle = handle, name = Nothing, avatarUrl = Nothing } dateTime



-- VIEW


view : ByAt u -> Html msg
view (ByAt by at) =
let
handle =
UserHandle.toString by
UserHandle.toString by.handle

profileSnippet =
by
|> ProfileSnippet.profileSnippet
|> ProfileSnippet.small
|> ProfileSnippet.view

by_ =
( handle, profileSnippet )
in
{-
Q: Why is this using Keyed?
Expand All @@ -44,6 +76,6 @@ view (ByAt by at) =
-}
Keyed.node "div"
[ class "by-at" ]
[ ( handle, strong [] [ text handle ] )
[ by_
, ( DateTime.toISO8601 at, span [] [ DateTime.view DateTime.Distance at, text " ago" ] )
]

0 comments on commit d99d531

Please sign in to comment.