diff --git a/src/Logic/ImageProviders/AllImageProviders.ts b/src/Logic/ImageProviders/AllImageProviders.ts index bfab05e343..457e37d5d2 100644 --- a/src/Logic/ImageProviders/AllImageProviders.ts +++ b/src/Logic/ImageProviders/AllImageProviders.ts @@ -90,6 +90,9 @@ export default class AllImageProviders { const allPrefixes = Utils.Dedup(prefixes ?? [].concat(...sources.map(s => s.defaultKeyPrefixes))) for (const prefix of allPrefixes) { for (const k in tags) { + if (!tags[k]) { + continue + } if (k === prefix || k.startsWith(prefix + ":")) { count++ continue diff --git a/src/UI/Image/DeletableImage.svelte b/src/UI/Image/DeletableImage.svelte index 3831621e03..1a3ce32998 100644 --- a/src/UI/Image/DeletableImage.svelte +++ b/src/UI/Image/DeletableImage.svelte @@ -18,6 +18,7 @@ import { DownloadIcon } from "@rgossiaux/svelte-heroicons/solid" import ChangeTagAction from "../../Logic/Osm/Actions/ChangeTagAction" import { Tag } from "../../Logic/Tags/Tag" + import { MenuState } from "../../Models/MenuState" export let image: ProvidedImage export let state: SpecialVisualizationState @@ -26,7 +27,7 @@ onDestroy( showDeleteDialog.addCallbackAndRunD((shown) => { if (shown) { - state.previewedImage.set(undefined) + MenuState.previewedImage.set(undefined) } }) ) @@ -53,18 +54,31 @@ issue: reportReason.data, sequence_id: imageInfo.collection, reporter_comments: (reportFreeText.data ?? "") + "\n\n" + "Reported from " + url, - reporter_email, + reporter_email }) reported.set(true) } async function unlink() { - await state?.changes?.applyAction( - new ChangeTagAction(tags.data.id, new Tag(image.key, ""), tags.data, { - changeType: "delete-image", - theme: state.theme.id, - }) - ) + console.log("Unlinking image", image.key, image.id) + if (image.id.length < 10) { + console.error("Suspicious value, not deleting ", image.id) + return + } + // The "key" is the provider key, but not necessarely the actual key that should be reset + // We iterate over all tags. *Every* tag for which the value contains the id will be deleted + const tgs = tags.data + for (const key in tgs) { + if (typeof tgs[key] !== "string" || tgs[key].indexOf(image.id) < 0) { + continue + } + + await state?.changes?.applyAction( + new ChangeTagAction(tgs.id, new Tag(key, ""), tgs, { + changeType: "delete-image", + theme: state.theme.id + })) + } } const t = Translations.t.image.panoramax @@ -161,7 +175,7 @@