From 17098d073be3bc42d1e8526becec88c0e78560bf Mon Sep 17 00:00:00 2001 From: appala venkata avinash Date: Wed, 17 Apr 2024 00:07:54 +0530 Subject: [PATCH 1/2] Added hashtags in the post container seperately --- src/components/Posts/index.js | 126 ++++++++++++++++++++++------------ 1 file changed, 82 insertions(+), 44 deletions(-) diff --git a/src/components/Posts/index.js b/src/components/Posts/index.js index f5076d0..bc842ee 100644 --- a/src/components/Posts/index.js +++ b/src/components/Posts/index.js @@ -1,6 +1,7 @@ import { getEventHash, getSignature, nip19, SimplePool } from 'nostr-tools'; import { fetchInvoice, getProfileMetadata, getZapEndpoint } from '../ZapHelper'; import { Link } from 'react-router-dom'; +import { useNavigate } from 'react-router-dom'; import React, { useEffect, useState } from 'react'; import ZapModal from '../ZapHelper/ZapModal'; import { ShareModal } from '../Share/modal'; @@ -94,6 +95,10 @@ export const removeHashtagsAndLinks = text => { return text.replace(/(https?:\/\/[^\s]+)/g, ''); }; +export function extractHashtags(text) { + return text.match(/#\w+/g) || []; +} + export async function upvotePost(noteId, userPublicKey) { const storedData = localStorage.getItem('memestr'); @@ -322,6 +327,7 @@ function Posts(props) { let title = removeHashtagsAndLinks(props.note.content) .trimLeft() .trimRight(); + if (title.length === 0) { title = ' '; } @@ -376,6 +382,7 @@ function Posts(props) { } let truncatedTitle = truncateTitle(title, 70); + let hashtags = extractHashtags(truncatedTitle); let titleWithLinks = convertHashtagsToLinks(truncatedTitle); function renderContent(imageLink) { @@ -420,6 +427,10 @@ function Posts(props) { } }); } + const navigate = useNavigate(); + const handleTagClick = suggestions => { + navigate(`/search/${suggestions}`); + }; let postUrl = `/post/${props.note.id}?voteCount=${votesCount}`; return ( @@ -446,51 +457,78 @@ function Posts(props) {
-
- - - - {commentCount > 0 ? commentCount : ''} - - - - + ))} +
+ +
+
+ + + + {commentCount > 0 ? commentCount : ''} + + +
+ +
+ +
+ +
+ - - - - + +
+ +
+ +
From cd835f298d5dd5b7d0849a658f4d83fc668af694 Mon Sep 17 00:00:00 2001 From: appala venkata avinash Date: Thu, 9 May 2024 18:35:34 +0530 Subject: [PATCH 2/2] Modified Container Design --- src/components/Posts/index.js | 89 ++++++++++++++--------------------- 1 file changed, 35 insertions(+), 54 deletions(-) diff --git a/src/components/Posts/index.js b/src/components/Posts/index.js index bc842ee..98a1b2e 100644 --- a/src/components/Posts/index.js +++ b/src/components/Posts/index.js @@ -95,6 +95,11 @@ export const removeHashtagsAndLinks = text => { return text.replace(/(https?:\/\/[^\s]+)/g, ''); }; +export const removeHashtags = text => { + const withoutHastags = text.replace(/#\w+/g, ''); + return withoutHastags.replace(/(https?:\/\/[^\s]+)/g, ''); +}; + export function extractHashtags(text) { return text.match(/#\w+/g) || []; } @@ -356,34 +361,9 @@ function Posts(props) { } } - function convertHashtagsToLinks(text) { - const hashtagRegex = /#(\w+)(?=\s|#|$)/g; - const tokens = []; - let match; - let lastIndex = 0; - while ((match = hashtagRegex.exec(text)) !== null) { - if (match.index > lastIndex) { - tokens.push(text.slice(lastIndex, match.index)); - } - tokens.push( - - {match[0]} - , - ); - lastIndex = match.index + match[0].length; - } - if (lastIndex < text.length) { - tokens.push(text.slice(lastIndex)); - } - return tokens; - } - let truncatedTitle = truncateTitle(title, 70); let hashtags = extractHashtags(truncatedTitle); - let titleWithLinks = convertHashtagsToLinks(truncatedTitle); + let titleWithLinks = removeHashtags(truncatedTitle); function renderContent(imageLink) { try { @@ -437,39 +417,13 @@ function Posts(props) { <>
- {/* Post Header: Title and Time */} -
-
-

- {titleWithLinks} -

- - {timeDifference.duration} - {timeDifference.unit} - -
-
- {/* Post Media Content */} -
+
{renderContent(imageLink)}
- +
-
- {hashtags.slice(0, 4).map((tag, index) => ( - - ))} -
-
+
+ +
+
+ {hashtags.slice(0, 4).map((tag, index) => ( + + ))} +
+ + + {timeDifference.duration} + {timeDifference.unit} + +
+ +
+

+ {titleWithLinks} +

+