From 8221b1681933934554f64c04ea97941a81f7f2d0 Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Wed, 29 Jul 2026 06:59:36 -0700 Subject: [PATCH] Add swiper buttons --- src/app/main/page.tsx | 135 ++++++++++++++++++++++++++++-------------- 1 file changed, 92 insertions(+), 43 deletions(-) diff --git a/src/app/main/page.tsx b/src/app/main/page.tsx index e002ce9..29cd49a 100644 --- a/src/app/main/page.tsx +++ b/src/app/main/page.tsx @@ -1,11 +1,20 @@ 'use client' import { useGlobal } from '@/providers/GlobalProvider' -import 'swiper/css' import { Swiper, SwiperSlide } from 'swiper/react' +import type { Swiper as SwiperType } from 'swiper' +import { Navigation } from 'swiper/modules' +import 'swiper/css' +import 'swiper/css/navigation' import { formatDistanceToNow } from 'date-fns' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import { faEllipsis, faPlay } from '@fortawesome/free-solid-svg-icons' +import { + faChevronLeft, + faChevronRight, + faEllipsis, + faPlay +} from '@fortawesome/free-solid-svg-icons' +import { useRef } from 'react' export default function HomePage () { const { @@ -35,6 +44,10 @@ export default function HomePage () { .sort((a, b) => b[1] - a[1]) ) + const swiperRef = useRef(null) + const prevRef = useRef(null) + const nextRef = useRef(null) + return (
@@ -46,48 +59,84 @@ export default function HomePage () { {Object.entries(filteredLaunchesList).length == 0 ? (

You have no recently launched games

) : ( - - {Object.entries(filteredLaunchesList).map(([key, timestamp]) => { - const versionInfo = serverVersionList?.versions.find( - v => v.id == key.split('-').slice(1).join('-') - ) - if (!versionInfo) return +
+ { + swiperRef.current = swiper + }} + onBeforeInit={swiper => { + if ( + swiper.params.navigation && + typeof swiper.params.navigation !== 'boolean' + ) { + swiper.params.navigation.prevEl = prevRef.current + swiper.params.navigation.nextEl = nextRef.current + } + }} + > + {Object.entries(filteredLaunchesList).map(([key, timestamp]) => { + const versionInfo = serverVersionList?.versions.find( + v => v.id == key.split('-').slice(1).join('-') + ) + if (!versionInfo) return - return ( - -

- {versionInfo?.displayName} -

-

- Last played{' '} - {formatDistanceToNow(new Date(timestamp), { - addSuffix: true - })} -

-
- await launchGame(versionInfo)} - /> - { - setManagingVersion(versionInfo.id) - setPopupMode(2) - setShowPopup(true) - setFadeOut(false) - }} - /> -
-
- ) - })} -
+ return ( + +

+ {versionInfo?.displayName} +

+

+ Last played{' '} + {formatDistanceToNow(new Date(timestamp), { + addSuffix: true + })} +

+
+ await launchGame(versionInfo)} + /> + { + setManagingVersion(versionInfo.id) + setPopupMode(2) + setShowPopup(true) + setFadeOut(false) + }} + /> +
+
+ ) + })} + +
+ + +
+
)}