mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-09 16:50:28 +03:00
Add new ctrl/cmd - k search modal (#2467)
Some checks failed
Deploy to Netlify (dev) / Deploy to Netlify (push) Has been cancelled
Some checks failed
Deploy to Netlify (dev) / Deploy to Netlify (push) Has been cancelled
* add new search modal * remove search modal from searchTab * fix member avatar load for space with 2 member * use media authentication when rendering avatar * fix hotkey for macos * add @ in username * replace subspace minus separator with em dash
This commit is contained in:
parent
c1274e851a
commit
399b1a373e
9 changed files with 523 additions and 23 deletions
36
src/app/hooks/useListFocusIndex.ts
Normal file
36
src/app/hooks/useListFocusIndex.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { useCallback, useState } from 'react';
|
||||
|
||||
export const useListFocusIndex = (size: number, initialIndex: number) => {
|
||||
const [index, setIndex] = useState(initialIndex);
|
||||
|
||||
const next = useCallback(() => {
|
||||
setIndex((i) => {
|
||||
const nextIndex = i + 1;
|
||||
if (nextIndex >= size) {
|
||||
return 0;
|
||||
}
|
||||
return nextIndex;
|
||||
});
|
||||
}, [size]);
|
||||
|
||||
const previous = useCallback(() => {
|
||||
setIndex((i) => {
|
||||
const previousIndex = i - 1;
|
||||
if (previousIndex < 0) {
|
||||
return size - 1;
|
||||
}
|
||||
return previousIndex;
|
||||
});
|
||||
}, [size]);
|
||||
|
||||
const reset = useCallback(() => {
|
||||
setIndex(initialIndex);
|
||||
}, [initialIndex]);
|
||||
|
||||
return {
|
||||
index,
|
||||
next,
|
||||
previous,
|
||||
reset,
|
||||
};
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue