feat(post): add post count and highlight functionality to u/address

This commit is contained in:
Tom (plebeius.eth)
2024-06-28 22:09:11 +02:00
parent 140900d1bc
commit a6a41edd76
8 changed files with 139 additions and 30 deletions
+29
View File
@@ -0,0 +1,29 @@
const useAuthorAddressClick = () => {
const handleUserAddressClick = (shortAddress: string | undefined) => {
if (!shortAddress) return;
// Select the elements corresponding to the clicked short address
const elements = document.querySelectorAll(`.${shortAddress}`);
// Check if the clicked address is already highlighted
const isAlreadyHighlighted = Array.from(elements).some((element) => element.classList.contains('highlight'));
// Remove highlight from all elements with the .highlight class
const prevElements = document.querySelectorAll('.highlight');
prevElements.forEach((element) => {
element.classList.remove('highlight');
});
// If the clicked address was already highlighted, don't add the highlight back
if (isAlreadyHighlighted) return;
// Highlight the new elements
elements.forEach((element) => {
element.classList.add('highlight');
});
};
return handleUserAddressClick;
};
export default useAuthorAddressClick;