@@ -16,12 +16,14 @@ import Control.Monad.Reader (runReaderT)
1616import Data.Argonaut (class DecodeJson)
1717import Data.Array as Array
1818import Data.Clipboard as Clipboard
19+import Data.DateTime (DateTime)
1920import Data.Either (Either(..))
2021import Data.JNullable (fromJNullable, jnull, nullify)
2122import Data.JNullable as JNullable
2223import Data.JOpt (fromJOpt)
2324import Data.Maybe (Maybe(..))
2425import Data.OpenURL (openURL)
26+import Data.Ord.Down (Down(..))
2527import Data.SymmetricCryptoKey (SymmetricCryptoKey)
2628import Data.Timestamp as Timestamp
2729import Data.Traversable (traverse)
@@ -93,8 +95,8 @@ main = do
9395 Bridge.NeedCiphersList -> run do
9496 sync <- getOrReset storage SyncKey
9597 ciphers <- traverse processCipher sync.ciphers
96− liftEffect $ Elm.send app $ Bridge.LoadCiphers $ Bridge.Sub_LoadCiphers_List ciphers
97− api <- getAuthedApi
98+ let sortedCiphers = Array.sortWith (_.date >>> Down) ciphers
99+ liftEffect $ Elm.send app $ Bridge.LoadCiphers $ Bridge.Sub_LoadCiphers_List $ map _.cipher sortedCiphers
98100 liftEffect $ Storage.store storage SyncKey sync
99101 pure unit
100102 Bridge.NeedsReset -> do
@@ -243,7 +245,7 @@ processCipher ::
243245 forall r.
244246 HasL "crypto" CryptoService r =>
245247 HasL "key" SymmetricCryptoKey r =>
246− CipherResponse -> Al r Bridge.Sub_LoadCiphers
248+ CipherResponse -> Al r {cipher :: Bridge.Sub_LoadCiphers, date :: DateTime}
247249processCipher cipher = do
248250 name <- decrypt cipher.name
249251 cipherType <- case cipher.type of
@@ -252,13 +254,16 @@ processCipher cipher = do
252254 n | n == cipherTypeCard -> pure Bridge.CardType
253255 n | n == cipherTypeIdentity -> pure Bridge.IdentityType
254256 n -> throwError $ error $ "Unsupported cipher type: " <> show n
257+ date <- liftEffect $ Timestamp.toDateTime cipher.revisionDate
255258 pure
256− $ Bridge.Sub_LoadCiphers
259+ $ {cipher: Bridge.Sub_LoadCiphers
257260 { name: name
258261 , date: Timestamp.toLocalDateTimeString cipher.revisionDate
259262 , id: cipher.id
260263 , cipherType
261264 }
265+ , date
266+ }
262267
263268runElmAff :: FFI.Elm -> Aff Unit -> Effect Unit
264269runElmAff app =