'use client'; import { FC, RefObject, useEffect, useRef, useState } from 'react'; import { useLaunchStore } from '@gitroom/frontend/components/new-launch/store'; import clsx from 'clsx'; import Image from 'next/image'; import { useShallow } from 'zustand/react/shallow'; import { GlobalIcon } from '@gitroom/frontend/components/ui/icons'; import { useT } from '@gitroom/react/translation/get.transation.service.client'; export function useHasScroll(ref: RefObject): boolean { const [hasHorizontalScroll, setHasHorizontalScroll] = useState(false); useEffect(() => { if (!ref.current) return; const checkScroll = () => { const el = ref.current; if (el) { setHasHorizontalScroll(el.scrollWidth > el.clientWidth); } }; checkScroll(); // initial check const resizeObserver = new ResizeObserver(checkScroll); resizeObserver.observe(ref.current); const mutationObserver = new MutationObserver(checkScroll); mutationObserver.observe(ref.current, { childList: true, subtree: true, characterData: true, }); return () => { resizeObserver.disconnect(); mutationObserver.disconnect(); }; }, [ref]); return hasHorizontalScroll; } export const SelectCurrent: FC = () => { const { selectedIntegrations, current, setCurrent, locked, setHide, hide } = useLaunchStore( useShallow((state) => ({ selectedIntegrations: state.selectedIntegrations, current: state.current, setCurrent: state.setCurrent, locked: state.locked, hide: state.hide, setHide: state.setHide, })) ); const contentRef = useRef(null); const hasScroll = useHasScroll(contentRef); useEffect(() => { if (!hide) { return; } setHide(false); }, [hide]); return ( <>
{ setHide(true); setCurrent('global'); }} className={clsx( 'cursor-pointer flex gap-[8px] rounded-[8px] w-[40px] h-[40px] justify-center items-center bg-newBgLineColor', current !== 'global' ? 'text-[#A3A3A3]' : 'border border-[#FC69FF] text-[#FC69FF]' )} >
{selectedIntegrations.map(({ integration }) => (
{ setHide(true); setCurrent(integration.id); }} key={integration.id} className={clsx( 'border cursor-pointer relative flex gap-[8px] w-[40px] h-[40px] rounded-[8px] items-center bg-newBgLineColor justify-center', current === integration.id ? 'border-[#FC69FF] text-[#FC69FF]' : 'border-transparent' )} >
{integration.identifier} {integration.identifier === 'youtube' ? ( ) : ( {integration.identifier} )}
))}
); }; export const IsGlobal: FC<{ id: string }> = ({ id }) => { const t = useT(); const { isInternal } = useLaunchStore( useShallow((state) => ({ isInternal: !!state.internal.find(p => p.integration.id === id), })) ); if (!isInternal) { return null; } return (
); };