({
loadingOptions,
totalDuration,
}: {
loadingOptions: LoadingOptions[];
totalDuration: number;
})
| 174 | } |
| 175 | |
| 176 | async function showSyncLoading({ |
| 177 | loadingOptions, |
| 178 | totalDuration, |
| 179 | }: { |
| 180 | loadingOptions: LoadingOptions[]; |
| 181 | totalDuration: number; |
| 182 | }): Promise<void> { |
| 183 | PageLoading.page.element.show().setStyle({ opacity: "0" }); |
| 184 | await PageLoading.page.beforeShow({}); |
| 185 | |
| 186 | const fillDivider = loadingOptions.length; |
| 187 | const fillOffset = 100 / fillDivider; |
| 188 | |
| 189 | //void here to run the loading promise as soon as possible |
| 190 | void PageLoading.page.element.promiseAnimate({ |
| 191 | opacity: "1", |
| 192 | duration: totalDuration / 2, |
| 193 | }); |
| 194 | |
| 195 | for (let i = 0; i < loadingOptions.length; i++) { |
| 196 | const currentOffset = fillOffset * i; |
| 197 | const options = loadingOptions[i] as LoadingOptions; |
| 198 | if (options.style === "bar") { |
| 199 | await PageLoading.showBar(); |
| 200 | if (i === 0) { |
| 201 | await PageLoading.updateBar(0, 0); |
| 202 | PageLoading.updateText(""); |
| 203 | } |
| 204 | } else { |
| 205 | PageLoading.showSpinner(); |
| 206 | } |
| 207 | |
| 208 | if (options.style === "bar") { |
| 209 | await getLoadingPromiseWithBarKeyframes( |
| 210 | options, |
| 211 | fillDivider, |
| 212 | currentOffset, |
| 213 | ); |
| 214 | void PageLoading.updateBar(100, 125); |
| 215 | PageLoading.updateText("Done"); |
| 216 | } else { |
| 217 | await options.loadingPromise(); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | await PageLoading.page.element.promiseAnimate({ |
| 222 | opacity: "0", |
| 223 | duration: totalDuration / 2, |
| 224 | }); |
| 225 | |
| 226 | await PageLoading.page.afterHide(); |
| 227 | PageLoading.page.element.hide(); |
| 228 | } |
| 229 | |
| 230 | // Global abort controller for keyframe promises |
| 231 | let keyframeAbortController: AbortController | null = null; |
no test coverage detected