Skip to content
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

Development #430

Merged
merged 14 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/components/comment-edit-form/comment-edit-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const CommentEditForm = ({ commentCid, hideCommentEditForm }: CommentEditFormPro
const defaultPublishOptions: PublishCommentEditOptions = {
commentCid,
content,
edit: { reason: edit?.reason },
reason: edit?.reason ?? '',
spoiler,
subplebbitAddress,
onChallenge: (...args: any) => addChallenge([...args, post]),
Expand Down Expand Up @@ -82,8 +82,8 @@ const CommentEditForm = ({ commentCid, hideCommentEditForm }: CommentEditFormPro
{t('edit_reason')}:{' '}
<input
className={styles.url}
value={publishCommentEditOptions.edit?.reason}
onChange={(e) => setPublishCommentEditOptions((state) => ({ ...state, edit: { reason: e.target.value } }))}
value={publishCommentEditOptions.reason}
onChange={(e) => setPublishCommentEditOptions((state) => ({ ...state, reason: e.target.value }))}
/>
</span>
<span className={styles.optionsButton} onClick={() => setShowFormattingHelp(!showFormattingHelp)}>
Expand Down
2 changes: 2 additions & 0 deletions src/components/markdown/markdown.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
.markdown ol {
padding-left: 40px;
white-space: normal;
padding-bottom: 5px;
}

.markdown ul {
padding-left: 40px;
white-space: normal;
padding-bottom: 5px;
}

.markdown blockquote {
Expand Down
5 changes: 5 additions & 0 deletions src/components/markdown/markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ const Markdown = ({ content }: MarkdownProps) => {
remarkPlugins={remarkPlugins}
rehypePlugins={[[rehypeSanitize]]}
components={{
a: ({ children, href }) => (
<a href={href} target='_blank' rel='noopener noreferrer'>
{children}
</a>
),
img: ({ src }) => <span>{src}</span>,
video: ({ src }) => <span>{src}</span>,
iframe: ({ src }) => <span>{src}</span>,
Expand Down
122 changes: 62 additions & 60 deletions src/components/post/comment-tools/comment-tools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,67 +263,69 @@ const CommentTools = ({
const isInInboxView = isInboxView(useLocation().pathname);

return (
<ul className={`${styles.buttons} ${isReply && !isInInboxView ? styles.buttonsReply : ''} ${hasLabel ? styles.buttonsLabel : ''}`}>
{isReply ? (
isSingleReply ? (
<SingleReplyTools
author={author}
cid={cid}
failed={failed}
hasLabel={hasLabel}
index={index}
isAuthor={isAuthor}
isAccountMod={isAccountMod}
isCommentAuthorMod={isCommentAuthorMod}
parentCid={parentCid}
postCid={postCid}
showCommentEditForm={showCommentEditForm}
showReplyForm={showReplyForm}
subplebbitAddress={subplebbitAddress}
/>
(!(deleted || removed) || ((deleted || removed) && (isAuthor || isAccountMod))) && (
<ul className={`${styles.buttons} ${isReply && !isInInboxView ? styles.buttonsReply : ''} ${hasLabel ? styles.buttonsLabel : ''}`}>
{isReply ? (
isSingleReply ? (
<SingleReplyTools
author={author}
cid={cid}
failed={failed}
hasLabel={hasLabel}
index={index}
isAuthor={isAuthor}
isAccountMod={isAccountMod}
isCommentAuthorMod={isCommentAuthorMod}
parentCid={parentCid}
postCid={postCid}
showCommentEditForm={showCommentEditForm}
showReplyForm={showReplyForm}
subplebbitAddress={subplebbitAddress}
/>
) : (
<ReplyTools
author={author}
cid={cid}
failed={failed}
hasLabel={hasLabel}
index={index}
isAuthor={isAuthor}
isAccountMod={isAccountMod}
isCommentAuthorMod={isCommentAuthorMod}
showCommentEditForm={showCommentEditForm}
showReplyForm={showReplyForm}
subplebbitAddress={subplebbitAddress}
/>
)
) : (
<ReplyTools
author={author}
cid={cid}
failed={failed}
hasLabel={hasLabel}
index={index}
isAuthor={isAuthor}
isAccountMod={isAccountMod}
isCommentAuthorMod={isCommentAuthorMod}
showCommentEditForm={showCommentEditForm}
showReplyForm={showReplyForm}
subplebbitAddress={subplebbitAddress}
/>
)
) : (
<>
<CommentToolsLabel
cid={cid}
deleted={deleted}
failed={failed}
editState={editState}
isReply={isReply}
removed={removed}
spoiler={spoiler}
subplebbitAddress={subplebbitAddress}
/>
<PostTools
author={author}
cid={cid}
failed={failed}
hasLabel={hasLabel}
index={index}
isAuthor={isAuthor}
isAccountMod={isAccountMod}
isCommentAuthorMod={isCommentAuthorMod}
replyCount={replyCount}
showCommentEditForm={showCommentEditForm}
subplebbitAddress={subplebbitAddress}
/>
</>
)}
</ul>
<>
<CommentToolsLabel
cid={cid}
deleted={deleted}
failed={failed}
editState={editState}
isReply={isReply}
removed={removed}
spoiler={spoiler}
subplebbitAddress={subplebbitAddress}
/>
<PostTools
author={author}
cid={cid}
failed={failed}
hasLabel={hasLabel}
index={index}
isAuthor={isAuthor}
isAccountMod={isAccountMod}
isCommentAuthorMod={isCommentAuthorMod}
replyCount={replyCount}
showCommentEditForm={showCommentEditForm}
subplebbitAddress={subplebbitAddress}
/>
</>
)}
</ul>
)
);
};

Expand Down
48 changes: 28 additions & 20 deletions src/components/post/post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,33 @@ interface PostProps {
post: Comment | undefined;
}

const ThumbnailLoader = ({ post }: PostProps) => {
const { cid } = post || {};
// Reset state by remounting component when post changes
return useThumbnailContent(cid, post);
};

const useThumbnailContent = (key: string, post: any) => {
const [commentMediaInfo, setCommentMediaInfo] = useState<CommentMediaInfo | undefined>();

useEffect(() => {
const loadThumbnail = async () => {
const initialInfo = getCommentMediaInfo(post);
// some sites have CORS access, so the thumbnail can be fetched client-side, which is helpful if subplebbit.settings.fetchThumbnailUrls is false
if (initialInfo?.type === 'webpage' && !initialInfo.thumbnail) {
const newMediaInfo = await fetchWebpageThumbnailIfNeeded(initialInfo);
setCommentMediaInfo(newMediaInfo);
} else {
setCommentMediaInfo(initialInfo);
}
};

loadThumbnail();
}, [post]);

return commentMediaInfo;
};

const Post = ({ index, post = {} }: PostProps) => {
// handle single comment thread
const op = useComment({ commentCid: post?.parentCid ? post?.postCid : '' });
Expand Down Expand Up @@ -120,26 +147,7 @@ const Post = ({ index, post = {} }: PostProps) => {
const isInProfileHiddenView = isProfileHiddenView(location.pathname);
const isInSubplebbitView = isSubplebbitView(location.pathname, params);

// some sites have CORS access, so the thumbnail can be fetched client-side, which is helpful if subplebbit.settings.fetchThumbnailUrls is false
const [commentMediaInfo, setCommentMediaInfo] = useState<CommentMediaInfo | undefined>();

useEffect(() => {
const loadThumbnail = async () => {
const initialInfo = getCommentMediaInfo(post);

if (initialInfo?.type === 'webpage' && !initialInfo.thumbnail) {
const newMediaInfo = await fetchWebpageThumbnailIfNeeded(initialInfo);
setCommentMediaInfo(newMediaInfo);
} else {
setCommentMediaInfo(initialInfo);
}
};

loadThumbnail();
return () => {
setCommentMediaInfo(undefined);
};
}, [post]);
const commentMediaInfo = ThumbnailLoader({ post });

const [isExpanded, setIsExpanded] = useState(isInPostView);
const toggleExpanded = () => setIsExpanded(!isExpanded);
Expand Down
29 changes: 17 additions & 12 deletions src/components/post/thumbnail/thumbnail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ interface ThumbnailProps {
const Thumbnail = ({ cid, commentMediaInfo, expanded = false, isReply = false, link, linkHeight, linkWidth, subplebbitAddress, toggleExpanded }: ThumbnailProps) => {
const iframeThumbnail = commentMediaInfo?.patternThumbnailUrl || commentMediaInfo?.thumbnail;
let displayWidth, displayHeight, hasLinkDimensions;
const routeOrLink = isReply || commentMediaInfo?.type === 'webpage' ? link : `/p/${subplebbitAddress}/c/${cid}`;
const thumbnailClass = expanded ? styles.thumbnailHidden : styles.thumbnailVisible;

if (linkWidth && linkHeight) {
Expand Down Expand Up @@ -52,17 +51,23 @@ const Thumbnail = ({ cid, commentMediaInfo, expanded = false, isReply = false, l
return (
<span className={`${styles.thumbnail} ${thumbnailClass}`} style={style}>
<span className={hasLinkDimensions ? styles.transparentThumbnailWrapper : styles.thumbnailWrapper}>
<Link
to={routeOrLink}
onClick={(e) => {
if (e.button === 0 && isReply) {
e.preventDefault();
toggleExpanded && toggleExpanded();
}
}}
>
{mediaComponent}
</Link>
{isReply || commentMediaInfo?.type === 'webpage' ? (
<a
href={link}
target='_blank'
rel='noopener noreferrer'
onClick={(e) => {
if (e.button === 0 && isReply) {
e.preventDefault();
toggleExpanded && toggleExpanded();
}
}}
>
{mediaComponent}
</a>
) : (
<Link to={`/p/${subplebbitAddress}/c/${cid}`}>{mediaComponent}</Link>
)}
</span>
</span>
);
Expand Down
19 changes: 19 additions & 0 deletions src/components/reply/reply.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@
line-height: 20px;
}

.removedOrDeletedContent {
margin-bottom: 0 !important;
margin-top: 0 !important;
}

.md p {
margin-bottom: 5px;
}
Expand Down Expand Up @@ -165,6 +170,18 @@

.removedContent, .deletedContent {
text-transform: lowercase;
background-color: var(--removed-reply-backgrouhd-color);
display: inline-block;
padding: 5px;
}

.removedUsername {
color: var(--text-info);
text-transform: lowercase;
}

.hiddenMidcol {
visibility: hidden !important;
}

.usertext a {
Expand All @@ -189,11 +206,13 @@
}

.collapsedEntry .author,
.collapsedEntry .removedUsername,
.collapsedEntry .moderator,
.collapsedEntry .admin,
.collapsedEntry .owner,
.collapsedEntry .moderatorBrackets,
.collapsedEntry .time,
.collapsedEntry .score,
.collapsedEntry .children {
color: var(--text-info) !important;
font-style: italic !important;
Expand Down
Loading