From ec56e74c980b7785989d41d904e4350c30fdf865 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Wed, 2 Nov 2022 16:08:29 +0000 Subject: [PATCH] cancelling previous page jobs when switch gallery pages --- .../kotlin/app/dapk/st/messenger/gallery/PageReducer.kt | 5 +++++ .../dapk/st/messenger/gallery/state/ImageGalleryReducer.kt | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/features/messenger/src/main/kotlin/app/dapk/st/messenger/gallery/PageReducer.kt b/features/messenger/src/main/kotlin/app/dapk/st/messenger/gallery/PageReducer.kt index d2e9dd0..b2b6c3d 100644 --- a/features/messenger/src/main/kotlin/app/dapk/st/messenger/gallery/PageReducer.kt +++ b/features/messenger/src/main/kotlin/app/dapk/st/messenger/gallery/PageReducer.kt @@ -38,3 +38,8 @@ sealed interface PageAction : Action { data class PageContainer

( val page: SpiderPage ) + +fun PageContainer<*>.isDifferentPage(page: SpiderPage<*>): Boolean { + return page::class != this.page::class +} + diff --git a/features/messenger/src/main/kotlin/app/dapk/st/messenger/gallery/state/ImageGalleryReducer.kt b/features/messenger/src/main/kotlin/app/dapk/st/messenger/gallery/state/ImageGalleryReducer.kt index f66b2e9..5820b06 100644 --- a/features/messenger/src/main/kotlin/app/dapk/st/messenger/gallery/state/ImageGalleryReducer.kt +++ b/features/messenger/src/main/kotlin/app/dapk/st/messenger/gallery/state/ImageGalleryReducer.kt @@ -56,4 +56,10 @@ private fun SharedStateScope, Unit>>.c dispatch(PageAction.UpdatePage(page.state.copy(content = Lce.Content(media)))) }) }, + + sideEffect(PageAction.GoTo::class) { action, _ -> + if (getSharedState().state1.isDifferentPage(action.page)) { + jobBag.cancel("page") + } + } )