Harvest valuable features from external/ reference repos, adapted to each product's stack and wired in; all products typecheck clean. - gitgram-web (5): clickable @mention/#hashtag linkify in rendered content (munia), + feed/notification/accessibility patterns; install @testing-library/dom - gitgram-backend (3): feed thread dedup + muted-thread removal (bluesky), GitHub star/follow write-back via OAuth (gh-social) - gitgram-mobile (4): double-tap-to-like + heart bounce (proximity), haptics layer (bluesky useHaptics), + gesture/feed UX - aitm-api (4): beads ready/dependency-DAG endpoints + atomic claim (beads) - aitm-mcp (6): beads_ready work-queue tool, context-efficient projections, transport arg aliasing (context7/pal-mcp/beads) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { create } from 'zustand';
|
|
|
|
export interface LightboxImage {
|
|
uri: string;
|
|
// Optional accessible description for the image.
|
|
alt?: string;
|
|
}
|
|
|
|
interface LightboxState {
|
|
visible: boolean;
|
|
images: LightboxImage[];
|
|
initialIndex: number;
|
|
|
|
/** Open the fullscreen lightbox with one or more images. */
|
|
open: (images: LightboxImage[], initialIndex?: number) => void;
|
|
close: () => void;
|
|
}
|
|
|
|
const sanitizeIndex = (index: number, length: number): number => {
|
|
if (length === 0) return 0;
|
|
if (index < 0) return 0;
|
|
if (index >= length) return length - 1;
|
|
return index;
|
|
};
|
|
|
|
/**
|
|
* Global state backing the app-wide image lightbox. Any component can call
|
|
* `open([...])` to present a fullscreen, zoomable, swipeable image viewer.
|
|
*/
|
|
export const useLightboxStore = create<LightboxState>((set) => ({
|
|
visible: false,
|
|
images: [],
|
|
initialIndex: 0,
|
|
|
|
open: (images, initialIndex = 0) => {
|
|
const valid = images.filter((image) => Boolean(image?.uri));
|
|
if (valid.length === 0) return;
|
|
set({
|
|
visible: true,
|
|
images: valid,
|
|
initialIndex: sanitizeIndex(initialIndex, valid.length),
|
|
});
|
|
},
|
|
|
|
close: () => set({ visible: false }),
|
|
}));
|