Skip to content

Commit

Permalink
refactor: 모아보기가 비어있을 때 초기화 하는 로직 함수 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
semnil5202 committed Nov 13, 2023
1 parent 44031db commit a472f0b
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions frontend/src/pages/SeeTogether.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import useSetLayoutWidth from '../hooks/useSetLayoutWidth';
import useSetNavbarHighlight from '../hooks/useSetNavbarHighlight';
import useTags from '../hooks/useTags';
import useMapStore from '../store/mapInstance';
import { PinProps } from '../types/Pin';
import { TopicDetailProps } from '../types/Topic';
import PinDetail from './PinDetail';

Expand All @@ -38,7 +37,7 @@ function SeeTogether() {

const { topicId } = useParams();
const { routePage } = useNavigator();
const [searchParams, _] = useSearchParams();
const [searchParams] = useSearchParams();
const location = useLocation();

const [isOpen, setIsOpen] = useState(true);
Expand Down Expand Up @@ -79,7 +78,6 @@ function SeeTogether() {
);

setTopicDetails(topics);
setClusteredCoordinates();
};

const setClusteredCoordinates = async () => {
Expand Down Expand Up @@ -124,7 +122,22 @@ function SeeTogether() {
setCoordinates((prev) => [...prev]);
};

const togglePinDetail = () => {
setIsOpen(!isOpen);
};

const initMarkerWhenSeeTogetherIsEmpty = () => {
setCoordinates([]);

if (markers && markers.length > 0) {
removeMarkers();
removeInfowindows();
}
};

useEffect(() => {
setClusteredCoordinates();

const onDragEnd = (evt: evt) => {
if (dragTimerIdRef.current) {
clearTimeout(dragTimerIdRef.current);
Expand Down Expand Up @@ -155,10 +168,6 @@ function SeeTogether() {
};
}, [topicDetails]);

const togglePinDetail = () => {
setIsOpen(!isOpen);
};

useEffect(() => {
const queryParams = new URLSearchParams(location.search);

Expand All @@ -173,15 +182,9 @@ function SeeTogether() {

useEffect(() => {
getAndSetDataFromServer();
}, [topicId]);

useEffect(() => {
setTags([]);

if (markers && markers.length > 0) {
removeMarkers();
removeInfowindows();
}
initMarkerWhenSeeTogetherIsEmpty();
}, []);

if (!seeTogetherTopics || !topicId) return <></>;
Expand Down

0 comments on commit a472f0b

Please sign in to comment.