Skip to content

Commit

Permalink
Comment action icons. Also only show on hover
Browse files Browse the repository at this point in the history
  • Loading branch information
mdirolf committed May 8, 2024
1 parent 3a56a6f commit ff34c9a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
29 changes: 29 additions & 0 deletions app/components/Comments.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,32 @@
.publishDate {
font-style: italic;
}

.commentView {
margin-top: 1em;
}

.actionButton {
display: inline-flex;
align-items: center;
}

.actionButton:hover {
text-decoration: underline;
}

.actionButton svg {
margin-right: 0.5em;
}

.actionButtons {
visibility: hidden;
}

.commentView:hover > .actionButtons {
visibility: visible;
}

.commentView:has(.commentView:hover) > .actionButtons {
visibility: hidden;
}
26 changes: 20 additions & 6 deletions app/components/Comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
useEffect,
useState,
} from 'react';
import { FaComment, FaFlag, FaTrash } from 'react-icons/fa';
import { ConstructorPageT } from '../lib/constructorPage';
import {
CommentDeletionT,
Expand Down Expand Up @@ -119,7 +120,7 @@ interface CommentProps {
}
const CommentView = (props: CommentProps) => {
return (
<div className="marginTop1em">
<div className={styles.commentView}>
<div>
<CommentFlair
publishTime={Math.max(
Expand All @@ -143,6 +144,15 @@ const CommentView = (props: CommentProps) => {
);
};

function ActionButton(props: { icon: ReactNode; text: ReactNode }) {
return (
<span className={styles.actionButton}>
{props.icon}
{props.text}
</span>
);
}

const CommentWithReplies = (
props: PartialBy<CommentFormProps, 'user'> & {
comment: CommentOrLocalComment;
Expand Down Expand Up @@ -172,7 +182,7 @@ const CommentWithReplies = (
onClick={() => {
setShowingForm(true);
}}
text={t`Reply`}
text={<ActionButton icon={<FaComment />} text={t`Reply`} />}
/>
);
}
Expand All @@ -182,7 +192,7 @@ const CommentWithReplies = (
onClick={() => {
setShowingDeleteOverlay(true);
}}
text={'Delete'}
text={<ActionButton icon={<FaTrash />} text={t`Delete`} />}
/>
);
}
Expand All @@ -192,7 +202,7 @@ const CommentWithReplies = (
onClick={() => {
setShowingReportOverlay(true);
}}
text={'Report'}
text={<ActionButton icon={<FaFlag />} text={t`Report`} />}
/>
);
}
Expand Down Expand Up @@ -283,10 +293,14 @@ const CommentWithReplies = (
/>
</div>
) : (
<div>
<div className={styles.actionButtons}>
{actionButtons.map((btn, idx) => (
<Fragment key={idx}>
{!!idx && <> &middot; </>}
{!!idx && (
<span className="marginLeft0-5em marginRight0-5em">
&middot;
</span>
)}
{btn}
</Fragment>
))}
Expand Down

0 comments on commit ff34c9a

Please sign in to comment.