Skip to content

Commit 496838c

Browse files
committed
context aware search menu
1 parent 41cf380 commit 496838c

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
default: minor
3+
---
4+
5+
`Ctrl + K` search menu is now context aware and lists the current space's rooms at the top.

src/app/features/search/Search.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import { useKeyDown } from '$hooks/useKeyDown';
5555
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
5656
import { KeySymbol } from '$utils/key-symbol';
5757
import { isMacOS } from '$utils/user-agent';
58+
import { useSelectedSpace } from '$hooks/router/useSelectedSpace';
5859

5960
enum SearchRoomType {
6061
Rooms = '#',
@@ -167,7 +168,19 @@ export function Search({ requestClose }: SearchProps) {
167168
);
168169

169170
const [result, search, resetSearch] = useAsyncSearch(targetRooms, getTargetStr, SEARCH_OPTIONS);
170-
const roomsToRender = result ? result.items : topActiveRooms;
171+
const selectedSpaceId = useSelectedSpace();
172+
173+
const roomsToRender = useMemo(() => {
174+
const items = result ? result.items : topActiveRooms;
175+
if (!selectedSpaceId) return items;
176+
177+
return [...items].sort((a, b) => {
178+
const aInSpace = getAllParents(roomToParents, a)?.has(selectedSpaceId) ? 1 : 0;
179+
const bInSpace = getAllParents(roomToParents, b)?.has(selectedSpaceId) ? 1 : 0;
180+
return bInSpace - aInSpace;
181+
});
182+
}, [result, topActiveRooms, selectedSpaceId, roomToParents]);
183+
171184
const listFocus = useListFocusIndex(roomsToRender.length, 0);
172185

173186
const queryHighlighRegex = result?.query

0 commit comments

Comments
 (0)