Use the magic of modeling to prevent double-loading images
This commit is contained in:
parent
95fc1b912e
commit
8a6eda1fed
|
@ -31,11 +31,13 @@ data ImageError
|
||||||
|
|
||||||
data ImageData
|
data ImageData
|
||||||
= Unloaded String -- file ID of encrypted data
|
= Unloaded String -- file ID of encrypted data
|
||||||
|
| Loading
|
||||||
| ILoaded String -- blob url of decrypted image
|
| ILoaded String -- blob url of decrypted image
|
||||||
| IError ImageError
|
| IError ImageError
|
||||||
|
|
||||||
instance showImageData :: Show ImageData where
|
instance showImageData :: Show ImageData where
|
||||||
show (Unloaded fileID) = "Unloaded Image with fileID " <> fileID
|
show (Unloaded fileID) = "Unloaded Image with fileID " <> fileID
|
||||||
|
show Loading = "Image loading..."
|
||||||
show (ILoaded url) = "image: " <> url
|
show (ILoaded url) = "image: " <> url
|
||||||
show (IError e) = "error loading image: " <> (show e)
|
show (IError e) = "error loading image: " <> (show e)
|
||||||
|
|
||||||
|
|
14
src/UI.purs
14
src/UI.purs
|
@ -64,7 +64,8 @@ renderThumbnail pos image =
|
||||||
maybe [] (backgroundUrl >>> HP.style >>> pure) (image.blurhashUrl)
|
maybe [] (backgroundUrl >>> HP.style >>> pure) (image.blurhashUrl)
|
||||||
)
|
)
|
||||||
case image.thumb of
|
case image.thumb of
|
||||||
Unloaded _ ->
|
Unloaded _ -> []
|
||||||
|
Loading ->
|
||||||
[ HH.span
|
[ HH.span
|
||||||
[ HP.class_ $ ClassName "loading-msg"
|
[ HP.class_ $ ClassName "loading-msg"
|
||||||
]
|
]
|
||||||
|
@ -124,7 +125,8 @@ renderFocused zoom image =
|
||||||
, HP.class_ $ ClassName "blurhash-frame"
|
, HP.class_ $ ClassName "blurhash-frame"
|
||||||
]
|
]
|
||||||
case image.full of
|
case image.full of
|
||||||
Unloaded _ ->
|
Unloaded _ -> []
|
||||||
|
Loading ->
|
||||||
[ HH.span
|
[ HH.span
|
||||||
[ HP.class_ $ ClassName "loading-msg"
|
[ HP.class_ $ ClassName "loading-msg"
|
||||||
]
|
]
|
||||||
|
@ -218,11 +220,15 @@ update' (Pan right) (GLoaded gal@{images, focus: Just { imageIndex }}) =
|
||||||
Both
|
Both
|
||||||
[ pure $ DownloadImage $ (offset + newImageIndex) ]
|
[ pure $ DownloadImage $ (offset + newImageIndex) ]
|
||||||
(GLoaded gal{ focus = Just {imageIndex: newImageIndex, zoom: false }})
|
(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)
|
let revisedIndex = mod indx (length images)
|
||||||
maybeImageData = index images revisedIndex in
|
maybeImageData = index images revisedIndex in
|
||||||
case maybeImageData of
|
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"
|
Nothing -> Modify $ GError $ UnexpectedError "Despite taking the modulo, still invalid index"
|
||||||
update' _ modl = Modify modl
|
update' _ modl = Modify modl
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue