refactor(SW-194): PR comment fixes
This commit is contained in:
@@ -11,38 +11,37 @@ import ShowMoreButton from "@/components/TempDesignSystem/ShowMoreButton"
|
|||||||
import styles from "./accordion.module.css"
|
import styles from "./accordion.module.css"
|
||||||
|
|
||||||
import type { AccordionProps } from "@/types/components/blocks/Accordion"
|
import type { AccordionProps } from "@/types/components/blocks/Accordion"
|
||||||
|
import { HotelHashValues } from "@/types/components/hotelPage/tabNavigation"
|
||||||
|
|
||||||
export default function AccordionSection({ accordion, title }: AccordionProps) {
|
export default function AccordionSection({ accordion, title }: AccordionProps) {
|
||||||
const initialPageSize = 5
|
const showToggleButton = accordion.length > 5
|
||||||
const [pageSize, setPageSize] = useState(initialPageSize)
|
const [allAccordionsVisible, setAllAccordionsVisible] =
|
||||||
const showMoreVisible = accordion.length > initialPageSize
|
useState(!showToggleButton)
|
||||||
const showLessVisible = pageSize >= accordion.length
|
|
||||||
|
|
||||||
function handleShowMore() {
|
function toggleAccordions() {
|
||||||
setPageSize(showLessVisible ? initialPageSize : accordion.length)
|
setAllAccordionsVisible((state) => !state)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getClassName(idx: number): string {
|
function getClassName(idx: number): string {
|
||||||
if (showMoreVisible && idx > pageSize - 1) {
|
if (!allAccordionsVisible && idx > 4) {
|
||||||
return styles.hiddenItem
|
return styles.hiddenItem
|
||||||
} else if (showMoreVisible && idx == pageSize - 1) {
|
} else if (!allAccordionsVisible && idx === 4) {
|
||||||
return styles.lastItem
|
return styles.lastItem
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SectionContainer id="faq">
|
<SectionContainer id={HotelHashValues.faq}>
|
||||||
{title && <SectionHeader textTransform="uppercase" title={title} />}
|
{title && <SectionHeader textTransform="uppercase" title={title} />}
|
||||||
<Accordion theme={"light"} variant={"card"}>
|
<Accordion theme="light" variant="card">
|
||||||
{accordion.map((acc, idx: number) => (
|
{accordion.map((acc, idx: number) => (
|
||||||
<AccordionItem
|
<AccordionItem
|
||||||
key={`${acc.question}-${idx}`}
|
key={acc.question}
|
||||||
title={acc.question}
|
title={acc.question}
|
||||||
className={getClassName(idx)}
|
className={getClassName(idx)}
|
||||||
>
|
>
|
||||||
<JsonToHtml
|
<JsonToHtml
|
||||||
key={`${acc.question}-${idx}`}
|
|
||||||
embeds={acc.answer.embedded_itemsConnection.edges}
|
embeds={acc.answer.embedded_itemsConnection.edges}
|
||||||
nodes={acc.answer.json?.children[0].children}
|
nodes={acc.answer.json?.children[0].children}
|
||||||
/>
|
/>
|
||||||
@@ -50,10 +49,10 @@ export default function AccordionSection({ accordion, title }: AccordionProps) {
|
|||||||
))}
|
))}
|
||||||
</Accordion>
|
</Accordion>
|
||||||
|
|
||||||
{showMoreVisible ? (
|
{showToggleButton ? (
|
||||||
<ShowMoreButton
|
<ShowMoreButton
|
||||||
loadMoreData={handleShowMore}
|
loadMoreData={toggleAccordions}
|
||||||
showLess={showLessVisible}
|
showLess={allAccordionsVisible}
|
||||||
textShowMore="See all FAQ"
|
textShowMore="See all FAQ"
|
||||||
textShowLess="See less FAQ"
|
textShowLess="See less FAQ"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -17,10 +17,9 @@ import { HotelHashValues } from "@/types/components/hotelPage/tabNavigation"
|
|||||||
|
|
||||||
export function Rooms({ rooms }: RoomsProps) {
|
export function Rooms({ rooms }: RoomsProps) {
|
||||||
const intl = useIntl()
|
const intl = useIntl()
|
||||||
const initialPageSize = 5
|
const showToggleButton = rooms.length > 5
|
||||||
const [pageSize, setPageSize] = useState(initialPageSize)
|
const [allRoomsVisible, setAllRoomsVisible] = useState(!showToggleButton)
|
||||||
const showMoreVisible = rooms.length > initialPageSize
|
|
||||||
const showLessVisible = pageSize >= rooms.length
|
|
||||||
const scrollRef = useRef<HTMLDivElement>(null)
|
const scrollRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
const mappedRooms = rooms
|
const mappedRooms = rooms
|
||||||
@@ -45,10 +44,10 @@ export function Rooms({ rooms }: RoomsProps) {
|
|||||||
.sort((a, b) => a.sortOrder - b.sortOrder)
|
.sort((a, b) => a.sortOrder - b.sortOrder)
|
||||||
|
|
||||||
function handleShowMore() {
|
function handleShowMore() {
|
||||||
if (scrollRef.current && showMoreVisible) {
|
if (scrollRef.current && allRoomsVisible) {
|
||||||
scrollRef.current.scrollIntoView({ behavior: "smooth" })
|
scrollRef.current.scrollIntoView({ behavior: "smooth" })
|
||||||
}
|
}
|
||||||
setPageSize(showLessVisible ? initialPageSize : rooms.length)
|
setAllRoomsVisible((state) => !state)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -68,7 +67,7 @@ export function Rooms({ rooms }: RoomsProps) {
|
|||||||
<div
|
<div
|
||||||
key={id}
|
key={id}
|
||||||
className={
|
className={
|
||||||
!showLessVisible && index > 2 ? styles.hiddenRoomCard : ""
|
!allRoomsVisible && index > 2 ? styles.hiddenRoomCard : ""
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<RoomCard
|
<RoomCard
|
||||||
@@ -83,10 +82,10 @@ export function Rooms({ rooms }: RoomsProps) {
|
|||||||
)}
|
)}
|
||||||
</Grids.Stackable>
|
</Grids.Stackable>
|
||||||
|
|
||||||
{showMoreVisible ? (
|
{showToggleButton ? (
|
||||||
<ShowMoreButton
|
<ShowMoreButton
|
||||||
loadMoreData={handleShowMore}
|
loadMoreData={handleShowMore}
|
||||||
showLess={showLessVisible}
|
showLess={allRoomsVisible}
|
||||||
textShowMore="Show more rooms"
|
textShowMore="Show more rooms"
|
||||||
textShowLess="Show less rooms"
|
textShowLess="Show less rooms"
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user