Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
image-board-svelte
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Trirst
image-board-svelte
Commits
7b91a900
Commit
7b91a900
authored
Oct 21, 2021
by
Trirst
Browse files
Options
Downloads
Patches
Plain Diff
Image post editing
parent
9d8e1daf
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/routes/ImagePost.svelte
+66
-3
66 additions, 3 deletions
src/routes/ImagePost.svelte
with
66 additions
and
3 deletions
src/routes/ImagePost.svelte
+
66
−
3
View file @
7b91a900
...
@@ -9,6 +9,8 @@
...
@@ -9,6 +9,8 @@
let
addTag
=
false
;
let
addTag
=
false
;
let
tag
=
""
;
let
tag
=
""
;
let
originalComment
;
let
originalComment
;
let
form
;
let
edit
=
false
;
async
function
getImageMetadata
()
{
async
function
getImageMetadata
()
{
return
await
fetchAPI
(
paths
.
ImageField
(
params
.
snowflake
));
return
await
fetchAPI
(
paths
.
ImageField
(
params
.
snowflake
));
...
@@ -23,6 +25,20 @@
...
@@ -23,6 +25,20 @@
fetchAPI
(
paths
.
ImageTagField
(
params
.
snowflake
,
tag
),
options
);
fetchAPI
(
paths
.
ImageTagField
(
params
.
snowflake
,
tag
),
options
);
tag
=
""
;
tag
=
""
;
}
}
// Serialize image metada fields into JSON string that can be sent to API endpoints
function
serializeForm
(
form
)
{
return
JSON
.
stringify
(
Object
.
fromEntries
(
new
FormData
(
form
)));
}
async
function
updateImageMetadata
(
snowflake
,
metadata
)
{
const
options
=
{
method
:
"
PATCH
"
,
headers
:
{
secret
:
$user
.
secret
,
},
body
:
metadata
,
};
return
fetchAPI
(
paths
.
ImageField
(
snowflake
),
options
);
}
onMount
(
async
()
=>
{
onMount
(
async
()
=>
{
imageMetadata
=
await
getImageMetadata
();
imageMetadata
=
await
getImageMetadata
();
...
@@ -34,11 +50,15 @@
...
@@ -34,11 +50,15 @@
<div
class=
"pl-2"
>
<div
class=
"pl-2"
>
<ul>
<ul>
<li><strong>
Snowflake:
</strong>
{
imageMetadata
.
snowflake
}
</li>
<li><strong>
Snowflake:
</strong>
{
imageMetadata
.
snowflake
}
</li>
<li><strong>
Source:
</strong>
{
imageMetadata
.
source
}
</li>
<li>
<strong>
Source:
</strong>
<a
href=
{
imageMetadata
.
source
}
>
{
imageMetadata
.
source
}
</a>
</li>
<li><strong>
Image type:
</strong>
{
imageMetadata
.
type
}
</li>
<li><strong>
Image type:
</strong>
{
imageMetadata
.
type
}
</li>
<li><strong>
Uploaded by:
</strong>
{
imageMetadata
.
user
}
</li>
<li><strong>
Uploaded by:
</strong>
{
imageMetadata
.
user
}
</li>
</ul>
</ul>
<button
on:click=
{
()
=>
(
addTag
=
!
addTag
)
}
>
Add tag
</button>
<div><button
on:click=
{
()
=>
(
edit
=
!
edit
)
}
>
Edit
</button></div>
<div><button
on:click=
{
()
=>
(
addTag
=
!
addTag
)
}
>
Add tag
</button></div>
{
#if
addTag
}
{
#if
addTag
}
<div
class=
"space-x-2"
>
<div
class=
"space-x-2"
>
<input
type=
"text"
placeholder=
"Add tag"
bind:value=
{
tag
}
/>
<input
type=
"text"
placeholder=
"Add tag"
bind:value=
{
tag
}
/>
...
@@ -77,3 +97,46 @@
...
@@ -77,3 +97,46 @@
{
/if
}
{
/if
}
</div>
</div>
</div>
</div>
{
#if
edit
}
<form
class=
"flex flex-col flex-1 mx-16 my-4 space-y-6"
bind:this=
{
form
}
>
<input
type=
"text"
placeholder=
"Source"
name=
"source"
autocomplete=
"off"
bind:value=
{
imageMetadata
.
source
}
/>
<input
type=
"text"
placeholder=
"Parent"
name=
"parent"
autocomplete=
"off"
bind:value=
{
imageMetadata
.
parent
}
/>
<textarea
type=
"text"
placeholder=
"Commentary"
name=
"commentary"
autocomplete=
"off"
class=
"max-h-full resize-none flex-1"
bind:value=
{
imageMetadata
.
commentary
}
/>
<textarea
type=
"text"
placeholder=
"Commentary translation"
name=
"commentary_translation"
autocomplete=
"off"
class=
"max-h-full resize-none flex-1"
bind:value=
{
imageMetadata
.
commentary_translation
}
/>
<button
on:click
|
preventDefault=
{
()
=>
{
updateImageMetadata
(
imageMetadata
.
snowflake
,
serializeForm
(
form
)
);
edit
=
false
;
}
}
>
Submit
</button
>
</form>
{
/if
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment