SNS 설정 정규화 로직 분리
This commit is contained in:
@@ -10,9 +10,6 @@ import {
|
||||
normalizeSignupBlockedUsernames,
|
||||
parseSignupBlockedUsernamesFromText
|
||||
} from '~/lib/signup-blocked-usernames.js'
|
||||
import {
|
||||
normalizeSocialLinks
|
||||
} from '~/lib/social-links.js'
|
||||
import {
|
||||
DISPLAY_COUNT_OPTIONS,
|
||||
POST_LIST_COUNT_OPTIONS
|
||||
@@ -29,6 +26,13 @@ import {
|
||||
hasPostSettingsSectionChanges,
|
||||
normalizePostSettingsSection
|
||||
} from '~/lib/admin-post-settings-section.js'
|
||||
import {
|
||||
SOCIAL_SETTINGS_FIELDS,
|
||||
assignSocialSettingsSection,
|
||||
createDefaultSocialSettingsSnapshot,
|
||||
hasSocialSettingsSectionChanges,
|
||||
normalizeSocialSettingsSection
|
||||
} from '~/lib/admin-social-settings-section.js'
|
||||
|
||||
definePageMeta({
|
||||
layout: 'admin'
|
||||
@@ -154,9 +158,7 @@ const miscSnapshot = reactive({
|
||||
copyrightText: ''
|
||||
})
|
||||
/** 편집 시작 시점의 SNS 정보(취소 시 복원용) */
|
||||
const socialSnapshot = reactive({
|
||||
socialLinks: []
|
||||
})
|
||||
const socialSnapshot = reactive(createDefaultSocialSettingsSnapshot())
|
||||
/** 편집 시작 시점의 POST 설정(취소 시 복원용) */
|
||||
const postSnapshot = reactive(createDefaultPostSettingsSnapshot())
|
||||
/** 편집 시작 시점의 메인 화면 커버(취소 시 복원용) */
|
||||
@@ -222,6 +224,7 @@ const {
|
||||
default: () => null
|
||||
})
|
||||
const initialPostSettings = normalizePostSettingsSection(settings.value)
|
||||
const initialSocialSettings = normalizeSocialSettingsSection(settings.value)
|
||||
|
||||
const form = reactive({
|
||||
title: settings.value?.title || 'sori.studio',
|
||||
@@ -231,7 +234,7 @@ const form = reactive({
|
||||
logoUrl: settings.value?.logoUrl || '',
|
||||
faviconUrl: settings.value?.faviconUrl || '',
|
||||
copyrightText: settings.value?.copyrightText || '©2026 sori.studio',
|
||||
socialLinks: normalizeSocialLinks(settings.value?.socialLinks || []),
|
||||
...initialSocialSettings,
|
||||
...initialPostSettings,
|
||||
homeCoverImageUrl: settings.value?.homeCoverImageUrl || '',
|
||||
homeCoverDarkImageUrl: settings.value?.homeCoverDarkImageUrl || '',
|
||||
@@ -282,7 +285,7 @@ const hasMiscChanges = computed(() => editMisc.value && (
|
||||
* @returns {boolean} 변경 여부
|
||||
*/
|
||||
const hasSocialChanges = computed(() => editSocial.value
|
||||
&& JSON.stringify(normalizeSocialLinks(form.socialLinks)) !== JSON.stringify(normalizeSocialLinks(socialSnapshot.socialLinks)))
|
||||
&& hasSocialSettingsSectionChanges(form, socialSnapshot))
|
||||
|
||||
/**
|
||||
* POST 설정 변경 여부
|
||||
@@ -1065,7 +1068,7 @@ const buildSiteSettingsPayload = (fields = null) => {
|
||||
logoUrl: form.logoUrl,
|
||||
faviconUrl: form.faviconUrl,
|
||||
copyrightText: form.copyrightText,
|
||||
socialLinks: normalizeSocialLinks(form.socialLinks),
|
||||
...normalizeSocialSettingsSection(form),
|
||||
...normalizePostSettingsSection(form),
|
||||
homeCoverImageUrl: form.homeCoverImageUrl || '',
|
||||
homeCoverDarkImageUrl: form.homeCoverDarkImageUrl || '',
|
||||
@@ -1243,8 +1246,8 @@ const saveMiscSection = async () => {
|
||||
* @returns {void}
|
||||
*/
|
||||
const beginEditSocial = () => {
|
||||
socialSnapshot.socialLinks = normalizeSocialLinks(form.socialLinks)
|
||||
form.socialLinks = normalizeSocialLinks(form.socialLinks)
|
||||
assignSocialSettingsSection(socialSnapshot, form)
|
||||
assignSocialSettingsSection(form, socialSnapshot)
|
||||
editSocial.value = true
|
||||
}
|
||||
|
||||
@@ -1253,7 +1256,7 @@ const beginEditSocial = () => {
|
||||
* @returns {void}
|
||||
*/
|
||||
const cancelEditSocial = () => {
|
||||
form.socialLinks = normalizeSocialLinks(socialSnapshot.socialLinks)
|
||||
assignSocialSettingsSection(form, socialSnapshot)
|
||||
editSocial.value = false
|
||||
}
|
||||
|
||||
@@ -1266,16 +1269,17 @@ const saveSocialSection = async () => {
|
||||
return
|
||||
}
|
||||
|
||||
form.socialLinks = normalizeSocialLinks(form.socialLinks)
|
||||
assignSocialSettingsSection(form, form)
|
||||
|
||||
const ok = await persistSiteSettings({
|
||||
successToast: 'SNS 정보가 저장되었습니다.',
|
||||
savingFlag: savingSocial,
|
||||
fields: ['socialLinks']
|
||||
fields: SOCIAL_SETTINGS_FIELDS
|
||||
})
|
||||
|
||||
if (ok) {
|
||||
socialSnapshot.socialLinks = normalizeSocialLinks(form.socialLinks)
|
||||
assignSocialSettingsSection(socialSnapshot, form)
|
||||
assignSocialSettingsSection(form, socialSnapshot)
|
||||
editSocial.value = false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user