Persistently shown navigation bar
()
| 71 | |
| 72 | /** Persistently shown navigation bar */ |
| 73 | function NavBar() { |
| 74 | const [subject] = useCurrentSubject(); |
| 75 | const [input, setInput] = useState<string>(''); |
| 76 | const [query] = useSearchQuery(); |
| 77 | const history = useHistory(); |
| 78 | const [inputRef, setInputFocus] = useFocus(); |
| 79 | const { navbarTop, navbarFloating, sideBarLocked, setSideBarLocked, agent } = |
| 80 | useSettings(); |
| 81 | const [showButtons, setShowButtons] = React.useState<boolean>(true); |
| 82 | |
| 83 | useEffect(() => { |
| 84 | setInput(query); |
| 85 | }, [query]); |
| 86 | |
| 87 | useEffect(() => { |
| 88 | // Prevents setting an empty input if the first letter of a query has just been typed |
| 89 | !query && setInput(subject); |
| 90 | }, [subject, query]); |
| 91 | |
| 92 | useHotkeys('/', e => { |
| 93 | e.preventDefault(); |
| 94 | //@ts-ignore this does seem callable |
| 95 | inputRef.current.select(); |
| 96 | }); |
| 97 | |
| 98 | useHotkeys( |
| 99 | 'esc', |
| 100 | e => { |
| 101 | e.preventDefault(); |
| 102 | //@ts-ignore this does seem callable |
| 103 | inputRef.current.blur(); |
| 104 | }, |
| 105 | { enableOnTags: ['INPUT'] }, |
| 106 | ); |
| 107 | |
| 108 | useHotkeys('/', e => { |
| 109 | e.preventDefault(); |
| 110 | setInputFocus(); |
| 111 | }); |
| 112 | |
| 113 | function handleChange(e) { |
| 114 | setInput(e.target.value); |
| 115 | try { |
| 116 | tryValidURL(e.target.value); |
| 117 | // Replace instead of push to make the back-button behavior better. |
| 118 | history.replace(openURL(e.target.value)); |
| 119 | } catch (_err) { |
| 120 | history.replace(searchURL(e.target.value)); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | function handleSelect(e) { |
| 125 | e.target.select(); |
| 126 | } |
| 127 | |
| 128 | /** Checks if the app is running in PWA / stand alone mode or in a browser */ |
| 129 | const isInStandaloneMode = () => |
| 130 | window.matchMedia('(display-mode: standalone)').matches || |
nothing calls this directly
no test coverage detected