Skip to content

Commit 69d5ef3

Browse files
committed
feat: add de_collect topic
1 parent 4ee6bab commit 69d5ef3

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/actions/topics.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { handleResponse, handleError } from '@/middleWares'
33
import { domain } from '@/constants'
44

55
export const COLLECT_TOPIC = 'COLLECT_TOPIC'
6-
export const collectTopic = ({ accesstoken, topic_id }) => dispatch => {
7-
fetch(`${domain}topic_collect/collect`, {
6+
export const collectTopic = ({ accesstoken, topic_id, is_collect }) => dispatch => {
7+
const url = `${domain}topic_collect/${is_collect ? 'de_' : ''}collect`
8+
fetch(url, {
89
method: 'POST',
910
body: JSON.stringify({ accesstoken, topic_id }),
1011
headers: new Headers({
@@ -15,7 +16,8 @@ export const collectTopic = ({ accesstoken, topic_id }) => dispatch => {
1516
.then(res => {
1617
if (res.success) {
1718
dispatch({
18-
type: COLLECT_TOPIC
19+
type: COLLECT_TOPIC,
20+
action: is_collect
1921
})
2022
}
2123
})

src/components/TopicDetail/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ class TopicDetail extends Component {
5050
alert('请先登录!')
5151
return
5252
}
53-
if (topic.is_collect) return
5453

5554
collectTopic({
5655
accesstoken,
57-
topic_id: topic.id
56+
topic_id: topic.id,
57+
is_collect: topic.is_collect
5858
})
5959
}
6060
like(id) {

src/reducers/topic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default function topic(state = _state, action) {
1818
case FETCH_TOPIC_DETAIL:
1919
return action.data
2020
case COLLECT_TOPIC:
21-
return Object.assign({}, state, { is_collect: true })
21+
return Object.assign({}, state, { is_collect: !action.action })
2222
case LIKE_REPLY:
2323
const copy = Object.assign({}, state)
2424
const reply = copy.replies.find(item => item.id === action.id)

0 commit comments

Comments
 (0)