mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 13:22:39 +03:00
Wired up editing comments
This commit is contained in:
parent
125afc5e23
commit
0f6e4a86d0
@ -276,6 +276,12 @@ export default class App extends React.Component {
|
||||
comments,
|
||||
pagination,
|
||||
postId,
|
||||
dispatchAction: (_action, data) => this.dispatchAction(_action, data),
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Use dispatchAction instead
|
||||
*/
|
||||
onAction: (_action, data) => this.dispatchAction(_action, data)
|
||||
};
|
||||
}
|
||||
|
@ -115,9 +115,27 @@ async function deleteComment({state, api, data: comment}) {
|
||||
};
|
||||
}
|
||||
|
||||
async function editComment({state, api, data: comment}) {
|
||||
const data = await api.comments.edit({
|
||||
comment
|
||||
});
|
||||
comment = data.comments[0];
|
||||
|
||||
// Replace the comment in the state with the new one
|
||||
return {
|
||||
comments: state.comments.map((c) => {
|
||||
if (c.id === comment.id) {
|
||||
return comment;
|
||||
}
|
||||
return c;
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
const Actions = {
|
||||
// Put your actions here
|
||||
addComment,
|
||||
editComment,
|
||||
hideComment,
|
||||
deleteComment,
|
||||
showComment,
|
||||
|
@ -1,13 +1,27 @@
|
||||
import {formatRelativeTime} from '../utils/helpers';
|
||||
import React, {useState} from 'react';
|
||||
import React, {useContext, useState} from 'react';
|
||||
import Avatar from './Avatar';
|
||||
import AppContext from '../AppContext';
|
||||
|
||||
const EditForm = (props) => {
|
||||
// todo: we need to convert the HTML back to an editable state instead of putting it into the textarea
|
||||
const [message, setMessage] = useState(props.comment.html);
|
||||
const {dispatchAction} = useContext(AppContext);
|
||||
|
||||
const getHTML = () => {
|
||||
// Convert newlines to <br> for now (until we add a real editor)
|
||||
return message.replace('\n', '<br>');
|
||||
};
|
||||
|
||||
const submitForm = async (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
await dispatchAction('editComment', {
|
||||
id: props.comment.id,
|
||||
html: getHTML()
|
||||
});
|
||||
|
||||
props.toggle();
|
||||
|
||||
return false;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user