Make Spotlight Dialog roving reset more stable (#7698)
This commit is contained in:
parent
f5226f9d5b
commit
fce19d763a
1 changed files with 14 additions and 26 deletions
|
@ -21,7 +21,6 @@ import React, {
|
||||||
useCallback,
|
useCallback,
|
||||||
useContext,
|
useContext,
|
||||||
useEffect,
|
useEffect,
|
||||||
useLayoutEffect,
|
|
||||||
useMemo,
|
useMemo,
|
||||||
useState,
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
|
@ -184,25 +183,15 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", onFinished }) =>
|
||||||
});
|
});
|
||||||
}, [cli, query]);
|
}, [cli, query]);
|
||||||
|
|
||||||
// Reset the selection back to the first item whenever the query changes
|
|
||||||
useLayoutEffect(() => {
|
|
||||||
rovingContext.dispatch({
|
|
||||||
type: Type.SetFocus,
|
|
||||||
payload: {
|
|
||||||
ref: rovingContext.state.refs[0],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}, [query]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
||||||
|
|
||||||
const activeSpace = SpaceStore.instance.activeSpaceRoom;
|
const activeSpace = SpaceStore.instance.activeSpaceRoom;
|
||||||
const [spaceResults, spaceResultsLoading] = useSpaceResults(activeSpace, query);
|
const [spaceResults, spaceResultsLoading] = useSpaceResults(activeSpace, query);
|
||||||
|
|
||||||
const setQuery = (e: ChangeEvent<HTMLInputElement>): void => {
|
const setQuery = (e: ChangeEvent<HTMLInputElement>): void => {
|
||||||
const newQuery = e.currentTarget.value;
|
const newQuery = e.currentTarget.value;
|
||||||
_setQuery(newQuery);
|
_setQuery(newQuery);
|
||||||
if (!query !== !newQuery) {
|
|
||||||
setImmediate(() => {
|
setImmediate(() => {
|
||||||
// reset the activeRef when we start/stop querying as the view changes
|
// reset the activeRef when we change query for best usability
|
||||||
const ref = rovingContext.state.refs[0];
|
const ref = rovingContext.state.refs[0];
|
||||||
if (ref) {
|
if (ref) {
|
||||||
rovingContext.dispatch({
|
rovingContext.dispatch({
|
||||||
|
@ -214,7 +203,6 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", onFinished }) =>
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const viewRoom = (roomId: string, persist = false) => {
|
const viewRoom = (roomId: string, persist = false) => {
|
||||||
|
|
Loading…
Reference in a new issue