-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added feedItem keyboard support
- Loading branch information
Showing
10 changed files
with
147 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/pages/commonFeed/components/FeedLayout/constants/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
export const BATCHES_AMOUNT_TO_PRELOAD = 2; | ||
export const ITEMS_AMOUNT_TO_PRE_LOAD_MESSAGES = 10; | ||
export const MENTION_TAG_ELEMENT = { | ||
key: "data-cy", | ||
value: "mentions-portal" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
export const useElementPresence = (attribute, value) => { | ||
const [elementPresent, setElementPresent] = useState(false); | ||
|
||
useEffect(() => { | ||
const observerCallback = (mutationsList) => { | ||
mutationsList.forEach((mutation) => { | ||
// Check for added nodes | ||
mutation.addedNodes.forEach((node) => { | ||
if ( | ||
node.nodeType === 1 && // Ensure it's an element | ||
node.getAttribute(attribute) === value | ||
) { | ||
setElementPresent(true); | ||
} | ||
}); | ||
|
||
// Check for removed nodes | ||
mutation.removedNodes.forEach((node) => { | ||
if ( | ||
node.nodeType === 1 && // Ensure it's an element | ||
node.getAttribute(attribute) === value | ||
) { | ||
setElementPresent(false); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
const observer = new MutationObserver(observerCallback); | ||
|
||
// Start observing the entire document | ||
observer.observe(document.body, { childList: true, subtree: true }); | ||
|
||
// Check initially if the element is already present | ||
const initialElement = document.querySelector(`[${attribute}="${value}"]`); | ||
if (initialElement) { | ||
setElementPresent(true); | ||
} | ||
|
||
return () => { | ||
observer.disconnect(); // Cleanup observer on unmount | ||
}; | ||
}, [attribute, value]); | ||
|
||
return elementPresent; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
export const useIsElementFocused = (id: string) => { | ||
const [isFocused, setIsFocused] = useState(false); | ||
|
||
useEffect(() => { | ||
const handleFocusChange = () => { | ||
const element = document.getElementById(id); | ||
setIsFocused(document.activeElement === element); | ||
}; | ||
|
||
// Listen to focus changes globally | ||
document.addEventListener("focusin", handleFocusChange); | ||
document.addEventListener("focusout", handleFocusChange); | ||
|
||
// Cleanup | ||
return () => { | ||
document.removeEventListener("focusin", handleFocusChange); | ||
document.removeEventListener("focusout", handleFocusChange); | ||
}; | ||
}, [id]); | ||
|
||
return isFocused; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters