Skip to content
This repository has been archived by the owner on Nov 15, 2018. It is now read-only.

Commit

Permalink
fix: 问答话题不能收藏的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
mutoe committed Jul 6, 2018
1 parent 82451a0 commit 2f607ea
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 38 deletions.
38 changes: 16 additions & 22 deletions src/api/question/topics.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import request from "../../http";
import api from "../api.js";

/**
* The topics API query function.
Expand All @@ -12,7 +12,7 @@ import request from "../../http";
* @returns
*/
export function query(params = {}) {
return request.get("/question-topics", {
return api.get("/question-topics", {
params,
validateStatus: status => status === 200
});
Expand Down Expand Up @@ -45,32 +45,26 @@ export function search(name = null, offset = 0, limit = 15, follow = true) {
return query({ name, offset, limit, follow });
}

export function userQuery(query = {}) {
return request.get("/user/question-topics", {
params: query,
validateStatus: status => status === 200
export function userQuery(params = {}) {
return api.get("/user/question-topics", {
params,
validateStatus: s => s === 200
});
}

export function followTopics(after = 0, limit = 15) {
export function getFollowTopics(after = 0, limit = 15) {
return userQuery({ after, limit, type: "follow" });
}

/**
* Follow a topic.
*
* @param {number} id
* @return {Promise}
* @author Seven Du <[email protected]>
* @param {number} topicId
* @returns
*/
export function follow(id) {
return request.put(
`/user/question-topics/${id}`,
{},
{
validateStatus: status => status === 201
}
);
export function followTopic(topicId) {
const url = `/user/question-topics/${topicId}`;
return api.put(url, {}, { validateStatus: s => s === 201 });
}

/**
Expand All @@ -80,8 +74,8 @@ export function follow(id) {
* @return {Promise}
* @author Seven Du <[email protected]>
*/
export function unfollow(id) {
return request.delete(`/user/question-topics/${id}`, {
export function unfollowTopic(id) {
return api.delete(`/user/question-topics/${id}`, {
validateStatus: status => status === 204
});
}
Expand All @@ -94,7 +88,7 @@ export function unfollow(id) {
* @author Seven Du <[email protected]>
*/
export function show(topic) {
return request.get(`/question-topics/${topic}`, {
return api.get(`/question-topics/${topic}`, {
validateStatus: status => status === 200
});
}
Expand All @@ -110,7 +104,7 @@ export function show(topic) {
* @author Seven Du <[email protected]>
*/
export function questions(topic, type, offset = 0, limit = 15) {
return request.get(`/question-topics/${topic}/questions`, {
return api.get(`/question-topics/${topic}/questions`, {
params: { type, offset, limit },
validateStatus: status => status === 200
});
Expand Down
29 changes: 15 additions & 14 deletions src/page/question/TopicList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<script>
import TopicCard from "./components/TopicCard.vue";
import { all, followTopics, follow, unfollow } from "@/api/question/topics";
import * as api from "@/api/question/topics.js";
export default {
name: "TopicList",
Expand Down Expand Up @@ -77,7 +77,8 @@ export default {
handleRefreshByAll() {
const offset = 0;
const limit = 15;
all(offset, limit)
api
.all(offset, limit)
.then(({ data }) => {
this.topics = data;
this.loadContainer.topEnd(false);
Expand All @@ -92,7 +93,8 @@ export default {
handleRefreshByFollow() {
const after = 0;
const limit = 15;
followTopics(after, limit)
api
.getFollowTopics(after, limit)
.then(({ data }) => {
this.topics = data;
this.loadContainer.topEnd(false);
Expand All @@ -116,7 +118,8 @@ export default {
handleLoadMoreByAll() {
const offset = this.topics.length;
const limit = 15;
all(offset, limit)
api
.all(offset, limit)
.then(({ data }) => {
this.topics = [...this.topics, ...data];
this.loadContainer.bottomEnd(data.length < limit);
Expand All @@ -129,7 +132,8 @@ export default {
handleLoadMoreByFollow() {
const { id: after } = this.topisc[this.topics.length];
const limit = 15;
followTopics(after, limit)
api
.getFollowTopics(after, limit)
.then(({ data }) => {
this.topics = [...this.topics, ...data];
this.loadContainer.bottomEnd(data.length < limit);
Expand All @@ -140,17 +144,14 @@ export default {
});
},
handleFollow(topic) {
follow(topic.id)
.then(() => {
topic.has_follow = true;
this.follows_count += 1;
})
.catch(({ response: { data } = {} }) => {
this.$Message.error(data);
});
api.followTopic(topic.id).then(() => {
topic.has_follow = true;
this.follows_count += 1;
});
},
handleUnfollow(topic) {
unfollow(topic.id)
api
.unfollowTopic(topic.id)
.then(() => {
topic.has_follow = false;
topic.follows_count -= 1;
Expand Down
4 changes: 2 additions & 2 deletions src/page/question/components/TopicCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ export default {
},
methods: {
handleUnfollow(topic) {
this.$emit("unfollow", { topic });
this.$emit("unfollow", topic);
},
handleFollow(topic) {
this.$emit("follow", { topic });
this.$emit("follow", topic);
}
}
};
Expand Down

0 comments on commit 2f607ea

Please sign in to comment.