브랜드 설정 정규화 로직 분리
This commit is contained in:
@@ -5,7 +5,6 @@ import {
|
||||
normalizeAnnouncementAlignment,
|
||||
normalizeAnnouncementBackgroundColor
|
||||
} from '~/lib/announcement-bar.js'
|
||||
import { DEFAULT_BRAND_COLOR, normalizeBrandColor } from '~/lib/brand-color.js'
|
||||
import {
|
||||
DISPLAY_COUNT_OPTIONS,
|
||||
POST_LIST_COUNT_OPTIONS
|
||||
@@ -38,6 +37,13 @@ import {
|
||||
normalizeSpamSettingsSection,
|
||||
parseSpamBlockedUsernamesText
|
||||
} from '~/lib/admin-spam-settings-section.js'
|
||||
import {
|
||||
BRAND_SETTINGS_FIELDS,
|
||||
assignBrandSettingsSection,
|
||||
createDefaultBrandSettingsSnapshot,
|
||||
hasBrandSettingsSectionChanges,
|
||||
normalizeBrandSettingsSection
|
||||
} from '~/lib/admin-brand-settings-section.js'
|
||||
|
||||
definePageMeta({
|
||||
layout: 'admin'
|
||||
@@ -174,9 +180,7 @@ const homeCoverSnapshot = reactive({
|
||||
homeCoverText: ''
|
||||
})
|
||||
/** 편집 시작 시점의 브랜드 설정(취소 시 복원용) */
|
||||
const brandSnapshot = reactive({
|
||||
brandColor: DEFAULT_BRAND_COLOR
|
||||
})
|
||||
const brandSnapshot = reactive(createDefaultBrandSettingsSnapshot())
|
||||
/** 맞춤 설정 시작 시점의 어나운스 바(취소 시 복원용) */
|
||||
const announcementSnapshot = reactive({
|
||||
announcementEnabled: false,
|
||||
@@ -229,6 +233,7 @@ const {
|
||||
const initialPostSettings = normalizePostSettingsSection(settings.value)
|
||||
const initialSocialSettings = normalizeSocialSettingsSection(settings.value)
|
||||
const initialSpamSettings = normalizeSpamSettingsSection(settings.value)
|
||||
const initialBrandSettings = normalizeBrandSettingsSection(settings.value)
|
||||
|
||||
const form = reactive({
|
||||
title: settings.value?.title || 'sori.studio',
|
||||
@@ -244,7 +249,7 @@ const form = reactive({
|
||||
homeCoverDarkImageUrl: settings.value?.homeCoverDarkImageUrl || '',
|
||||
homeCoverTitle: settings.value?.homeCoverTitle || '',
|
||||
homeCoverText: settings.value?.homeCoverText || '',
|
||||
brandColor: normalizeBrandColor(settings.value?.brandColor || DEFAULT_BRAND_COLOR),
|
||||
...initialBrandSettings,
|
||||
announcementEnabled: Boolean(settings.value?.announcementEnabled),
|
||||
announcementText: settings.value?.announcementText || '',
|
||||
announcementUrl: settings.value?.announcementUrl || '',
|
||||
@@ -314,7 +319,7 @@ const hasHomeCoverChanges = computed(() => editHomeCover.value && (
|
||||
* @returns {boolean} 변경 여부
|
||||
*/
|
||||
const hasBrandChanges = computed(() => editBrand.value
|
||||
&& normalizeBrandColor(form.brandColor) !== normalizeBrandColor(brandSnapshot.brandColor))
|
||||
&& hasBrandSettingsSectionChanges(form, brandSnapshot))
|
||||
|
||||
/**
|
||||
* 어나운스 바 변경 여부
|
||||
@@ -1078,7 +1083,7 @@ const buildSiteSettingsPayload = (fields = null) => {
|
||||
homeCoverDarkImageUrl: form.homeCoverDarkImageUrl || '',
|
||||
homeCoverTitle: form.homeCoverTitle || '',
|
||||
homeCoverText: form.homeCoverText || '',
|
||||
brandColor: normalizeBrandColor(form.brandColor || DEFAULT_BRAND_COLOR),
|
||||
...normalizeBrandSettingsSection(form),
|
||||
announcementEnabled: Boolean(form.announcementEnabled),
|
||||
announcementText: form.announcementText || '',
|
||||
announcementUrl: form.announcementUrl || '',
|
||||
@@ -1458,8 +1463,8 @@ const saveHomeCoverSection = async () => {
|
||||
* @returns {void}
|
||||
*/
|
||||
const beginEditBrand = () => {
|
||||
brandSnapshot.brandColor = normalizeBrandColor(form.brandColor || DEFAULT_BRAND_COLOR)
|
||||
form.brandColor = brandSnapshot.brandColor
|
||||
assignBrandSettingsSection(brandSnapshot, form)
|
||||
assignBrandSettingsSection(form, brandSnapshot)
|
||||
editBrand.value = true
|
||||
}
|
||||
|
||||
@@ -1468,7 +1473,7 @@ const beginEditBrand = () => {
|
||||
* @returns {void}
|
||||
*/
|
||||
const cancelEditBrand = () => {
|
||||
form.brandColor = brandSnapshot.brandColor
|
||||
assignBrandSettingsSection(form, brandSnapshot)
|
||||
editBrand.value = false
|
||||
}
|
||||
|
||||
@@ -1477,7 +1482,7 @@ const cancelEditBrand = () => {
|
||||
* @returns {void}
|
||||
*/
|
||||
const normalizeBrandColorInput = () => {
|
||||
form.brandColor = normalizeBrandColor(form.brandColor || DEFAULT_BRAND_COLOR)
|
||||
assignBrandSettingsSection(form, form)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1494,11 +1499,12 @@ const saveBrandSection = async () => {
|
||||
const ok = await persistSiteSettings({
|
||||
successToast: '브랜드 컬러가 저장되었습니다.',
|
||||
savingFlag: savingBrand,
|
||||
fields: ['brandColor']
|
||||
fields: BRAND_SETTINGS_FIELDS
|
||||
})
|
||||
|
||||
if (ok) {
|
||||
brandSnapshot.brandColor = normalizeBrandColor(form.brandColor || DEFAULT_BRAND_COLOR)
|
||||
assignBrandSettingsSection(brandSnapshot, form)
|
||||
assignBrandSettingsSection(form, brandSnapshot)
|
||||
editBrand.value = false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user