We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

SnowdriftEvent.hs 2.54 KB
Newer Older
Mitchell Rosen's avatar
Mitchell Rosen committed
1 2 3 4 5 6
-- | Put all CSS for these widgets in templates/project_feed.cassius

module View.SnowdriftEvent where

import Import

7 8 9 10
import Model.User

import Data.Map ((!))

Mitchell Rosen's avatar
Mitchell Rosen committed
11
renderCommentPostedOnWikiPageEvent :: CommentId -> Comment -> Entity WikiPage -> Widget
12
renderCommentPostedOnWikiPageEvent comment_id comment (Entity _ wiki_page) =
Mitchell Rosen's avatar
Mitchell Rosen committed
13 14 15 16 17 18 19 20 21 22 23 24 25
    [whamlet|
        <div>On #{wikiPageTarget wiki_page}: #{commentText comment}
            \ <a href=@{CommentDirectLinkR comment_id}>(permalink)
    |]

-- This should really *never* be called, but it's included in case of nuclear meltdown.
renderCommentPostedOnUnknownDiscussionEvent :: CommentId -> Comment -> Widget
renderCommentPostedOnUnknownDiscussionEvent comment_id comment =
    [whamlet|
        <div>#{commentText comment}
            \ <a href=@{CommentDirectLinkR comment_id}>(permalink)
    |]

26 27 28 29 30 31 32
renderCommentPendingEvent :: CommentId -> Comment -> Widget
renderCommentPendingEvent comment_id comment =
    [whamlet|
        <div>Comment pending: #{commentText comment}
            \ <a href=@{CommentDirectLinkR comment_id}>(permalink)
    |]

33
renderWikiPageEvent :: WikiPageId -> WikiPage -> Widget
34
renderWikiPageEvent _ wiki_page =
35 36 37 38
    [whamlet|
        <div>Wiki page: #{wikiPageTarget wiki_page}
    |]

Mitchell Rosen's avatar
Mitchell Rosen committed
39
renderWikiEditEvent :: WikiEditId -> WikiEdit -> Entity WikiPage -> Widget
40
renderWikiEditEvent _ _ (Entity _ wiki_page) =
Mitchell Rosen's avatar
Mitchell Rosen committed
41 42 43
    [whamlet|
        <div>#{wikiPageTarget wiki_page} edit!
    |]
44

45
renderNewPledgeEvent :: SharesPledgedId -> SharesPledged -> UserMap -> Widget
46
renderNewPledgeEvent _ SharesPledged{..} users_map = do
47
    let pledger = users_map ! sharesPledgedUser
48
    [whamlet|
Mitchell Rosen's avatar
Mitchell Rosen committed
49
        <div>#{userDisplayName (Entity sharesPledgedUser pledger)} pledged #{show sharesPledgedShares} new shares!
50 51
    |]

52
renderUpdatedPledgeEvent :: Int64 -> SharesPledgedId -> SharesPledged -> UserMap -> Widget
53
renderUpdatedPledgeEvent old_shares _ SharesPledged{..} users_map = do
Mitchell Rosen's avatar
Mitchell Rosen committed
54 55 56 57
    let pledger      = users_map ! sharesPledgedUser
        (verb, punc) = if old_shares < sharesPledgedShares
                           then ("increased", "!")
                           else ("decreased", ".") :: (Text, Text)
58
    [whamlet|
Mitchell Rosen's avatar
Mitchell Rosen committed
59
        <div>#{userDisplayName (Entity sharesPledgedUser pledger)} #{verb} their pledge from #{show old_shares} to #{show sharesPledgedShares} shares#{punc}
60 61 62 63 64 65
    |]

renderDeletedPledgeEvent :: UserId -> Int64 -> UserMap -> Widget
renderDeletedPledgeEvent user_id shares users_map = do
    let pledger = users_map ! user_id
    [whamlet|
Mitchell Rosen's avatar
Mitchell Rosen committed
66
        <div>#{userDisplayName (Entity user_id pledger)} withdrew #{show shares} shares.
67
    |]