mirror of
https://github.com/mediacms-io/mediacms.git
synced 2026-05-05 20:23:26 -04:00
comments
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
|||||||
VERSION = "8.1.3"
|
VERSION = "8.1.4"
|
||||||
|
|||||||
@@ -392,7 +392,7 @@ function displayCommentsRelatedAlert() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const CommentsListHeader = ({ commentsLength }) => {
|
const CommentsListHeader = ({ commentsLength, ordering, onToggleOrdering }) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{!MemberContext._currentValue.can.readComment || MediaPageStore.get('media-data').enable_comments ? null : (
|
{!MemberContext._currentValue.can.readComment || MediaPageStore.get('media-data').enable_comments ? null : (
|
||||||
@@ -409,12 +409,30 @@ const CommentsListHeader = ({ commentsLength }) => {
|
|||||||
: MediaPageStore.get('media-data').enable_comments
|
: MediaPageStore.get('media-data').enable_comments
|
||||||
? translateString('No') + ' ' + commentsText.single + ' ' + translateString('yet')
|
? translateString('No') + ' ' + commentsText.single + ' ' + translateString('yet')
|
||||||
: ''}
|
: ''}
|
||||||
|
{commentsLength > 0 && (
|
||||||
|
<button className="comments-order-toggle" onClick={onToggleOrdering}>
|
||||||
|
<span className="material-icons">swap_vert</span>
|
||||||
|
<span className="comments-order-label">
|
||||||
|
{ordering === 'newest' ? translateString('Newest first') : translateString('Oldest first')}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
</h2>
|
</h2>
|
||||||
) : null}
|
) : null}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getSortedComments(comments, ordering) {
|
||||||
|
const sorted = [...comments];
|
||||||
|
sorted.sort((a, b) => {
|
||||||
|
const da = new Date(a.add_date);
|
||||||
|
const db = new Date(b.add_date);
|
||||||
|
return ordering === 'newest' ? db - da : da - db;
|
||||||
|
});
|
||||||
|
return sorted;
|
||||||
|
}
|
||||||
|
|
||||||
export default function CommentsList(props) {
|
export default function CommentsList(props) {
|
||||||
const [mediaId, setMediaId] = useState(MediaPageStore.get('media-id'));
|
const [mediaId, setMediaId] = useState(MediaPageStore.get('media-id'));
|
||||||
|
|
||||||
@@ -424,6 +442,12 @@ export default function CommentsList(props) {
|
|||||||
|
|
||||||
const [displayComments, setDisplayComments] = useState(false);
|
const [displayComments, setDisplayComments] = useState(false);
|
||||||
|
|
||||||
|
const [ordering, setOrdering] = useState('newest');
|
||||||
|
|
||||||
|
function toggleOrdering() {
|
||||||
|
setOrdering((o) => (o === 'newest' ? 'oldest' : 'newest'));
|
||||||
|
}
|
||||||
|
|
||||||
function onCommentsLoad() {
|
function onCommentsLoad() {
|
||||||
const retrievedComments = [...MediaPageStore.get('media-comments')];
|
const retrievedComments = [...MediaPageStore.get('media-comments')];
|
||||||
|
|
||||||
@@ -512,12 +536,12 @@ export default function CommentsList(props) {
|
|||||||
return (
|
return (
|
||||||
<div className="comments-list">
|
<div className="comments-list">
|
||||||
<div className="comments-list-inner">
|
<div className="comments-list-inner">
|
||||||
<CommentsListHeader commentsLength={comments.length} />
|
<CommentsListHeader commentsLength={comments.length} ordering={ordering} onToggleOrdering={toggleOrdering} />
|
||||||
|
|
||||||
{MediaPageStore.get('media-data').enable_comments ? <CommentForm media_id={mediaId} /> : null}
|
{MediaPageStore.get('media-data').enable_comments ? <CommentForm media_id={mediaId} /> : null}
|
||||||
|
|
||||||
{displayComments
|
{displayComments
|
||||||
? comments.map((c) => {
|
? getSortedComments(comments, ordering).map((c) => {
|
||||||
return (
|
return (
|
||||||
<Comment
|
<Comment
|
||||||
key={c.uid}
|
key={c.uid}
|
||||||
|
|||||||
@@ -277,6 +277,39 @@
|
|||||||
margin: 0 2rem 1.5rem 0;
|
margin: 0 2rem 1.5rem 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.comments-order-toggle {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
vertical-align: middle;
|
||||||
|
gap: 2px;
|
||||||
|
background: none;
|
||||||
|
border: 0;
|
||||||
|
padding: 2px 8px;
|
||||||
|
margin-left: 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
opacity: 0.6;
|
||||||
|
border-radius: 4px;
|
||||||
|
transition: opacity 0.15s, background-color 0.15s;
|
||||||
|
|
||||||
|
&:hover,
|
||||||
|
&:focus {
|
||||||
|
opacity: 1;
|
||||||
|
background-color: rgba(128, 128, 128, 0.12);
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.material-icons {
|
||||||
|
font-size: 18px;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comments-order-label {
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 400;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.disabled-comments-msg {
|
.disabled-comments-msg {
|
||||||
display: block;
|
display: block;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|||||||
@@ -887,7 +887,7 @@ class MediaPageStore extends EventEmitter {
|
|||||||
|
|
||||||
submitCommentResponse(response) {
|
submitCommentResponse(response) {
|
||||||
if (response && 201 === response.status && response.data && Object.keys(response.data)) {
|
if (response && 201 === response.status && response.data && Object.keys(response.data)) {
|
||||||
MediaPageStoreData[this.id].comments.push(response.data);
|
MediaPageStoreData[this.id].comments.unshift(response.data);
|
||||||
this.emit('comment_submit', response.data.uid);
|
this.emit('comment_submit', response.data.uid);
|
||||||
}
|
}
|
||||||
setTimeout(
|
setTimeout(
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user