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] 드래그앤드롭 원활하게 수정 #94

Merged
merged 1 commit into from
Nov 16, 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
7 changes: 6 additions & 1 deletion src/app/mypage/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ const MyPage = () => {
fetchGetCount();
}, []);

useEffect(() => {
if (name.length > 0 && email.length > 0) {
setLoading(false);
}
}, [name, email]);

const goToLetterType = () => {
router.push("/mypage/lettertype");
};
Expand Down Expand Up @@ -69,7 +75,6 @@ const MyPage = () => {
const response = await getLetterCount();
setLetterCount(response.data.letterCount);
setPlanetCount(response.data.spaceCount);
setLoading(false);
} catch (error) {
console.error("편지수, 행성수 조회 실패:", error);
}
Expand Down
8 changes: 4 additions & 4 deletions src/app/planet/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const PlanetPage = () => {
console.log("모든 편지 수 조회 성공:", response.data);
setCountLetter(response.data.letterCount);
setCurrentOrbits(response.data.content);
setIsLoading(false);

if (response.data.letterCount < 3 && getInitUserToast() !== "true") {
setShowTooltip(true);
setInitUserToast();
Expand Down Expand Up @@ -127,10 +127,8 @@ const PlanetPage = () => {
// });
// }
//setDroppedItem(null);
setIsLoading(false);
} catch (error) {
console.error("행성 편지 목록 조회 실패:", error);
setIsLoading(false);
}
};

Expand All @@ -151,7 +149,6 @@ const PlanetPage = () => {
} catch (error) {
console.error("메인 ID 조회 실패:", error);
setSpaceInfo(null);
setIsLoading(false);

/* 메인 ID 없을 경우 회원 탈퇴로 간주 */
// router.push("/login");
Expand All @@ -166,6 +163,8 @@ const PlanetPage = () => {
} catch (error) {
console.error("궤도 편지 목록 조회 실패:", error);
setOrbitMessages(null);
} finally {
setIsLoading(false);
}
};

Expand Down Expand Up @@ -695,4 +694,5 @@ const LoaderContainer = styled.div`
display: flex;
align-items: center;
justify-content: center;
background-color: ${theme.colors.bg};
`;
43 changes: 25 additions & 18 deletions src/components/common/Tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ const Tag = (props: TagProps) => {
const [editedName, setEditedName] = useState(name);
const [isHoldTriggered, setIsHoldTriggered] = useState<boolean>(false);
const [isDragging, setIsDragging] = useState<boolean>(false);
const [startPosition, setStartPosition] = useState<{
x: number;
y: number;
} | null>(null);
const startPositionRef = useRef<{ x: number; y: number }>({ x: 0, y: 0 });
const [translate, setTranslate] = useState({ x: 0, y: 0 });
const holdTimeout = useRef<NodeJS.Timeout | null>(null);
const tagRef = useRef<HTMLDivElement | null>(null);
Expand Down Expand Up @@ -94,7 +91,7 @@ const Tag = (props: TagProps) => {

const handleDragEnd = () => {
setIsDragging(false);
setStartPosition(null);
startPositionRef.current = { x: 0, y: 0 };
};

const handleNameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
Expand Down Expand Up @@ -169,9 +166,13 @@ const Tag = (props: TagProps) => {
}
if (isDragable && tagType === "orbit") {
e.stopPropagation();
console.log("터치 시작");
const touch = e.touches[0];
setStartPosition({ x: touch.clientX, y: touch.clientY });
console.log("터치 시작", e.touches?.[0]);

const touch = e.touches?.[0];
if (touch) {
const position = { x: touch.clientX, y: touch.clientY };
startPositionRef.current = position;
}

e.currentTarget.addEventListener("touchmove", handleTouchMove, {
passive: false,
Expand All @@ -183,12 +184,14 @@ const Tag = (props: TagProps) => {
};

const handleTouchMove = (e: TouchEvent) => {
console.log("터치 움직임");
const startPosition = startPositionRef.current;
console.log("터치 움직임", startPosition);

if (startPosition) {
const touch = e.touches[0];
console.log(startPosition.x);
const deltaX = touch.clientX - 60;
const deltaY = touch.clientY - startPosition.y;

setTranslate({
x: touch.clientX - startPosition.x,
y: touch.clientY - startPosition.y,
Expand Down Expand Up @@ -377,25 +380,29 @@ const Box = styled.div<{
background: ${theme.colors.gray800};
${(props) => props.theme.fonts.body08};
display: flex;
${$hasEditIcon &&
css`
${
$hasEditIcon &&
css`
height: 47px;
padding: 9px 18px;
border-radius: 200px;
background: rgba(255, 255, 255, 0.2);
backdrop-filter: blur(2px);
${(props) => props.theme.fonts.title01};
gap: 4px;
`}
${$hasName === false &&
css`
`
}
${
$hasName === false &&
css`
padding: 7.5px 13px 7.5px 13px;
`}
`
}
`}

${({ $tagType, $orbitType }) =>
$tagType === "letter" &&
css`
$tagType === "letter" &&
css`
display: block;
max-width: 90px;
padding: ${$orbitType === "2" ? "7.5px 15px" : "11px 15px"};
Expand Down