mirror of
https://github.com/stashapp/stash.git
synced 2026-01-30 20:13:58 +01:00
* Add scene detail header * Make common count button and add view count * Add titles to play count and o count buttons * Move rating from edit panel * Include frame rate in header * Remove redundant title/studio * Improve numeric rating presentation * Add star where there is no rating header * Set rating on blur when click to edit * Add star to numeric rating on gallery wall card * Apply click to rate on movie page * Apply click to rate to performer page * Apply click to rate to studio page * Fix rating number presentation on list tables * Add data-value attributes
31 lines
766 B
TypeScript
31 lines
766 B
TypeScript
import { useRef, useEffect } from "react";
|
|
|
|
const useFocus = () => {
|
|
const htmlElRef = useRef<HTMLInputElement | null>(null);
|
|
const setFocus = () => {
|
|
const currentEl = htmlElRef.current;
|
|
if (currentEl) {
|
|
currentEl.focus();
|
|
}
|
|
};
|
|
|
|
// eslint-disable-next-line no-undef
|
|
return [htmlElRef, setFocus] as const;
|
|
};
|
|
|
|
// focuses on the element only once on mount
|
|
export const useFocusOnce = (active?: boolean, override?: boolean) => {
|
|
const [htmlElRef, setFocus] = useFocus();
|
|
const focused = useRef(false);
|
|
|
|
useEffect(() => {
|
|
if ((!focused.current || override) && active) {
|
|
setFocus();
|
|
focused.current = true;
|
|
}
|
|
}, [setFocus, active, override]);
|
|
|
|
return [htmlElRef, setFocus] as const;
|
|
};
|
|
|
|
export default useFocus;
|