improved comment linking
This commit is contained in:
		
							parent
							
								
									2ceada66d6
								
							
						
					
					
						commit
						d14123cc42
					
				| @ -23,6 +23,7 @@ import { useMe } from './me' | |||||||
| import { useQuoteReply } from './use-quote-reply' | import { useQuoteReply } from './use-quote-reply' | ||||||
| import { DownZap } from './dont-link-this' | import { DownZap } from './dont-link-this' | ||||||
| import Skull from '../svgs/death-skull.svg' | import Skull from '../svgs/death-skull.svg' | ||||||
|  | import { commentSubTreeRootId } from '../lib/item' | ||||||
| 
 | 
 | ||||||
| function Parent ({ item, rootText }) { | function Parent ({ item, rootText }) { | ||||||
|   const root = useRoot() |   const root = useRoot() | ||||||
| @ -59,17 +60,11 @@ const truncateString = (string = '', maxLength = 140) => | |||||||
| export function CommentFlat ({ item, rank, siblingComments, ...props }) { | export function CommentFlat ({ item, rank, siblingComments, ...props }) { | ||||||
|   const router = useRouter() |   const router = useRouter() | ||||||
|   const [href, as] = useMemo(() => { |   const [href, as] = useMemo(() => { | ||||||
|     if (item.path.split('.').length > COMMENT_DEPTH_LIMIT + 1) { |     const rootId = commentSubTreeRootId(item) | ||||||
|     return [{ |     return [{ | ||||||
|       pathname: '/items/[id]', |       pathname: '/items/[id]', | ||||||
|         query: { id: item.parentId, commentId: item.id } |       query: { id: rootId, commentId: item.id } | ||||||
|       }, `/items/${item.parentId}`] |     }, `/items/${rootId}`] | ||||||
|     } else { |  | ||||||
|       return [{ |  | ||||||
|         pathname: '/items/[id]', |  | ||||||
|         query: { id: item.root.id, commentId: item.id } |  | ||||||
|       }, `/items/${item.root.id}`] |  | ||||||
|     } |  | ||||||
|   }, [item?.id]) |   }, [item?.id]) | ||||||
| 
 | 
 | ||||||
|   return ( |   return ( | ||||||
|  | |||||||
| @ -11,7 +11,7 @@ import { dayMonthYear, timeSince } from '../lib/time' | |||||||
| import Link from 'next/link' | import Link from 'next/link' | ||||||
| import Check from '../svgs/check-double-line.svg' | import Check from '../svgs/check-double-line.svg' | ||||||
| import HandCoin from '../svgs/hand-coin-fill.svg' | import HandCoin from '../svgs/hand-coin-fill.svg' | ||||||
| import { COMMENT_DEPTH_LIMIT, LOST_BLURBS, FOUND_BLURBS } from '../lib/constants' | import { LOST_BLURBS, FOUND_BLURBS } from '../lib/constants' | ||||||
| import CowboyHatIcon from '../svgs/cowboy.svg' | import CowboyHatIcon from '../svgs/cowboy.svg' | ||||||
| import BaldIcon from '../svgs/bald.svg' | import BaldIcon from '../svgs/bald.svg' | ||||||
| import { RootProvider } from './root' | import { RootProvider } from './root' | ||||||
| @ -28,6 +28,7 @@ import { numWithUnits } from '../lib/format' | |||||||
| import BountyIcon from '../svgs/bounty-bag.svg' | import BountyIcon from '../svgs/bounty-bag.svg' | ||||||
| import { LongCountdown } from './countdown' | import { LongCountdown } from './countdown' | ||||||
| import { nextBillingWithGrace } from '../lib/territory' | import { nextBillingWithGrace } from '../lib/territory' | ||||||
|  | import { commentSubTreeRootId } from '../lib/item' | ||||||
| 
 | 
 | ||||||
| function Notification ({ n, fresh }) { | function Notification ({ n, fresh }) { | ||||||
|   const type = n.__typename |   const type = n.__typename | ||||||
| @ -98,9 +99,7 @@ const defaultOnClick = n => { | |||||||
| 
 | 
 | ||||||
|   // Votification, Mention, JobChanged, Reply all have item
 |   // Votification, Mention, JobChanged, Reply all have item
 | ||||||
|   if (!n.item.title) { |   if (!n.item.title) { | ||||||
|     const path = n.item.path.split('.') |     const rootId = commentSubTreeRootId(n.item) | ||||||
|     if (path.length > COMMENT_DEPTH_LIMIT + 1) { |  | ||||||
|       const rootId = path.slice(-(COMMENT_DEPTH_LIMIT + 1))[0] |  | ||||||
|     return { |     return { | ||||||
|       href: { |       href: { | ||||||
|         pathname: '/items/[id]', |         pathname: '/items/[id]', | ||||||
| @ -108,15 +107,6 @@ const defaultOnClick = n => { | |||||||
|       }, |       }, | ||||||
|       as: `/items/${rootId}` |       as: `/items/${rootId}` | ||||||
|     } |     } | ||||||
|     } else { |  | ||||||
|       return { |  | ||||||
|         href: { |  | ||||||
|           pathname: '/items/[id]', |  | ||||||
|           query: { id: n.item.root.id, commentId: n.item.id } |  | ||||||
|         }, |  | ||||||
|         as: `/items/${n.item.root.id}` |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|   } else { |   } else { | ||||||
|     return { |     return { | ||||||
|       href: { |       href: { | ||||||
|  | |||||||
| @ -8,17 +8,16 @@ import Link from 'next/link' | |||||||
| import { FeeButtonProvider, postCommentBaseLineItems, postCommentUseRemoteLineItems } from './fee-button' | import { FeeButtonProvider, postCommentBaseLineItems, postCommentUseRemoteLineItems } from './fee-button' | ||||||
| import { commentsViewedAfterComment } from '../lib/new-comments' | import { commentsViewedAfterComment } from '../lib/new-comments' | ||||||
| import { commentSchema } from '../lib/validate' | import { commentSchema } from '../lib/validate' | ||||||
| import { COMMENT_DEPTH_LIMIT } from '../lib/constants' |  | ||||||
| import { useToast } from './toast' | import { useToast } from './toast' | ||||||
| import { toastDeleteScheduled } from '../lib/form' | import { toastDeleteScheduled } from '../lib/form' | ||||||
| import { ItemButtonBar } from './post' | import { ItemButtonBar } from './post' | ||||||
| import { useShowModal } from './modal' | import { useShowModal } from './modal' | ||||||
| import { Button } from 'react-bootstrap' | import { Button } from 'react-bootstrap' | ||||||
| import { useRoot } from './root' | import { useRoot } from './root' | ||||||
|  | import { commentSubTreeRootId } from '../lib/item' | ||||||
| 
 | 
 | ||||||
| export function ReplyOnAnotherPage ({ item }) { | export function ReplyOnAnotherPage ({ item }) { | ||||||
|   const path = item.path.split('.') |   const rootId = commentSubTreeRootId(item) | ||||||
|   const rootId = path.slice(-(COMMENT_DEPTH_LIMIT - 1))[0] |  | ||||||
| 
 | 
 | ||||||
|   let text = 'reply on another page' |   let text = 'reply on another page' | ||||||
|   if (item.ncomments > 0) { |   if (item.ncomments > 0) { | ||||||
|  | |||||||
| @ -7,6 +7,8 @@ import { useMe } from './me' | |||||||
| import { useToast } from './toast' | import { useToast } from './toast' | ||||||
| import { SSR } from '../lib/constants' | import { SSR } from '../lib/constants' | ||||||
| import { callWithTimeout } from '../lib/nostr' | import { callWithTimeout } from '../lib/nostr' | ||||||
|  | import { commentSubTreeRootId } from '../lib/item' | ||||||
|  | import { useRouter } from 'next/router' | ||||||
| 
 | 
 | ||||||
| const referrurl = (ipath, me) => { | const referrurl = (ipath, me) => { | ||||||
|   const path = `${ipath}${me ? `/r/${me.name}` : ''}` |   const path = `${ipath}${me ? `/r/${me.name}` : ''}` | ||||||
| @ -67,7 +69,16 @@ export default function Share ({ path, title, className = '' }) { | |||||||
| export function CopyLinkDropdownItem ({ item }) { | export function CopyLinkDropdownItem ({ item }) { | ||||||
|   const me = useMe() |   const me = useMe() | ||||||
|   const toaster = useToast() |   const toaster = useToast() | ||||||
|   const url = referrurl(`/items/${item.id}`, me) |   const router = useRouter() | ||||||
|  |   let url = referrurl(`/items/${item.id}`, me) | ||||||
|  | 
 | ||||||
|  |   // if this is a comment and we're not directly on the comment page
 | ||||||
|  |   // link to the comment in context
 | ||||||
|  |   if (item.parentId && !router.asPath.includes(`/items/${item.id}`)) { | ||||||
|  |     const rootId = commentSubTreeRootId(item) | ||||||
|  |     url = referrurl(`/items/${rootId}`, me) + `?commentId=${item.id}` | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   return ( |   return ( | ||||||
|     <Dropdown.Item |     <Dropdown.Item | ||||||
|       onClick={async () => { |       onClick={async () => { | ||||||
|  | |||||||
| @ -1,4 +1,4 @@ | |||||||
| import { OLD_ITEM_DAYS } from './constants' | import { COMMENT_DEPTH_LIMIT, OLD_ITEM_DAYS } from './constants' | ||||||
| import { datePivot } from './time' | import { datePivot } from './time' | ||||||
| 
 | 
 | ||||||
| export const defaultCommentSort = (pinned, bio, createdAt) => { | export const defaultCommentSort = (pinned, bio, createdAt) => { | ||||||
| @ -52,3 +52,8 @@ export const deleteItemByAuthor = async ({ models, id, item }) => { | |||||||
| 
 | 
 | ||||||
|   return await models.item.update({ where: { id: Number(id) }, data: updateData }) |   return await models.item.update({ where: { id: Number(id) }, data: updateData }) | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | export const commentSubTreeRootId = (item) => { | ||||||
|  |   const path = item.path.split('.') | ||||||
|  |   return path.slice(-(COMMENT_DEPTH_LIMIT - 1))[0] | ||||||
|  | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user