Taskbar search tweaks

This commit is contained in:
Dustin Brett 2023-11-16 22:00:43 -08:00
parent da94d68318
commit 4615ad62cf
4 changed files with 19 additions and 5 deletions

View File

@ -49,15 +49,20 @@ const Details: FC<{
const isDirectory =
stats?.isDirectory() || (!extension && !isYTUrl && !isNostrUrl);
const baseUrl = isYTUrl || isNostrUrl ? url : info?.url;
const currentUrlRef = useRef(url);
useEffect(() => {
stat(url).then(setStats);
getResultInfo(fs, url).then(setInfo);
stat(url).then(
(newStats) => currentUrlRef.current === url && setStats(newStats)
);
getResultInfo(fs, url).then(
(newInfo) => currentUrlRef.current === url && setInfo(newInfo)
);
}, [fs, stat, url]);
useEffect(() => {
elementRef.current?.scrollTo({ behavior: "smooth", top: 0 });
// eslint-disable-next-line react-hooks-addons/no-unused-deps
currentUrlRef.current = url;
}, [url]);
return info?.url && stats ? (

View File

@ -40,6 +40,7 @@ import Icon from "styles/common/Icon";
import {
DESKTOP_PATH,
FOCUSABLE_ELEMENT,
KEYPRESS_DEBOUNCE_MS,
PICTURES_FOLDER,
PREVENT_SCROLL,
SHORTCUT_EXTENSION,
@ -160,6 +161,7 @@ const Search: FC<SearchProps> = ({ toggleSearch }) => {
},
[open, toggleSearch]
);
const searchTimeoutRef = useRef(0);
useEffect(() => {
if (
@ -436,7 +438,11 @@ const Search: FC<SearchProps> = ({ toggleSearch }) => {
? inputRef.current?.value.replace(tabAppend, "")
: inputRef.current?.value;
setSearchTerm(value ?? "");
window.clearTimeout(searchTimeoutRef.current);
searchTimeoutRef.current = window.setTimeout(
() => setSearchTerm(value ?? ""),
searchTimeoutRef.current > 0 ? KEYPRESS_DEBOUNCE_MS : 0
);
}}
onKeyDown={({ key }) => {
if (key === "Enter" && firstResult?.ref) {

View File

@ -7,6 +7,7 @@ import { useSession } from "contexts/session";
import { useViewport } from "contexts/viewport";
import { useProcessesRef } from "hooks/useProcessesRef";
import { useEffect, useRef } from "react";
import { KEYPRESS_DEBOUNCE_MS } from "utils/constants";
import { haltEvent, toggleShowDesktop } from "utils/functions";
declare global {
@ -39,7 +40,7 @@ const haltAndDebounceBinding = (event: KeyboardEvent): boolean => {
triggeringBinding = true;
setTimeout(() => {
triggeringBinding = false;
}, 150);
}, KEYPRESS_DEBOUNCE_MS);
return false;
};

View File

@ -203,6 +203,8 @@ export const TRANSITIONS_IN_SECONDS = {
WINDOW: TRANSITIONS_IN_MILLISECONDS.WINDOW / MILLISECONDS_IN_SECOND,
};
export const KEYPRESS_DEBOUNCE_MS = 150;
export const LONG_PRESS_DELAY_MS = 750;
export const ONE_DAY_IN_MILLISECONDS = 86400000;