diff --git a/src/components/views/Board.jsx b/src/components/views/Board.jsx index d96c6449..78657676 100644 --- a/src/components/views/Board.jsx +++ b/src/components/views/Board.jsx @@ -14,6 +14,7 @@ import SettingsModal from '../SettingsModal'; import findShortParentCid from '../../utils/findShortParentCid'; import getCommentMediaInfo from '../../utils/getCommentMediaInfo'; import getDate from '../../utils/getDate'; +import handleAddressClick from '../../utils/handleAddressClick'; import handleQuoteClick from '../../utils/handleQuoteClick'; import handleStyleChange from '../../utils/handleStyleChange'; import renderComments from '../../utils/renderComments'; @@ -449,7 +450,10 @@ const Board = () => { Anonymous}   (u/ - + handleAddressClick(thread.author.shortAddress)} + > {thread.author.shortAddress} )   @@ -542,7 +546,10 @@ const Board = () => { : Anonymous}   - + handleAddressClick(reply.author.shortAddress)} + > (u/ {reply.author.shortAddress} @@ -675,7 +682,10 @@ const Board = () => { : Anonymous}   - + handleAddressClick(thread.author.shortAddress)} + > (u/ {thread.author.shortAddress} @@ -801,7 +811,10 @@ const Board = () => { : Anonymous}   - + handleAddressClick(reply.author.shortAddress)} + > (u/ {reply.author.shortAddress} diff --git a/src/components/views/Thread.jsx b/src/components/views/Thread.jsx index db97963c..fd63a513 100644 --- a/src/components/views/Thread.jsx +++ b/src/components/views/Thread.jsx @@ -14,6 +14,7 @@ import SettingsModal from '../SettingsModal'; import findShortParentCid from '../../utils/findShortParentCid'; import getCommentMediaInfo from '../../utils/getCommentMediaInfo'; import getDate from '../../utils/getDate'; +import handleAddressClick from '../../utils/handleAddressClick'; import handleQuoteClick from '../../utils/handleQuoteClick'; import handleStyleChange from '../../utils/handleStyleChange'; import renderThreadComments from '../../utils/renderThreadComments'; @@ -467,7 +468,9 @@ const Thread = () => { Anonymous}     - + handleAddressClick(comment.author?.shortAddress)}> (u/ {comment.author?.shortAddress} @@ -532,7 +535,10 @@ const Thread = () => { : Anonymous}   - + handleAddressClick(reply.author?.shortAddress)} + > (u/ {reply.author?.shortAddress ?? reply.author.address} @@ -649,7 +655,10 @@ const Thread = () => { : Anonymous}   - + handleAddressClick(comment.author?.shortAddress)} + > (u/ {comment.author?.shortAddress} @@ -745,7 +754,10 @@ const Thread = () => { : Anonymous}   - + handleAddressClick(reply.author?.shortAddress)} + > (u/ {reply.author?.shortAddress} diff --git a/src/utils/handleAddressClick.js b/src/utils/handleAddressClick.js new file mode 100644 index 00000000..b4283ecf --- /dev/null +++ b/src/utils/handleAddressClick.js @@ -0,0 +1,29 @@ +function handleAddressClick(shortAddress) { + const isMobile = window.innerWidth <= 480; + const addressSelector = isMobile ? '.address-mobile' : '.address-desktop'; + const postReplySelector = isMobile ? '.post-reply-mobile' : '.post-reply-desktop'; + const opSelector = isMobile ? '.op-mobile' : '.op-desktop'; + + const matchingElements = [...document.querySelectorAll(postReplySelector + ',' + opSelector)].filter(el => { + const addressElement = el.querySelector(addressSelector); + return addressElement && addressElement.textContent.includes(shortAddress); + }); + + if (matchingElements.length === 0) { + console.log('Could not find any matching elements'); + return; + } + + const highlightedElements = document.querySelectorAll('.highlighted'); + highlightedElements.forEach(el => { + el.classList.remove('highlighted'); + }); + + matchingElements.forEach(el => { + if (!el.classList.contains('op-mobile') && !el.classList.contains('op-desktop')) { + el.classList.add('highlighted'); + } + }); +} + +export default handleAddressClick; \ No newline at end of file