Use the magic of modeling to prevent double-loading images

This commit is contained in:
Emi Simpson 2022-11-15 21:01:45 -05:00
parent 95fc1b912e
commit 8a6eda1fed
Signed by: Emi
GPG Key ID: A12F2C2FFDC3D847
2 changed files with 12 additions and 4 deletions

View File

@ -31,11 +31,13 @@ data ImageError
data ImageData
= Unloaded String -- file ID of encrypted data
| Loading
| ILoaded String -- blob url of decrypted image
| IError ImageError
instance showImageData :: Show ImageData where
show (Unloaded fileID) = "Unloaded Image with fileID " <> fileID
show Loading = "Image loading..."
show (ILoaded url) = "image: " <> url
show (IError e) = "error loading image: " <> (show e)

View File

@ -64,7 +64,8 @@ renderThumbnail pos image =
maybe [] (backgroundUrl >>> HP.style >>> pure) (image.blurhashUrl)
)
case image.thumb of
Unloaded _ ->
Unloaded _ -> []
Loading ->
[ HH.span
[ HP.class_ $ ClassName "loading-msg"
]
@ -124,7 +125,8 @@ renderFocused zoom image =
, HP.class_ $ ClassName "blurhash-frame"
]
case image.full of
Unloaded _ ->
Unloaded _ -> []
Loading ->
[ HH.span
[ HP.class_ $ ClassName "loading-msg"
]
@ -218,11 +220,15 @@ update' (Pan right) (GLoaded gal@{images, focus: Just { imageIndex }}) =
Both
[ pure $ DownloadImage $ (offset + newImageIndex) ]
(GLoaded gal{ focus = Just {imageIndex: newImageIndex, zoom: false }})
update' (DownloadImage indx) (GLoaded { images }) =
update' (DownloadImage indx) (GLoaded gal@{ images }) =
let revisedIndex = mod indx (length images)
maybeImageData = index images revisedIndex in
case maybeImageData of
Just imageData -> Affect [fetchFullAction revisedIndex imageData]
Just imageData -> case modifyAt revisedIndex _{full = Loading} images of
Just newImages -> Both
[fetchFullAction revisedIndex imageData]
(GLoaded gal{ images = newImages })
Nothing -> Modify $ GError $ UnexpectedError "Valid position asserted by index and module declared invalid by index"
Nothing -> Modify $ GError $ UnexpectedError "Despite taking the modulo, still invalid index"
update' _ modl = Modify modl