mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-08 08:10:29 +03:00
Fix auto read (#1466)
* add height to bottom anchor * add width to bottom anchor * add make bottom anchor inline-block * try mark as read on focus receive
This commit is contained in:
parent
03af183fb3
commit
5dc613cd79
2 changed files with 47 additions and 8 deletions
25
src/app/hooks/useDocumentFocusChange.ts
Normal file
25
src/app/hooks/useDocumentFocusChange.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { useEffect } from 'react';
|
||||
|
||||
export const useDocumentFocusChange = (onChange: (focus: boolean) => void) => {
|
||||
useEffect(() => {
|
||||
let localFocus = document.hasFocus();
|
||||
|
||||
const handleFocus = () => {
|
||||
if (document.hasFocus()) {
|
||||
if (localFocus) return;
|
||||
localFocus = true;
|
||||
onChange(localFocus);
|
||||
} else if (localFocus) {
|
||||
localFocus = false;
|
||||
onChange(localFocus);
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener('focusin', handleFocus);
|
||||
document.addEventListener('focusout', handleFocus);
|
||||
return () => {
|
||||
document.removeEventListener('focusin', handleFocus);
|
||||
document.removeEventListener('focusout', handleFocus);
|
||||
};
|
||||
}, [onChange]);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue