프리티어 변경

필터링 AND OR 조건 추가
데이터 JSON 구조 변경
오류 수정
This commit is contained in:
2026-02-22 15:45:22 +09:00
parent 42b5c0f047
commit f569000ba5
8 changed files with 1174 additions and 904 deletions

View File

@@ -67,7 +67,7 @@ export function applyFilters() {
const statusMatch = state.activeStatuses.has(product.status);
const categoryMatch = state.activeCategories.has('All') || state.activeCategories.has(product.category);
const searchMatch = checkSearchMatch(product, keyword);
const tagMatch = state.activeTags.size === 0 || Array.from(state.activeTags).every((tag) => product.tags && product.tags.includes(tag));
const tagMatch = state.activeTags.size === 0 || (state.tagMode === 'AND' ? Array.from(state.activeTags).every((tag) => product.tags?.includes(tag)) : Array.from(state.activeTags).some((tag) => product.tags?.includes(tag)));
return statusMatch && categoryMatch && searchMatch && tagMatch;
})
@@ -195,8 +195,15 @@ export function renderTagChips() {
${hasActive ? 'bg-red-50 text-red-500 border-red-200 hover:bg-red-100' : 'bg-slate-50 text-slate-400 border-slate-200 opacity-60'}" title="태그 초기화">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>
</button>`;
const modeBtnHtml = `
<button id="tag-mode-btn" class="px-2 py-1 rounded-full text-[10px] font-bold border transition-colors
${state.tagMode === 'AND' ? 'bg-indigo-100 text-indigo-600 border-indigo-200' : 'bg-orange-100 text-orange-600 border-orange-200'}">
${state.tagMode}
</button>
`;
container.innerHTML =
modeBtnHtml +
resetBtnHtml +
sortedTags
.map((tag) => {
@@ -229,6 +236,11 @@ export function renderTagChips() {
applyFilters();
};
document.getElementById('tag-mode-btn').onclick = () => {
state.tagMode = state.tagMode === 'AND' ? 'OR' : 'AND';
applyFilters(); // 필터 재적용 및 UI 갱신
};
container.querySelectorAll('.tag-chip').forEach((chip) => {
chip.onclick = () => {
const tag = chip.dataset.tag;
@@ -263,23 +275,42 @@ export function toggleCategory(category) {
* 로고(타이틀) 클릭 시 모든 필터 초기화
*/
document.getElementById('logo-title')?.addEventListener('click', () => {
// 1. 기본 상태 초기화
state.searchKeyword = '';
state.activeTags.clear();
state.activeCategories.clear();
state.activeCategories.add('All');
state.currentPage = 1;
// 2. [수정] config.js의 명칭(isDefaultActive)에 맞춰 필터 복구
state.activeStatuses.clear();
// STATUS_FILTERS를 순회하며 STATUS_META에 정의된 기본 활성 상태를 추가
STATUS_FILTERS.forEach((f) => {
// config.js에서 정의한 isDefaultActive 속성을 확인합니다.
if (STATUS_META[f.key]?.isDefaultActive) {
state.activeStatuses.add(f.key);
}
});
// 만약 config 설정 실수로 아무것도 추가되지 않았다면 '판매중'이라도 강제로 넣음 (안전장치)
if (state.activeStatuses.size === 0) {
state.activeStatuses.add('판매중');
}
// 3. UI 리셋
const searchInput = document.getElementById('search-input');
if (searchInput) searchInput.value = '';
state.activeCategories.clear();
state.activeCategories.add('All');
state.activeStatuses.clear();
STATUS_FILTERS.filter((f) => f.defaultActive).forEach((f) => state.activeStatuses.add(f.key));
state.activeTags.clear();
applyFilters();
// 4. 데이터 갱신 및 UI 렌더링
applyFilters();
renderStatusChips();
renderCategoryChips(productsData);
renderTagChips();
window.scrollTo({ top: 0, behavior: 'smooth' });
console.log("필터 복구 완료:", Array.from(state.activeStatuses));
});
/**