refactor(SW-194): PR comment fixes

This commit is contained in:
Matilda Landström
2024-10-14 08:44:56 +02:00
parent db44518acf
commit c8b3bd7e89
2 changed files with 22 additions and 24 deletions

View File

@@ -17,10 +17,9 @@ import { HotelHashValues } from "@/types/components/hotelPage/tabNavigation"
export function Rooms({ rooms }: RoomsProps) {
const intl = useIntl()
const initialPageSize = 5
const [pageSize, setPageSize] = useState(initialPageSize)
const showMoreVisible = rooms.length > initialPageSize
const showLessVisible = pageSize >= rooms.length
const showToggleButton = rooms.length > 5
const [allRoomsVisible, setAllRoomsVisible] = useState(!showToggleButton)
const scrollRef = useRef<HTMLDivElement>(null)
const mappedRooms = rooms
@@ -45,10 +44,10 @@ export function Rooms({ rooms }: RoomsProps) {
.sort((a, b) => a.sortOrder - b.sortOrder)
function handleShowMore() {
if (scrollRef.current && showMoreVisible) {
if (scrollRef.current && allRoomsVisible) {
scrollRef.current.scrollIntoView({ behavior: "smooth" })
}
setPageSize(showLessVisible ? initialPageSize : rooms.length)
setAllRoomsVisible((state) => !state)
}
return (
@@ -68,7 +67,7 @@ export function Rooms({ rooms }: RoomsProps) {
<div
key={id}
className={
!showLessVisible && index > 2 ? styles.hiddenRoomCard : ""
!allRoomsVisible && index > 2 ? styles.hiddenRoomCard : ""
}
>
<RoomCard
@@ -83,10 +82,10 @@ export function Rooms({ rooms }: RoomsProps) {
)}
</Grids.Stackable>
{showMoreVisible ? (
{showToggleButton ? (
<ShowMoreButton
loadMoreData={handleShowMore}
showLess={showLessVisible}
showLess={allRoomsVisible}
textShowMore="Show more rooms"
textShowLess="Show less rooms"
/>