mirror of
https://github.com/Sped0n/bridget.git
synced 2026-04-22 14:09:30 -07:00
refactor: split monolithic state into context-based modules
Extract image, desktop, mobile, and config state into separate context providers to improve modularity and reduce unnecessary re-renders. Signed-off-by: Sped0n <hi@sped0n.com>
This commit is contained in:
26
assets/ts/mobile/galleryUtils.ts
Normal file
26
assets/ts/mobile/galleryUtils.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { type Swiper } from 'swiper'
|
||||
|
||||
import type { Vector } from '../utils'
|
||||
|
||||
export async function loadSwiper(): Promise<typeof Swiper> {
|
||||
const swiper = await import('swiper')
|
||||
return swiper.Swiper
|
||||
}
|
||||
|
||||
export function getActiveImageIndexes(
|
||||
currentIndex: number,
|
||||
length: number,
|
||||
navigateVector: Vector
|
||||
): number[] {
|
||||
const nextIndex = Math.min(currentIndex + 1, length - 1)
|
||||
const prevIndex = Math.max(currentIndex - 1, 0)
|
||||
|
||||
switch (navigateVector) {
|
||||
case 'next':
|
||||
return [nextIndex]
|
||||
case 'prev':
|
||||
return [prevIndex]
|
||||
case 'none':
|
||||
return [currentIndex, nextIndex, prevIndex]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user