diff --git a/Handler/Feed.hs b/Handler/Feed.hs index 1e5dfa4..4a7d298 100644 --- a/Handler/Feed.hs +++ b/Handler/Feed.hs @@ -5,9 +5,8 @@ module Handler.Feed import Import import Stackage.Database -import Data.These +import Data.These import Stackage.Snapshot.Diff -import qualified Data.HashMap.Strict as HashMap import Text.Blaze (text) getFeedR :: Handler TypedContent @@ -67,17 +66,17 @@ getContent sid2 snap = do Old New - $forall (name, VersionChange verChange) <- sortOn (toCaseFold . fst) $ HashMap.toList snapDiff + $forall (PackageName name, VersionChange change) <- toDiffList snapDiff #{name} - $case verChange - $of This oldVersion - #{oldVersion} + $case change + $of This (Version old) + #{old} - $of That newVersion + $of That (Version new) - #{newVersion} - $of These oldVersion newVersion - #{oldVersion} - #{newVersion} + #{new} + $of These (Version old) (Version new) + #{old} + #{new} |] diff --git a/Handler/StackageHome.hs b/Handler/StackageHome.hs index 7ee954d..c28130d 100644 --- a/Handler/StackageHome.hs +++ b/Handler/StackageHome.hs @@ -7,7 +7,6 @@ module Handler.StackageHome ) where import Import -import qualified Data.HashMap.Strict as HashMap import Data.These import Data.Time (FormatTime) import Stackage.Database diff --git a/Stackage/Snapshot/Diff.hs b/Stackage/Snapshot/Diff.hs index f041df4..eec4db2 100644 --- a/Stackage/Snapshot/Diff.hs +++ b/Stackage/Snapshot/Diff.hs @@ -2,7 +2,8 @@ module Stackage.Snapshot.Diff ( getSnapshotDiff , snapshotDiff - , SnapshotDiff + , SnapshotDiff() + , toDiffList , VersionChange(..) ) where @@ -13,10 +14,13 @@ import ClassyPrelude import Data.These import Stackage.Database (SnapshotId, PackageListingInfo(..), GetStackageDatabase, getPackages) -type PackageName = Text -type Version = Text +import Types -type SnapshotDiff = HashMap PackageName VersionChange +newtype SnapshotDiff + = SnapshotDiff { unSnapshotDiff :: HashMap PackageName VersionChange } + +toDiffList :: SnapshotDiff -> [(PackageName, VersionChange)] +toDiffList = sortOn (toCaseFold . unPackageName . fst) . HashMap.toList . unSnapshotDiff -- | Versions of a package as it occurs in the listings provided to `snapshotDiff`. -- @@ -32,6 +36,8 @@ getSnapshotDiff :: GetStackageDatabase m => SnapshotId -> SnapshotId -> m Snapsh getSnapshotDiff a b = snapshotDiff <$> getPackages a <*> getPackages b snapshotDiff :: [PackageListingInfo] -> [PackageListingInfo] -> SnapshotDiff -snapshotDiff as bs = HashMap.filter changed $ alignWith VersionChange (toMap as) (toMap bs) +snapshotDiff as bs = + SnapshotDiff $ HashMap.filter changed + $ alignWith VersionChange (toMap as) (toMap bs) where - toMap = HashMap.fromList . map (pliName &&& pliVersion) + toMap = HashMap.fromList . map (PackageName . pliName &&& Version . pliVersion) diff --git a/templates/stackage-diff.hamlet b/templates/stackage-diff.hamlet index 8197d95..d2b90b6 100644 --- a/templates/stackage-diff.hamlet +++ b/templates/stackage-diff.hamlet @@ -33,15 +33,15 @@ $else