Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.
TypeScript albumsexif-extractiongeocodinglive-photomotion-photophoto-galleryphoto-sharingwebgl-viewer
fix(settings): preserve social link edits during saves
Ahmet Ömer42f8594ff68f
diff --git a/packages/console/app/pages/dashboard/settings/general.vue b/packages/console/app/pages/dashboard/settings/general.vueindex cee731f8..769382da 100644--- a/packages/console/app/pages/dashboard/settings/general.vue+++ b/packages/console/app/pages/dashboard/settings/general.vue@@ -1,5 +1,6 @@<script lang="ts" setup>import { settingsFieldCommitKey } from '#console/composables/useSettingsForm'+import { reconcileSocialDraftAfterSave } from '#console/utils/socialLinksDraft'import {MAX_SOCIAL_LINKS,parseSocialLinks,@@ -36,6 +37,7 @@ const appearanceFields = computed(() =>const socialField = computed(() =>fields.value.find((field) => field.key === 'socialLinks'),)+const publishedSocialLinks = useSettingRef('app:socialLinks')const socialDraft = ref<string[]>(Array(MAX_SOCIAL_LINKS).fill(''))const socialInitialized = ref(false)const savedSocialLinks = computed(() => {@@ -88,13 +90,16 @@ const resetSocialLinks = () => {const socialSubmitError = ref('')const handleSocialLinksSubmit = async () => {socialSubmitError.value = ''- const links = socialDraft.value.map((link) => link.trim()).filter(Boolean)+ const draftAtSubmission = [...socialDraft.value]+ const links = draftAtSubmission.map((link) => link.trim()).filter(Boolean)try {parseSocialLinks({ links })await submit({ socialLinks: { links } })- socialDraft.value = Array.from(- { length: MAX_SOCIAL_LINKS },- (_, index) => links[index] ?? '',+ commitField('socialLinks', publishedSocialLinks.value)+ socialDraft.value = reconcileSocialDraftAfterSave(+ socialDraft.value,+ draftAtSubmission,+ savedSocialLinks.value,)} catch (error) {socialSubmitError.value =diff --git a/packages/console/app/utils/socialLinksDraft.ts b/packages/console/app/utils/socialLinksDraft.tsnew file mode 100644index 00000000..6576cee5--- /dev/null+++ b/packages/console/app/utils/socialLinksDraft.ts@@ -0,0 +1,14 @@+export function reconcileSocialDraftAfterSave(+ currentDraft: string[],+ draftAtSubmission: readonly string[],+ savedLinks: readonly string[],+): string[] {+ if (+ currentDraft.length !== draftAtSubmission.length ||+ currentDraft.some((link, index) => link !== draftAtSubmission[index])+ ) {+ return currentDraft+ }++ return draftAtSubmission.map((_, index) => savedLinks[index] ?? '')+}diff --git a/tests/social-links-draft.test.ts b/tests/social-links-draft.test.tsnew file mode 100644index 00000000..65160ef5--- /dev/null+++ b/tests/social-links-draft.test.ts@@ -0,0 +1,30 @@+import assert from 'node:assert/strict'+import test from 'node:test'+import { reconcileSocialDraftAfterSave } from '../packages/console/app/utils/socialLinksDraft.ts'++test('unchanged draft adopts the value returned by the server', () => {+ const submittedDraft = ['https://instagram.com/me', '', '', '']+ const savedLinks = ['https://www.instagram.com/me']++ assert.deepEqual(+ reconcileSocialDraftAfterSave(submittedDraft, submittedDraft, savedLinks),+ ['https://www.instagram.com/me', '', '', ''],+ )+})++test('typing during a save stays in the draft after the response', () => {+ const submittedDraft = ['https://instagram.com/me', '', '', '']+ const editedDraft = [+ 'https://instagram.com/me',+ 'https://github.com/me',+ '',+ '',+ ]++ assert.equal(+ reconcileSocialDraftAfterSave(editedDraft, submittedDraft, [+ 'https://www.instagram.com/me',+ ]),+ editedDraft,+ )+})