diff --git a/web/app/common/api.js b/web/app/common/api.js index 566db403..a067fc1c 100644 --- a/web/app/common/api.js +++ b/web/app/common/api.js @@ -11,11 +11,11 @@ export const logOut = () => fetcher.get({ url: `/auth/logout`, overriddenApiBase export const getConfig = () => fetcher.get(`/config`); // TODO: looks like we can get url from settings here and below -export const find = ({ sort, url }) => fetcher.get(`/find?url=${url}&sort=${sort}&format=tree`); +export const getPostComments = ({ sort, url }) => fetcher.get(`/find?url=${url}&sort=${sort}&format=tree`); -export const last = ({ siteId, max }) => fetcher.get(`/last/${max}?site=${siteId}`); +export const getLastComments = ({ siteId, max }) => fetcher.get(`/last/${max}?site=${siteId}`); -export const counts = ({ urls, siteId }) => fetcher.post({ +export const getCommentsCount = ({ urls, siteId }) => fetcher.post({ url: `/counts?site=${siteId}`, body: urls, }); @@ -24,12 +24,12 @@ export const getComment = ({ id }) => fetcher.get(`/id/${id}?url=${url}`); export const getUserComments = ({ user, limit }) => fetcher.get(`/comments?user=${user}&limit=${limit}`); -export const vote = ({ id, url, value }) => fetcher.put({ +export const putCommentVote = ({ id, url, value }) => fetcher.put({ url: `/vote/${id}?url=${url}&vote=${value}`, withCredentials: true, }); -export const send = ({ text, pid }) => fetcher.post({ +export const addComment = ({ text, pid }) => fetcher.post({ url: '/comment', body: { text, @@ -42,7 +42,7 @@ export const send = ({ text, pid }) => fetcher.post({ withCredentials: true, }); -export const edit = ({ text, id }) => fetcher.put({ +export const updateComment = ({ text, id }) => fetcher.put({ url: `/comment/${id}?url=${url}`, body: { text, @@ -64,27 +64,27 @@ export const getUser = () => fetcher.get({ }); /* admin */ -export const pin = ({ id, url }) => fetcher.put({ +export const pinComment = ({ id, url }) => fetcher.put({ url: `/admin/pin/${id}?url=${url}&pin=1`, withCredentials: true, }); -export const unpin = ({ id, url }) => fetcher.put({ +export const unpinComment = ({ id, url }) => fetcher.put({ url: `/admin/pin/${id}?url=${url}&pin=0`, withCredentials: true, }); -export const verify = ({ id }) => fetcher.put({ +export const setVerifyStatus = ({ id }) => fetcher.put({ url: `/admin/verify/${id}?verified=1`, withCredentials: true, }); -export const unverify = ({ id }) => fetcher.put({ +export const removeVerifyStatus = ({ id }) => fetcher.put({ url: `/admin/verify/${id}?verified=0`, withCredentials: true, }); -export const remove = ({ id }) => fetcher.delete({ +export const removeComment = ({ id }) => fetcher.delete({ url: `/admin/comment/${id}?url=${url}`, withCredentials: true, }); @@ -107,22 +107,22 @@ export const getBlocked = () => fetcher.get({ export default { logOut, getConfig, - find, - last, - counts, + getPostComments, + getLastComments, + getCommentsCount, getComment, getUserComments, - vote, - send, - edit, + putCommentVote, + addComment, + updateComment, getUser, getPreview, - pin, - unpin, - verify, - unverify, - remove, + pinComment, + unpinComment, + setVerifyStatus, + removeVerifyStatus, + removeComment, blockUser, unblockUser, getBlocked, diff --git a/web/app/components/comment/comment.jsx b/web/app/components/comment/comment.jsx index 02870a14..39d8ede2 100644 --- a/web/app/components/comment/comment.jsx +++ b/web/app/components/comment/comment.jsx @@ -137,7 +137,7 @@ export default class Comment extends Component { if (confirm('Do you want to pin this comment?')) { this.setState({ pinned: true }); - api.pin({ id, url }).then(() => { + api.pinComment({ id, url }).then(() => { api.getComment({ id }).then(comment => store.replaceComment(comment)); }); } @@ -149,7 +149,7 @@ export default class Comment extends Component { if (confirm('Do you want to unpin this comment?')) { this.setState({ pinned: false }); - api.unpin({ id, url }).then(() => { + api.unpinComment({ id, url }).then(() => { api.getComment({ id }).then(comment => store.replaceComment(comment)); }); } @@ -161,7 +161,7 @@ export default class Comment extends Component { if (confirm('Do you want to verify this user?')) { this.setState({ isUserVerified: true }); - api.verify({ id: userId }).then(() => { + api.setVerifyStatus({ id: userId }).then(() => { api.getComment({ id }).then(comment => store.replaceComment(comment)); }); } @@ -173,7 +173,7 @@ export default class Comment extends Component { if (confirm('Do you want to unverify this user?')) { this.setState({ isUserVerified: false }); - api.unverify({ id: userId }).then(() => { + api.removeVerifyStatus({ id: userId }).then(() => { api.getComment({ id }).then(comment => store.replaceComment(comment)); }); } @@ -213,7 +213,7 @@ export default class Comment extends Component { isReplying: false, }); - api.remove({ id }).then(() => { + api.removeComment({ id }).then(() => { api.getComment({ id }).then(comment => store.replaceComment(comment)); }); } @@ -233,7 +233,7 @@ export default class Comment extends Component { this.votingPromise = this.votingPromise .then(() => { - return api.vote({ id, url, value: 1 }) + return api.putCommentVote({ id, url, value: 1 }) .then(() => { api.getComment({ id }).then(comment => store.replaceComment(comment)); }); @@ -254,7 +254,7 @@ export default class Comment extends Component { this.votingPromise = this.votingPromise .then(() => { - return api.vote({ id, url, value: -1 }) + return api.putCommentVote({ id, url, value: -1 }) .then(() => { api.getComment({ id }).then(comment => store.replaceComment(comment)); }); diff --git a/web/app/components/input/input.jsx b/web/app/components/input/input.jsx index 6b080c28..7486ebaf 100644 --- a/web/app/components/input/input.jsx +++ b/web/app/components/input/input.jsx @@ -93,8 +93,8 @@ export default class Input extends Component { this.setState({ isDisabled: true, isErrorShown: false }); const request = mods.mode === 'edit' - ? api.edit({ text, id }) - : api.send({ text, ...(pid ? { pid } : {}) }); + ? api.updateComment({ text, id }) + : api.addComment({ text, ...(pid ? { pid } : {}) }); request .then(comment => { diff --git a/web/app/components/root/root.jsx b/web/app/components/root/root.jsx index 4ac23048..2428b663 100644 --- a/web/app/components/root/root.jsx +++ b/web/app/components/root/root.jsx @@ -62,7 +62,7 @@ export default class Root extends Component { api.getUser() .then(data => store.set('user', data)) .catch(() => store.set('user', {})), - api.find({ sort, url }) + api.getPostComments({ sort, url }) .then(({ comments = [] } = {}) => store.set('comments', comments)) .catch(() => store.set('comments', [])), ]).finally(() => { @@ -133,7 +133,7 @@ export default class Root extends Component { // if someone was unblocked let's reload comments if (wasSomeoneUnblocked) { - api.find({ sort, url }).then(({ comments } = {}) => store.set('comments', comments)); + api.getPostComments({ sort, url }).then(({ comments } = {}) => store.set('comments', comments)); } this.setState({ @@ -153,7 +153,7 @@ export default class Root extends Component { // can't save; ignore it } - api.find({ sort, url }) + api.getPostComments({ sort, url }) .then(({ comments } = {}) => store.set('comments', comments)) .finally(() => { this.setState({ isCommentsListLoading: false }); diff --git a/web/app/counter.js b/web/app/counter.js index 2c850233..3d0dd7df 100644 --- a/web/app/counter.js +++ b/web/app/counter.js @@ -33,7 +33,7 @@ function init() { return acc; }, {}); - api.counts({ urls: Object.keys(map), siteId: remark_config.site_id }) + api.getCommentsCount({ urls: Object.keys(map), siteId: remark_config.site_id }) .then(res => { res.forEach(item => (map[item.url].innerHTML = item.count)); }); diff --git a/web/app/last-comments.js b/web/app/last-comments.js index c83c6e8a..ddf31a89 100644 --- a/web/app/last-comments.js +++ b/web/app/last-comments.js @@ -39,7 +39,7 @@ function init() { [].slice.call(nodes).forEach(node => { const max = node.dataset.max || remark_config.max_last_comments || DEFAULT_LAST_COMMENTS_MAX; - api.last({ max, siteId: remark_config.site_id }) + api.getLastComments({ max, siteId: remark_config.site_id }) .then(comments => { try { render(, node);