[feat] solution/frontend: 섹션 아이템을 버튼으로 넣는다 — 레트로 템플릿이 기본 구성을 데려온다

시드에 세 아이템을 박아 두니 내용 없는 칸이 목록에 늘 붙어 있었다. 붙여넣기 아이템은
JSON 이 없으면 빈 섹션이라 "쓸 사람만 넣는" 쪽이 맞다.

- canvas/addable.ts: 추가 가능한 섹션 목록. dataSpec 이 단일 출처라 아이템을 만들면 여기 자동으로
  나타난다 — 목록을 따로 들면 만들어 놓고 고를 수 없는 상태가 된다
- SectionListPanel: 하단 [+ 섹션 추가] + 썸네일 목록. 나중에 넣은 섹션만 휴지통으로 뺀다
  (업종 기본 섹션은 스위치로 끄는 것이지 빼는 게 아니다). 내용이 있으면 빼기 전에 한 번 묻는다
- stores/builder: addSection 은 이미 있으면 새로 만들지 않고 켜기만 한다 — 새로 만들면 넣어 둔
  JSON 이 날아간다
- shared/TemplateItem.defaultSectionTypes + 업종마다 레트로 템플릿 하나(옛 항구·옛 다방·노포·시간여행).
  고르면 세 아이템이 함께 들어온다. 넣기만 하고 빼지 않는다 — 템플릿을 눌러 보다 넣어 둔 섹션이
  사라지면 사장님은 그게 템플릿 때문인 줄 모르고 자기가 지웠다고 생각한다
- siteTheme/applyTheme: 저장 payload 에 type 을 싣는다. 시드에 없는 섹션은 id 로 못 찾아 복원 때
  통째로 버려졌다 — 사장님이 채운 JSON 까지 같이 사라지는 자리였다
- industryData: 세 아이템을 시드에서 뺐다

tsc·eslint·vite build 통과(frontend·admin), 추가·삭제·템플릿 연동·저장복원 왕복 12건 확인
This commit is contained in:
minaChoi committed 2026-09-02 08:35:25 +09:00
1 parent 23162783f9
commit e6ffdad888
7 files changed
+317 -30

No files matched your search

+68 -8
View File
@@ -9,6 +9,7 @@ import type {
ViewportMode,
} from '@o2o/shared';
import {FALLBACK_INDUSTRY, INDUSTRY_CONFIGS} from '@/data/industryData';
import {addableSection, newSectionOf} from '@/features/builder/canvas/addable';
import {COLOR_PALETTE_PRESETS} from '@/features/builder/colorPalettes';
import {createFactSaver, type FactSaver} from '@/features/builder/factSave';
import {
@@ -125,6 +126,10 @@ interface BuilderState {
selectSection: (id: string | null) => void;
toggleSection: (id: string) => void;
reorderSection: (fromIndex: number, toIndex: number) => void;
/** [+ 섹션 추가] — 이미 있으면 켜기만 한다. */
addSection: (type: string) => void;
/** 나중에 넣은 섹션만 뺀다. 업종 기본 섹션은 스위치로 끄는 것이지 빼는 게 아니다. */
removeSection: (id: string) => void;
updateSectionContent: (sectionId: string, patch: Pick<SectionItem, 'name' | 'description' | 'body'>) => void;
/** 붙여넣기 아이템의 원문 JSON. 깨져 있어도 그대로 담는다 — 판단은 렌더러가 한다. */
updateSectionData: (sectionId: string, data: string) => void;
@@ -460,8 +465,31 @@ export const useBuilderStore = create<BuilderState>((set, get) => ({
setGatherStage: (gatherStage) => set({gatherStage}),
finishGather: () => set({isGathering: false, gatherCompleted: true, gatherStage: 3}),
/**
* 템플릿을 고른다. 그 템플릿이 데리고 오는 섹션이 있으면 함께 들어온다.
*
* ★ 넣기만 하고 빼지 않는다. 템플릿을 눌러 보다가 넣어 둔 섹션이 사라지면
* 사장님은 그게 템플릿 때문인 줄 모르고 자기가 지웠다고 생각한다.
*/
selectTemplate: (templateId) => {
set({templateId, colorPaletteId: null});
set((state) => {
const template = INDUSTRY_CONFIGS[state.industry].templates.find((t) => t.id === templateId);
const wanted = template?.defaultSectionTypes ?? [];
const added = wanted
.filter((type) => !state.sections.some((sec) => sec.type === type))
.map(newSectionOf)
.filter((sec): sec is SectionItem => sec !== undefined);
return {
templateId,
colorPaletteId: null,
sections: [
...state.sections.map((sec) =>
wanted.includes(sec.type) ? {...sec, isEnabled: true} : sec,
),
...added,
],
};
});
persistTheme();
},
selectColorPalette: (colorPaletteId) => {
@@ -514,6 +542,33 @@ export const useBuilderStore = create<BuilderState>((set, get) => ({
persistTheme();
},
addSection: (type) => {
const created = newSectionOf(type);
if (!created) return;
set((state) => {
const existing = state.sections.find((sec) => sec.type === type);
// 이미 있으면 새로 만들지 않는다 — 넣어 둔 JSON 이 날아간다.
if (existing) {
return {
sections: state.sections.map((sec) =>
sec.id === existing.id ? {...sec, isEnabled: true} : sec,
),
selectedSectionId: existing.id,
};
}
return {sections: [...state.sections, created], selectedSectionId: created.id};
});
persistTheme();
},
removeSection: (id) => {
set((state) => ({
sections: state.sections.filter((sec) => sec.id !== id),
selectedSectionId: state.selectedSectionId === id ? null : state.selectedSectionId,
}));
persistTheme();
},
updateSectionData: (sectionId, data) => {
set((state) => ({
sections: state.sections.map((section) =>
@@ -566,17 +621,22 @@ export const useBuilderStore = create<BuilderState>((set, get) => ({
// (SectionItem 에서는 선택 키다) 아래 filter 의 타입 술어가 컴파일되지 않는다.
.map((saved): SectionItem | null => {
const seed = seedById.get(saved.id);
if (!seed) return null;
// ★ 시드에 없어도 [+ 섹션 추가] 로 넣을 수 있는 것이면 되살린다.
// 여기서 버리면 사장님이 추가하고 JSON 까지 채운 섹션이 새로고침 한 번에 사라진다.
const revived =
seed ??
(saved.type && addableSection(saved.type) ? newSectionOf(saved.type) : undefined);
if (!revived) return null;
seedById.delete(saved.id);
return {
...seed,
name: saved.name || seed.name,
description: saved.description ?? seed.description,
body: saved.body ?? seed.body,
data: saved.data ?? seed.data,
...revived,
name: saved.name || revived.name,
description: saved.description ?? revived.description,
body: saved.body ?? revived.body,
data: saved.data ?? revived.data,
// 잠긴 섹션은 시드의 판단이 이긴다 — 서버에 꺼진 채로 저장돼 있더라도
// SEO·필수 마크업이 달린 섹션을 화면에서 꺼진 것처럼 보이게 하지 않는다.
isEnabled: seed.isLocked ? true : saved.enabled,
isEnabled: revived.isLocked ? true : saved.enabled,
...(saved.variantId ? {variantId: saved.variantId} : {}),
};
})