Skip to content
Snippets Groups Projects
Commit 484f8cdb authored by Trirst's avatar Trirst
Browse files

Better hot updating after editing image metadata

parent cba5e7ba
Branches
No related tags found
No related merge requests found
...@@ -2,18 +2,19 @@ ...@@ -2,18 +2,19 @@
import { fetchAPI } from "@/static/js/helper"; import { fetchAPI } from "@/static/js/helper";
import { paths } from "@/static/js/paths"; import { paths } from "@/static/js/paths";
import { user } from "@/stores"; import { user } from "@/stores";
import { onMount } from "svelte";
export let params = {}; export let params = {};
let imageMetadata = {}; let imageMetadata = {};
let addTag = false; let addTag = false;
let tag = ""; let tag = "";
let originalComment;
let form; let form;
let edit = false; let edit = false;
async function getImageMetadata() { $: getImageMetadata(params.snowflake);
return await fetchAPI(paths.ImageField(params.snowflake)); $: originalComment = imageMetadata.commentary ? true : false;
async function getImageMetadata(snowflake) {
imageMetadata = await fetchAPI(paths.ImageField(snowflake));
} }
function imageTagAdd() { function imageTagAdd() {
const options = { const options = {
...@@ -39,11 +40,6 @@ ...@@ -39,11 +40,6 @@
}; };
return fetchAPI(paths.ImageField(snowflake), options); return fetchAPI(paths.ImageField(snowflake), options);
} }
onMount(async () => {
imageMetadata = await getImageMetadata();
originalComment = imageMetadata.commentary ? true : false;
});
</script> </script>
<svelte:head> <svelte:head>
...@@ -108,14 +104,14 @@ ...@@ -108,14 +104,14 @@
placeholder="Source" placeholder="Source"
name="source" name="source"
autocomplete="off" autocomplete="off"
bind:value={imageMetadata.source} value={imageMetadata.source}
/> />
<input <input
type="text" type="text"
placeholder="Parent" placeholder="Parent"
name="parent" name="parent"
autocomplete="off" autocomplete="off"
bind:value={imageMetadata.parent} value={imageMetadata.parent}
/> />
<textarea <textarea
type="text" type="text"
...@@ -123,7 +119,7 @@ ...@@ -123,7 +119,7 @@
name="commentary" name="commentary"
autocomplete="off" autocomplete="off"
class="max-h-full resize-none flex-1" class="max-h-full resize-none flex-1"
bind:value={imageMetadata.commentary} value={imageMetadata.commentary}
/> />
<textarea <textarea
type="text" type="text"
...@@ -131,14 +127,12 @@ ...@@ -131,14 +127,12 @@
name="commentary_translation" name="commentary_translation"
autocomplete="off" autocomplete="off"
class="max-h-full resize-none flex-1" class="max-h-full resize-none flex-1"
bind:value={imageMetadata.commentary_translation} value={imageMetadata.commentary_translation}
/> />
<button <button
on:click|preventDefault={() => { on:click|preventDefault={() => {
updateImageMetadata( updateImageMetadata(params.snowflake, serializeForm(form));
imageMetadata.snowflake, getImageMetadata(params.snowflake);
serializeForm(form)
);
edit = false; edit = false;
}}>Submit</button }}>Submit</button
> >
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment