-
Notifications
You must be signed in to change notification settings - Fork 2
feat: 카테고리 필터 바텀시트 UI 및 API 파라미터 정렬 #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
src/components/product/product-filter-bar-container.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| import { getSubCategories } from '@/app/actions/category'; | ||
| import { api } from '@/lib/api-client'; | ||
| import { BrandWithProducts } from '@/types/domain/brand'; | ||
| import { ProductSearchResult } from '@/types/domain/product'; | ||
| import { ProductSortType } from '@/types/enums'; | ||
| import { BrandFilterOption, ProductFilterBar } from './product-filter-bar'; | ||
|
|
||
| interface ProductFilterBarContainerProps { | ||
| params: Promise<{ parentId: string; id: string }>; | ||
| searchParams: Promise<{ | ||
| sortType?: string; | ||
| page?: string; | ||
| clothingSizes?: string | string[]; | ||
| priceRange?: string | string[]; | ||
| brandIds?: string | string[]; | ||
| }>; | ||
| } | ||
|
|
||
| const PRICE_RANGE_PATTERN = /^\d+-\d+$/; | ||
|
|
||
| function normalizeBrandName(value: string) { | ||
| return value.trim().toLowerCase().replace(/\s+/g, ''); | ||
| } | ||
|
|
||
| function normalizeArray(value?: string | string[]) { | ||
| if (Array.isArray(value)) { | ||
| return value.filter((item) => item.trim().length > 0); | ||
| } | ||
| if (typeof value === 'string' && value.trim().length > 0) { | ||
| return [value]; | ||
| } | ||
| return []; | ||
| } | ||
|
|
||
| function normalizePriceRange(value?: string | string[]) { | ||
| if (Array.isArray(value)) { | ||
| return value[0] ?? ''; | ||
| } | ||
| return value ?? ''; | ||
| } | ||
|
|
||
| export default async function ProductFilterBarContainer({ | ||
| params, | ||
| searchParams, | ||
| }: ProductFilterBarContainerProps) { | ||
| const [{ parentId, id: subCategoryId }, query] = await Promise.all([ | ||
| params, | ||
| searchParams, | ||
| ]); | ||
|
|
||
| const parsedCategoryId = Number(subCategoryId); | ||
| const parsedParentId = Number(parentId); | ||
| const safeCategoryId = | ||
| Number.isFinite(parsedCategoryId) && parsedCategoryId > 0 | ||
| ? parsedCategoryId | ||
| : null; | ||
|
|
||
| if (safeCategoryId === null) { | ||
| return <ProductFilterBar parentCategoryName="" availableBrands={[]} />; | ||
| } | ||
|
|
||
| const sortValues = Object.values(ProductSortType); | ||
| const safeSortType = sortValues.includes(query.sortType as ProductSortType) | ||
| ? (query.sortType as ProductSortType) | ||
| : ProductSortType.POPULAR; | ||
|
|
||
| const sizeOptions = normalizeArray(query.clothingSizes).filter((size) => | ||
| ['XS', 'S', 'M', 'L', 'XL'].includes(size), | ||
| ); | ||
|
|
||
| const rawPriceRange = normalizePriceRange(query.priceRange); | ||
| const safePriceRange = PRICE_RANGE_PATTERN.test(rawPriceRange) | ||
| ? rawPriceRange | ||
| : ''; | ||
|
|
||
| const [subCategories, result] = await Promise.all([ | ||
| Number.isFinite(parsedParentId) | ||
| ? getSubCategories(parsedParentId) | ||
| : Promise.resolve([]), | ||
| api.get<ProductSearchResult>('/products', { | ||
| params: { | ||
| categoryId: safeCategoryId, | ||
| sortType: safeSortType, | ||
| page: 0, | ||
| size: 36, | ||
| clothingSizes: sizeOptions.length > 0 ? sizeOptions : undefined, | ||
| priceRange: safePriceRange || undefined, | ||
| }, | ||
| }), | ||
| ]); | ||
|
|
||
| const parentCategoryName = subCategories[0]?.parentCategoryName ?? ''; | ||
| const productItems = result.products.content as Array<{ | ||
| brandName: string; | ||
| brandId?: number; | ||
| }>; | ||
| const brandsFromProducts = Array.from( | ||
| new Set( | ||
| productItems | ||
| .map((product) => product.brandName.trim()) | ||
| .filter((brandName) => brandName.length > 0), | ||
| ), | ||
| ); | ||
|
|
||
| const recommendedBrands = await api | ||
| .get<BrandWithProducts[]>('/brands/recommend', { params: { count: 200 } }) | ||
| .catch(() => []); | ||
|
|
||
| const brandIdByNormalizedName = new Map<string, number>(); | ||
| productItems.forEach((product) => { | ||
| const normalized = normalizeBrandName(product.brandName); | ||
| if (!normalized) return; | ||
| if (Number.isFinite(product.brandId) && (product.brandId as number) > 0) { | ||
| brandIdByNormalizedName.set(normalized, product.brandId as number); | ||
| } | ||
| }); | ||
| recommendedBrands.forEach((brand) => { | ||
| const normalized = normalizeBrandName(brand.name); | ||
| if (!normalized || brandIdByNormalizedName.has(normalized)) return; | ||
| brandIdByNormalizedName.set(normalized, brand.id); | ||
| }); | ||
|
|
||
| const mappedFromProducts = brandsFromProducts | ||
| .map((name) => { | ||
| const id = brandIdByNormalizedName.get(normalizeBrandName(name)); | ||
| if (!id) return null; | ||
| return { id, name }; | ||
| }) | ||
| .filter((item): item is BrandFilterOption => item !== null); | ||
|
|
||
| const mappedFromRecommended: BrandFilterOption[] = recommendedBrands.map( | ||
| (brand) => ({ id: brand.id, name: brand.name }), | ||
| ); | ||
|
|
||
| const availableBrands = Array.from( | ||
| new Map( | ||
| [...mappedFromProducts, ...mappedFromRecommended].map((brand) => [ | ||
| String(brand.id), | ||
| brand, | ||
| ]), | ||
| ).values(), | ||
| ).sort((a, b) => a.name.localeCompare(b.name, 'ko')); | ||
|
|
||
| return ( | ||
| <ProductFilterBar | ||
| parentCategoryName={parentCategoryName} | ||
| availableBrands={availableBrands} | ||
| /> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: IT-Cotato/12th-OnGil-FE
Length of output: 94
🏁 Script executed:
Repository: IT-Cotato/12th-OnGil-FE
Length of output: 789
🏁 Script executed:
Repository: IT-Cotato/12th-OnGil-FE
Length of output: 94
🏁 Script executed:
Repository: IT-Cotato/12th-OnGil-FE
Length of output: 77
🏁 Script executed:
# List types directory ls -la src/types/Repository: IT-Cotato/12th-OnGil-FE
Length of output: 412
🏁 Script executed:
Repository: IT-Cotato/12th-OnGil-FE
Length of output: 4525
🏁 Script executed:
# Check imports and setup in the product-filter-bar-container.tsx file head -50 src/components/product/product-filter-bar-container.tsxRepository: IT-Cotato/12th-OnGil-FE
Length of output: 1461
🏁 Script executed:
Repository: IT-Cotato/12th-OnGil-FE
Length of output: 326
🏁 Script executed:
Repository: IT-Cotato/12th-OnGil-FE
Length of output: 1184
🏁 Script executed:
Repository: IT-Cotato/12th-OnGil-FE
Length of output: 1281
불필요한 타입 단언 제거 및 Product 타입 활용
result.products.content는Product[]타입입니다.brandName은 이미Product에 존재하므로 타입 단언이 필요 없습니다. 다만brandId는Product에 없고, 현재 코드의Number.isFinite()체크와as number캐스팅(113~114줄)은 필드 부재를 우회하는 패턴입니다.선택지:
brandId가 포함되면Product타입을 확장하고 단언 제거brandId접근 로직 제거🤖 Prompt for AI Agents