From 40757cbe6a342fa3623cbb454085d0096ffded97 Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Wed, 16 Nov 2022 11:53:34 -0500 Subject: [PATCH] Fix UnexpectedError in image update event handling --- src/UI.purs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/UI.purs b/src/UI.purs index fd6aabc..f7c59aa 100644 --- a/src/UI.purs +++ b/src/UI.purs @@ -34,7 +34,7 @@ failCooldown :: Milliseconds failCooldown = Milliseconds 10000.0 data Event = LoadThumbs - | ImgLoaded Boolean Int ImageData -- isThumb, index, data + | ImgUpdate Boolean Int ImageData -- isThumb, index, data | Focus Int | Unfocus | Zoom @@ -179,10 +179,10 @@ setFull :: ImageData -> Int -> LoadedGallery -> Model setFull newImage = setImage \i -> i{full = newImage} fetchThumbAction :: Int -> Image -> Aff Event -fetchThumbAction position image = fetchThumb image <#> ImgLoaded true position +fetchThumbAction position image = fetchThumb image <#> ImgUpdate true position fetchFullAction :: Int -> Image -> Aff Event -fetchFullAction position image = fetchFull image <#> ImgLoaded false position +fetchFullAction position image = fetchFull image <#> ImgUpdate false position eventByKey :: KE.KeyboardEvent -> Maybe Event eventByKey ev = case KE.key ev of @@ -223,7 +223,7 @@ update' :: Event -> Model -> UpdateResult update' Init _ = Affect $ [RegisterListeners, LoadThumbs] <#> pure update' LoadThumbs (GLoaded {images}) = Affect $ mapWithIndex fetchThumbAction images -update' (ImgLoaded isThumb pos newData) (GLoaded gal) = +update' (ImgUpdate isThumb pos newData) (GLoaded gal) = let newGallery = (if isThumb then setThumb else setFull) newData pos gal updatedImage = case newGallery of (GLoaded {images}) -> index images pos @@ -234,10 +234,8 @@ update' (ImgLoaded isThumb pos newData) (GLoaded gal) = fetch pos img in case newData, updatedImage of (Retrying _ _), Just img -> Both [retryAction img] newGallery - (IError _), _ -> Modify newGallery - (ILoaded _), _ -> Modify newGallery _, Nothing -> Modify $ GError $ UnexpectedError $ "Suprising out of bound index!" - weirdData, _ -> Modify $ GError $ UnexpectedError $ "Strange newData passed in ImgLoaded event: " <> show weirdData <> " Please open an issue on our issue tracker!" + _, (Just _) -> Modify newGallery -- No fetch required update' (Focus imageIndex) (GLoaded gal) = Both ([DownloadImage >>> pure] <*> [imageIndex, imageIndex - 1, imageIndex + 1]) (GLoaded gal{ focus = Just { imageIndex, zoom: false } })