-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into #763-채팅-endpoint-오류-수정
- Loading branch information
Showing
9 changed files
with
315 additions
and
88 deletions.
There are no files selected for viewing
This file contains 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,65 @@ | ||
import { keyframes } from "@emotion/react"; | ||
|
||
import Room from "."; | ||
|
||
type AnimatedRoomProps = { | ||
data: any; | ||
selected?: boolean; | ||
onClick?: () => void; | ||
marginTop?: string; | ||
marginBottom?: string; | ||
theme?: string; | ||
type?: "addition" | "deletion"; | ||
}; | ||
|
||
const growHeight = keyframes` | ||
from { | ||
height: 0px; | ||
} | ||
to { | ||
height: 125px; | ||
} | ||
`; | ||
|
||
const shrinkHeight = keyframes` | ||
from { | ||
height: 125px; | ||
} | ||
to { | ||
height: 0px; | ||
} | ||
`; | ||
|
||
const AnimatedRoom = ({ | ||
data, | ||
selected = false, | ||
onClick = () => {}, | ||
marginTop = "0px", | ||
marginBottom = "0px", | ||
theme, | ||
type, | ||
}: AnimatedRoomProps) => { | ||
const props = { | ||
data, | ||
selected, | ||
onClick, | ||
marginTop, | ||
marginBottom, | ||
theme, | ||
type, | ||
}; | ||
|
||
return !data.animating ? ( | ||
<Room {...props} /> | ||
) : ( | ||
<div | ||
css={{ | ||
animation: `${ | ||
type === "addition" ? growHeight : shrinkHeight | ||
} 0.5s forwards`, | ||
}} | ||
></div> | ||
); | ||
}; | ||
|
||
export default AnimatedRoom; |
This file contains 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,79 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
const useRoomListAnimationState = (rooms: Nullable<Array<any>>) => { | ||
const [state, setState] = useState< | ||
"default" | "additionAnimate" | "addition" | "deletionAnimate" | "deletion" | ||
>("default"); | ||
|
||
const [localRooms, setLocalRooms] = useState(rooms); | ||
|
||
const animateDeletion = () => { | ||
const deletionRooms = localRooms?.map((localRoom) => { | ||
if (!rooms?.find((room) => room._id === localRoom._id)) { | ||
return { ...localRoom, animating: true, type: "deletion" }; | ||
} | ||
return localRoom; | ||
}); | ||
setLocalRooms(deletionRooms); | ||
const timer = setTimeout(() => { | ||
setState("deletion"); | ||
}, 500); | ||
|
||
return () => clearTimeout(timer); | ||
}; | ||
|
||
const deletion = () => { | ||
setLocalRooms(localRooms?.filter((room) => room.type !== "deletion")); | ||
setState("additionAnimate"); | ||
}; | ||
|
||
const animateAddition = () => { | ||
let additionRooms = rooms?.map((room, index) => { | ||
if (!localRooms?.find((localRoom) => localRoom._id === room._id)) { | ||
return { ...room, animating: true, type: "addition" }; | ||
} | ||
return room; | ||
}); | ||
setLocalRooms(additionRooms); | ||
const timer = setTimeout(() => { | ||
setState("addition"); | ||
}, 500); | ||
return () => clearTimeout(timer); | ||
}; | ||
|
||
const addition = () => { | ||
setLocalRooms(rooms); | ||
setState("default"); | ||
}; | ||
|
||
useEffect(() => { | ||
if (rooms && localRooms?.length && rooms.length !== localRooms.length) { | ||
setState("deletionAnimate"); | ||
} else { | ||
setLocalRooms(rooms); | ||
} | ||
}, [rooms]); | ||
|
||
useEffect(() => { | ||
switch (state) { | ||
case "deletionAnimate": | ||
animateDeletion(); | ||
break; | ||
case "deletion": | ||
deletion(); | ||
break; | ||
case "additionAnimate": | ||
animateAddition(); | ||
break; | ||
case "addition": | ||
addition(); | ||
break; | ||
default: | ||
break; | ||
} | ||
}, [state]); | ||
|
||
return { localRooms, state }; | ||
}; | ||
|
||
export default useRoomListAnimationState; |
This file contains 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,47 @@ | ||
import { keyframes } from "@emotion/react"; | ||
import { useEffect, useState } from "react"; | ||
|
||
import Room from "@/components/Room"; | ||
|
||
const DiffRoom = (props: any) => { | ||
const [animating, setAnimating] = useState(true); | ||
|
||
useEffect(() => { | ||
const timer = setTimeout(() => { | ||
setAnimating(false); | ||
}, 500); | ||
return () => clearTimeout(timer); | ||
}, []); | ||
|
||
const growHeight = keyframes` | ||
from { | ||
height: 0px; | ||
} | ||
to { | ||
height: 125px; | ||
} | ||
`; | ||
|
||
const shrinkHeight = keyframes` | ||
from { | ||
height: 125px; | ||
} | ||
to { | ||
height: 0px; | ||
} | ||
`; | ||
|
||
const animation = props.type === "addition" ? growHeight : shrinkHeight; | ||
|
||
return animating ? ( | ||
<div | ||
css={{ | ||
animation: `${animation} 0.5s forwards`, | ||
}} | ||
></div> | ||
) : props.type === "addition" ? ( | ||
<Room data={props.room} marginBottom={props.marginBottom} /> | ||
) : null; | ||
}; | ||
|
||
export default DiffRoom; |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.