Merge pull request #104 from alexelev/refactor/APIDefinition

Refactor API definition (fixed #94)
This commit is contained in:
Igor Adamenko
2018-06-23 23:36:38 +03:00
committed by GitHub
6 changed files with 36 additions and 36 deletions
+22 -22
View File
@@ -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,
+7 -7
View File
@@ -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));
});
+2 -2
View File
@@ -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 => {
+3 -3
View File
@@ -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 });
+1 -1
View File
@@ -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));
});
+1 -1
View File
@@ -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(<ListComments comments={comments}/>, node);