MapComplete/src/UI/Image/UploadingImageCounter.svelte

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

89 lines
2.8 KiB
Svelte
Raw Normal View History

2023-09-28 23:50:27 +02:00
<script lang="ts">
2023-10-16 14:27:05 +02:00
/**
* Shows information about how much images are uploaded for the given feature
*
* Either pass in a store with tags or a featureId.
*/
2023-10-16 14:27:05 +02:00
import type { SpecialVisualizationState } from "../SpecialVisualization"
import { Store } from "../../Logic/UIEventSource"
import type { NoteId, OsmTags, OsmId } from "../../Models/OsmFeature"
2023-10-16 14:27:05 +02:00
import Translations from "../i18n/Translations"
import Tr from "../Base/Tr.svelte"
import Loading from "../Base/Loading.svelte"
import UploadFailedMessage from "./UploadFailedMessage.svelte"
2023-10-16 14:27:05 +02:00
export let state: SpecialVisualizationState
export let tags: Store<OsmTags> = undefined
export let featureId: OsmId | NoteId | "*" = tags?.data?.id ?? "*"
2023-12-19 22:08:00 +01:00
if (featureId === undefined) {
throw "No tags or featureID given"
}
2023-10-16 14:27:05 +02:00
export let showThankYou: boolean = true
/*
Number of images uploaded succesfully
*/
function getCount(input: Store<string[]>): Store<number> {
if (featureId == "*") {
2025-04-15 18:18:44 +02:00
return input.map((inp) => inp.length)
}
2025-04-15 18:18:44 +02:00
return input.map((success) => success.filter((item) => item === featureId).length)
}
let successfull = getCount(state.imageUploadManager.successfull)
/* Number of failed uploads */
let failed = getCount(state.imageUploadManager.fails)
let pending = getCount(state.imageUploadManager.queued)
2023-10-16 14:27:05 +02:00
const t = Translations.t.image
const debugging = state.featureSwitches.featureSwitchIsDebugging
let dismissed = 0
2025-04-15 18:18:44 +02:00
failed.addCallbackAndRun((failed) => {
dismissed = Math.min(failed, dismissed)
})
let progress = state.imageUploadManager.progressCurrentImage
</script>
{#if $debugging}
2024-04-13 02:40:21 +02:00
<div class="low-interaction">
Pending {$pending} Done {$successfull} Err {$failed}
2024-04-13 02:40:21 +02:00
</div>
{/if}
{#if $pending - $failed > 0}
<div class="alert">
<Loading>
2025-05-08 11:44:03 +02:00
<div class="flex w-full flex-col">
<div class="flex w-full justify-between gap-x-8">
{#if $pending - $failed === 1}
<Tr t={t.upload.one.uploading} />
{:else if $pending - $failed > 1}
<Tr t={t.upload.multiple.uploading.Subs({ count: $pending })} />
{/if}
{#if $progress !== undefined}
{$progress}%
{/if}
</div>
{#if $progress !== undefined}
2025-05-08 11:44:03 +02:00
<div class="low-interaction h-1 w-full overflow-hidden rounded-full">
<div class="h-1 bg-black" style={`width: calc(${$progress}%)`} />
</div>
{/if}
</div>
</Loading>
</div>
{/if}
{#if $failed > dismissed}
<UploadFailedMessage failed={$failed} on:click={() => (dismissed = $failed)} />
{/if}
{#if showThankYou}
{#if $successfull === 1}
<Tr cls="thanks" t={t.upload.one.done} />
{:else if $successfull > 1}
2025-04-15 18:18:44 +02:00
<Tr cls="thanks" t={t.upload.multiple.done.Subs({ count: $successfull })} />
{/if}
{/if}