From 02fd64d6dffc9b7e665cc0ead260215b3f05d8bb Mon Sep 17 00:00:00 2001
From: Lukas <lukas.budginas@gmail.com>
Date: Thu, 19 Dec 2024 17:59:32 +0200
Subject: [PATCH] Update comment permlink search result to navigate to comment
 page with selected params when permlink is clicked

---
 .../home/searches/CommentPermlinkResultTable.tsx  | 15 ++++++++++-----
 .../home/searches/CommentPermlinkSearch.tsx       |  2 ++
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/components/home/searches/CommentPermlinkResultTable.tsx b/components/home/searches/CommentPermlinkResultTable.tsx
index a2c8bb9c..47a4dd6f 100644
--- a/components/home/searches/CommentPermlinkResultTable.tsx
+++ b/components/home/searches/CommentPermlinkResultTable.tsx
@@ -14,6 +14,7 @@ import { formatAndDelocalizeTime } from "@/utils/TimeUtils";
 interface CommentPermlinkResultTableProps {
   data: Hive.Permlink[];
   accountName: string | undefined;
+  buildLink: (accountName: string, permlink: string) => {};
 }
 
 const TABLE_CELLS = [
@@ -39,12 +40,15 @@ const buildTableHeader = () => {
 
 const buildTableBody = (
   data: Hive.Permlink[],
-  accountName: string | undefined
+  accountName: string | undefined,
+  buildLink: (accountName: string, permlink: string) => {}
 ) => {
   if (!data || !data.length || !accountName) return;
 
   return data.map(
     ({ block, operation_id, permlink, timestamp, trx_id }: any) => {
+      const linkToCommentsPage = buildLink(accountName, permlink);
+
       return (
         <React.Fragment key={trx_id}>
           <TableRow className="border-b border-gray-700 hover:bg-inherit p-[10px]">
@@ -55,9 +59,7 @@ const buildTableBody = (
               {operation_id}
             </TableCell>
             <TableCell className="text-center text-link">
-              <Link href={`/comments/@${accountName}?&permlink=${permlink}`}>
-                {permlink}
-              </Link>
+              <Link href={linkToCommentsPage}>{permlink}</Link>
             </TableCell>
             <TableCell className="text-left text-text">
               {formatAndDelocalizeTime(timestamp)}
@@ -73,6 +75,7 @@ const buildTableBody = (
 };
 
 const CommentPermlinkResultTable = ({
+  buildLink,
   data,
   accountName,
 }: CommentPermlinkResultTableProps) => {
@@ -84,7 +87,9 @@ const CommentPermlinkResultTable = ({
             <TableHeader>
               <TableRow>{buildTableHeader()}</TableRow>
             </TableHeader>
-            <TableBody>{buildTableBody(data, accountName)}</TableBody>
+            <TableBody>
+              {buildTableBody(data, accountName, buildLink)}
+            </TableBody>
           </Table>
         </div>
       </div>
diff --git a/components/home/searches/CommentPermlinkSearch.tsx b/components/home/searches/CommentPermlinkSearch.tsx
index 60f32df4..8641e156 100644
--- a/components/home/searches/CommentPermlinkSearch.tsx
+++ b/components/home/searches/CommentPermlinkSearch.tsx
@@ -16,6 +16,7 @@ const CommentsPermlinkSearch = () => {
     setPermlinkSearchProps,
     setCommentPaginationPage,
     setCommentType,
+    commentType,
     setLastSearchKey,
     searchRanges,
   } = useSearchesContext();
@@ -48,6 +49,7 @@ const CommentsPermlinkSearch = () => {
         lastTime: searchRanges.lastTimeUnitValue,
         rangeSelectKey: searchRanges.rangeSelectKey,
         timeUnit: searchRanges.timeUnitSelectKey,
+        commentType,
       };
       startCommentPermlinkSearch(
         commentPermlinksSearchProps,
-- 
GitLab