From 1e260f0dab8f86f1d9c0d4c9e5285c0e24d0bbb1 Mon Sep 17 00:00:00 2001 From: Justin Maximillian Kimlim Date: Tue, 23 Jul 2024 01:13:47 +0700 Subject: [PATCH] feat: inline-editing for tags, links and working capacity --- .../pubpage-admin/edit-links.svelte | 31 ++++ src/lib/themes/minimal.svelte | 132 +++++++++++++----- 2 files changed, 131 insertions(+), 32 deletions(-) create mode 100644 src/lib/components/pubpage-admin/edit-links.svelte diff --git a/src/lib/components/pubpage-admin/edit-links.svelte b/src/lib/components/pubpage-admin/edit-links.svelte new file mode 100644 index 00000000..e97fb4d8 --- /dev/null +++ b/src/lib/components/pubpage-admin/edit-links.svelte @@ -0,0 +1,31 @@ + + +{#if open} + +
+
+ +

+ Edit tags +

+
+
+ + + + +
+
+
+{/if} diff --git a/src/lib/themes/minimal.svelte b/src/lib/themes/minimal.svelte index 09755dbf..a6359d87 100644 --- a/src/lib/themes/minimal.svelte +++ b/src/lib/themes/minimal.svelte @@ -2,6 +2,12 @@ import type { Profile } from '../../routes/(app)/auth/v1/account/proxy+page.server'; import { env } from '$env/dynamic/public'; import AvatarEditor from '$lib/components/avatar/editor.svelte'; + import EditLinks from '$lib/components/pubpage-admin/edit-links.svelte'; + + let editingTags = false; + let linkLabel = ''; + let linkUrl = ''; + export let profile: Profile; export let token; export let is_author; @@ -29,16 +35,6 @@ return 'Not Specified'; } }; - const ShortDescription = () => { - return [ - profile.username, - printWorkCapacity(profile.work_capacity), - printWorkCompensation(profile.work_compensation), - profile.location - ] - .filter(Boolean) - .join(' • '); - }; let initialLoaded = true; let unsavedChanges = false; @@ -63,10 +59,10 @@ const formData = new FormData(); for (const key in profile) { if (key === 'links') { - const keyUrls = profile[key]?.map((link) => link.url); - const keyLabels = profile[key]?.map((link) => link.label); - formData.append('link-url', keyUrls); - formData.append('link-label', keyLabels); + profile[key]?.forEach((link) => { + formData.append('link-url', link.url); + formData.append('link-label', link.label); + }); } formData.append(key, profile[key]); } @@ -89,6 +85,28 @@ console.log(err); }); }; + + const editLinkCallback = (label: string, url: string) => { + editingTags = false; + unsavedChanges = true; + profile.links = profile.links.map((link) => { + if (link.label === linkLabel && link.url === linkUrl) { + link.url = url; + link.label = label; + } + return link; + }); + if (linkLabel === '' && linkUrl === '') { + profile.links.push({ label, url }); + } + }; + const addTags = () => { + profile.tags = profile.tags || []; + profile.tags.push('(newly added tag)'); + }; + const deleteTag = (tag: string) => { + profile.tags = profile.tags.filter((t) => t !== tag); + }; @@ -108,6 +126,7 @@ /> {/if}
+ {#if is_author}
@@ -151,8 +170,26 @@ {/if} {profile.username} • - {printWorkCompensation(profile.work_compensation)} • - {printWorkCapacity(profile.work_capacity)} • + {#if env.PUBLIC_SHOW_WORK_CAPACITY == 'true'} + {#if is_author} + + {:else} + {printWorkCompensation(profile.work_compensation)} • + {/if} + {#if is_author} + + {:else} + {printWorkCapacity(profile.work_capacity)} • + {/if} + {/if} {#if is_author} {:else} @@ -161,20 +198,40 @@ {#if profile.bio} @@ -190,24 +247,32 @@ {/if} {#if profile.tags && profile.tags.length > 0} -
+
{#each profile.tags as tag} {#if is_author} - + {tag} + + deleteTag(tag)}>× - #{tag} - {:else} - - #{tag} + + {tag} {/if} {/each} + {#if is_author} + + + + + {/if}
{/if} @@ -236,14 +301,17 @@ padding: 1em; margin: 1em; } - .tags a { + .tag { padding: 0.25em; } + .tag::before { + content: '#'; + } .links { margin: 0.5em; display: flex; } - .links a { + .link { margin: 0.5em; }