Something went wrong. Try again.
A Bsky-like frontend using the atprotocol natively.
Something went wrong. Try again.
1.1 kB · 31 lines
TSX
at main
1234567891011121314151617181920212223242526272829303132import { useState, useCallback, useEffect } from 'react';import type { VideoAutoplay } from '../settings/storage';import { getVideoAutoplay, setVideoAutoplay as persistVideoAutoplay } from '../settings/storage';import { VideoAutoplayContext } from './videoAutoplayContext';export { VideoAutoplayContext } from './videoAutoplayContext';
export function VideoAutoplayProvider({ children }: { children: React.ReactNode }) { const [autoplay, setAutoplayState] = useState<VideoAutoplay>(getVideoAutoplay);
const setAutoplay = useCallback((mode: VideoAutoplay) => { persistVideoAutoplay(mode); setAutoplayState(mode); }, []);
useEffect(() => { const handler = (e: StorageEvent) => { if (e.key === 'foxsky_settings') { setAutoplayState(getVideoAutoplay()); } }; window.addEventListener('storage', handler); return () => window.removeEventListener('storage', handler); }, []);
return ( <VideoAutoplayContext.Provider value={{ autoplay, setAutoplay }}> {children} </VideoAutoplayContext.Provider> );}