mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 22:01:49 +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,
|
comments,
|
||||||
pagination,
|
pagination,
|
||||||
postId,
|
postId,
|
||||||
|
dispatchAction: (_action, data) => this.dispatchAction(_action, data),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
* Use dispatchAction instead
|
||||||
|
*/
|
||||||
onAction: (_action, data) => this.dispatchAction(_action, data)
|
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 = {
|
const Actions = {
|
||||||
// Put your actions here
|
// Put your actions here
|
||||||
addComment,
|
addComment,
|
||||||
|
editComment,
|
||||||
hideComment,
|
hideComment,
|
||||||
deleteComment,
|
deleteComment,
|
||||||
showComment,
|
showComment,
|
||||||
|
@ -1,14 +1,28 @@
|
|||||||
import {formatRelativeTime} from '../utils/helpers';
|
import {formatRelativeTime} from '../utils/helpers';
|
||||||
import React, {useState} from 'react';
|
import React, {useContext, useState} from 'react';
|
||||||
import Avatar from './Avatar';
|
import Avatar from './Avatar';
|
||||||
|
import AppContext from '../AppContext';
|
||||||
|
|
||||||
const EditForm = (props) => {
|
const EditForm = (props) => {
|
||||||
// todo: we need to convert the HTML back to an editable state instead of putting it into the textarea
|
// 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 [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) => {
|
const submitForm = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
|
await dispatchAction('editComment', {
|
||||||
|
id: props.comment.id,
|
||||||
|
html: getHTML()
|
||||||
|
});
|
||||||
|
|
||||||
|
props.toggle();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user