import { ArrowLeft, ArrowRight, RotateCw, Folders, Menu, SquareArrowOutUpRight, Info, Search, Lock, } from 'lucide-react'; import clsx from 'clsx'; import { useState, useEffect, useRef, useMemo } from 'react'; import loaderStore from '/src/utils/hooks/loader/useLoaderStore'; import { process, openEmbed } from '/src/utils/hooks/loader/utils'; import { useOptions } from '/src/utils/optionsContext'; import { useLocation, useNavigate } from 'react-router-dom'; const Action = ({ Icon, size = 15, action = () => alert('nothing here yet'), disabled = false }) => { const { options } = useOptions(); return ( ); }; const Omnibox = () => { const [Icon, setIcon] = useState(Info); const activeTab = loaderStore((state) => state.tabs.find((tab) => tab.active)); const { updateUrl, refreshTab, goBack, goForward, toggleTabs, toggleMenu, showUI } = loaderStore(); const inputRef = useRef(null); const { options } = useOptions(); const { state } = useLocation(); const navigate = useNavigate(); const { iframeUrls } = loaderStore(); const isProcied = (url) => url?.includes('portal/k12/') || url?.includes('ham/'); const isNewTab = (url) => !url || url === 'tabs://new' || url.endsWith('/new'); const updateIcon = (url) => { if (isNewTab(url)) { setIcon(Info); } else if (isProcied(url)) { const decoded = process(url, true, options.prType || 'scr', options.engine || undefined); setIcon(decoded.startsWith('https://') ? Lock : Info); } else { setIcon(Info); } }; const getDisplayUrl = (url) => { if (isNewTab(url)) return ''; if (isProcied(url)) { const decoded = process(url, true, options.prType || 'scr', options.engine || undefined); return decoded.startsWith('https://') ? decoded.slice(8) : decoded; } return url; }; const [input, setInput] = useState(getDisplayUrl(activeTab?.url)); useEffect(() => { const url = iframeUrls[activeTab?.id]; if (activeTab?.url === 'tabs://new') { setInput(''); } else if (url && url !== 'about:blank') { setInput(getDisplayUrl(url)); updateIcon(url); } }, [iframeUrls, activeTab?.id]); useEffect(() => { if (state?.url && activeTab) { const processedUrl = process(state.url, false, options.prType || 'scr', options.engine || undefined); if (processedUrl) { updateUrl(activeTab.id, processedUrl); } navigate('.', { replace: true, state: {} }); } }, [state?.url, activeTab?.id]); useEffect(() => { if (activeTab) { updateIcon(activeTab.url); } }, [activeTab]); return (
activeTab && goBack(activeTab.id, () => { setInput(''); }) } /> {/** ^^ callback used if going back to a new tab only */} activeTab && goForward(activeTab.id)} /> activeTab && refreshTab(activeTab.id)} />
setIcon(Search)} onBlur={() => updateIcon(iframeUrls[activeTab?.id])} value={input} ref={inputRef} onChange={(e) => setInput(e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter' && activeTab && input.length !== 0) { const processedUrl = process(input, false, options.prType || 'scr', options.engine || undefined); if (processedUrl) { updateUrl(activeTab.id, processedUrl); } inputRef.current.blur(); } }} >
openEmbed(activeTab?.url)} disabled={activeTab?.url == 'tabs://new'} /> { e?.stopPropagation(); toggleMenu(); }} />
); }; export default Omnibox;