-
Notifications
You must be signed in to change notification settings - Fork 0
feat(tweets): 推文发布框与正文支持表情选择与内联渲染 #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,20 +2,24 @@ | |
| * TweetContent - 推文正文组件 | ||
| * | ||
| * 将正文中的 #话题# 解析为跳转到 /tweets/topics/$tag 的 Clickable Link, | ||
| * 阻止冒泡避免触发整卡点击进入详情页。 | ||
| * 将正文中的 [name] 占位符解析为内联表情图片,阻止冒泡避免触发整卡点击进入详情页。 | ||
| */ | ||
|
|
||
| import type { TweetEmoteRef } from "@entities/tweet/model/types"; | ||
| import { EmojiText } from "@shared/ui/emoji-text"; | ||
| import { Link } from "@tanstack/react-router"; | ||
| import type React from "react"; | ||
|
|
||
| const HASHTAG_REGEX = /#([^#\r\n]{1,50})#/g; | ||
|
|
||
| export interface TweetContentProps { | ||
| /** 推文正文 */ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [轻微] TweetContentProps 中 content: string 字段上的 /** 推文正文 */ 仅是字段名语义复述(父组件名 TweetContent 已暗示这是正文内容),不携带任何额外约束或来源说明。
|
||
| content: string; | ||
| /** 表情映射表,key 为 [name],value 为表情图片 URL */ | ||
| emote?: Record<string, TweetEmoteRef>; | ||
| className?: string; | ||
| } | ||
|
|
||
| export function TweetContent({ content, className }: TweetContentProps) { | ||
| export function TweetContent({ content, emote, className }: TweetContentProps) { | ||
| if (!content) return null; | ||
|
|
||
| const elements: React.ReactNode[] = []; | ||
|
|
@@ -33,12 +37,11 @@ export function TweetContent({ content, className }: TweetContentProps) { | |
| const fullMatch = match[0]; | ||
| const tagName = match[1]; | ||
|
|
||
| // 匹配前的普通文本 | ||
| // 匹配前的普通文本(支持表情) | ||
| if (matchStart > lastIndex) { | ||
| elements.push(content.slice(lastIndex, matchStart)); | ||
| const textChunk = content.slice(lastIndex, matchStart); | ||
| elements.push(<EmojiText key={`text-${lastIndex}`} text={textChunk} emote={emote} />); | ||
| } | ||
|
|
||
| // 话题标签 Link | ||
| elements.push( | ||
| <Link | ||
| key={`${matchStart}-${tagName}`} | ||
|
|
@@ -54,11 +57,11 @@ export function TweetContent({ content, className }: TweetContentProps) { | |
| lastIndex = matchEnd; | ||
| } | ||
|
|
||
| // 剩余文本 | ||
| // 剩余文本(支持表情) | ||
| if (lastIndex < content.length) { | ||
| elements.push(content.slice(lastIndex)); | ||
| const textChunk = content.slice(lastIndex); | ||
| elements.push(<EmojiText key={`text-${lastIndex}`} text={textChunk} emote={emote} />); | ||
| } | ||
|
|
||
| return ( | ||
| <p | ||
| className={`whitespace-pre-wrap wrap-break-word text-sm leading-relaxed text-foreground ${className ?? ""}`} | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[轻微] 导出类型别名 TweetEmoteRef 上方的 JSDoc "TweetEmoteRef - 推文表情映射值别名" 仅是类型名语义复述,未补充代码自表达之外的信息(如 key 格式、与 TweetCommentEmoteRef 的关系、来源字段等)。