Skip to content
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

Fix: Popular Sports Local Filter Drag #52

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/Lesson/LocalFilter/LocalFilter.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export interface LocalFilterProps {
placeholderType?: string; // 지도 νƒ­κ³Ό κ°•μ’Œ νƒ­ νŽ˜μ΄μ§€μ— λ”°λ₯Έ λ“œλ‘­λ‹€μš΄ μš”μ†Œ λ””μžμΈ 차이 κ΅¬λΆ„μš©
additionalBottomSheetClass?: string;
isSpecialMode?: boolean;
onToggleOpen?: (isOpen: boolean) => void; // λΆ€λͺ¨ μ»΄ν¬λ„ŒνŠΈμ—μ„œ λ°”ν…€μ‹œνŠΈ μ—΄λ¦Ό μƒνƒœ μ—…λ°μ΄νŠΈ ν•¨μˆ˜ μΆ”κ°€
}
7 changes: 6 additions & 1 deletion src/components/Lesson/LocalFilter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function LocalFilter({
placeholderType,
additionalBottomSheetClass,
isSpecialMode,
onToggleOpen,
}: LocalFilterProps) {
const [isOpen, setIsOpen] = useState(false);
const filterRef = useRef<HTMLDivElement>(null);
Expand All @@ -35,10 +36,14 @@ export default function LocalFilter({
document.body.style.overflow = '';
}

if (onToggleOpen) {
onToggleOpen(isOpen);
}

return () => {
document.body.style.overflow = '';
};
}, [isOpen]);
}, [isOpen, onToggleOpen]);

const handleOptionClick = (key: string) => {
onChange(key);
Expand Down
14 changes: 4 additions & 10 deletions src/components/MapHome/FacilityInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,13 @@ export default function FacilityInfo({
}, [facility, initialPosition]);

const getLabelItem = () => {
if (!facility || !facility.items || facility.items.length === 0) {
if (!facility || !facility.items || facility.items.length === 0)
return 'μ—†μŒ';
}

if (filterItem && facility.items.includes(filterItem)) {
return filterItem;
}

const filteredItems = facility.items.filter(item => item === filterItem);
if (filteredItems.length > 0) {
return filterItem;
}

const frequency: Record<string, number> = {};
facility.items.forEach(item => {
frequency[item] = (frequency[item] || 0) + 1;
Expand All @@ -97,7 +91,7 @@ export default function FacilityInfo({
a[1] > b[1] ? a : b
)[0];

return mostFrequentItem || 'μ—†μŒ';
return mostFrequentItem;
};

if (!facility) return null;
Expand Down Expand Up @@ -141,8 +135,8 @@ export default function FacilityInfo({
</div>
<div className={styles.chipsContainer}>
<Chips
chipState={filterItem ? 'sports' : 'label'}
text={getLabelItem() || ''}
chipState="sports"
text={getLabelItem()}
serialNumber={isNormalFacility ? true : false}
/>
</div>
Expand Down
14 changes: 13 additions & 1 deletion src/components/MapHome/PopularSports/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function PopularSports({
const [isNextStep, setIsNextStep] = useState(false);
const [selectedCityCode, setSelectedCityCode] = useState<string>('11');
const [selectedLocalCode, setSelectedLocalCode] = useState<string>('');
const [isFilterOpen, setIsFilterOpen] = useState(false);

// μ‹œλ„ 선택 μ‹œ ꡬ/κ΅° μ˜΅μ…˜ μ„€μ •
useEffect(() => {
Expand Down Expand Up @@ -75,13 +76,14 @@ export default function PopularSports({

// λ“œλž˜κ·Έ 이벀트 ν•Έλ“€λŸ¬
const handleDragStart = (event: React.MouseEvent | React.TouchEvent) => {
if (isFilterOpen) return; // ν•„ν„°κ°€ μ—΄λ € μžˆμ„ λ•Œ λ“œλž˜κ·Έ 막기
setIsDragging(true);
initialY.current =
'touches' in event ? event.touches[0].clientY : event.clientY;
};

const handleDragMove = (event: React.MouseEvent | React.TouchEvent) => {
if (!isDragging) return;
if (!isDragging || isFilterOpen) return;

const currentY =
'touches' in event ? event.touches[0].clientY : event.clientY;
Expand Down Expand Up @@ -110,6 +112,15 @@ export default function PopularSports({
);
};

// λ°”ν…€μ‹œνŠΈ μ—΄λ¦Ό μƒνƒœ λ³€κ²½ ν•Έλ“€λŸ¬
const handleToggleFilterOpen = (isOpen: boolean) => {
setIsFilterOpen(isOpen);
if (isOpen) {
// ν•„ν„°κ°€ 열리면 PopularSports의 μœ„μΉ˜λ₯Ό μ΄ˆκΈ°ν™”
setPosition(0);
}
};

return (
<div
className={styles.popularSportsContainer}
Expand Down Expand Up @@ -144,6 +155,7 @@ export default function PopularSports({
isNextStep={isNextStep}
additionalBottomSheetClass={styles.customBottomSheet}
isSpecialMode={mode === 'special'}
onToggleOpen={handleToggleFilterOpen}
/>
</div>
</header>
Expand Down
Loading