Skip to content

Commit

Permalink
更新代码
Browse files Browse the repository at this point in the history
  • Loading branch information
54sword committed Feb 8, 2018
1 parent ee60aa8 commit b611503
Show file tree
Hide file tree
Showing 7 changed files with 263 additions and 163 deletions.
65 changes: 64 additions & 1 deletion src/actions/comment.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import grapgQLClient from '../common/grapgql-client'


import Ajax from '../common/ajax'
import { DateDiff } from '../common/date'
Expand Down Expand Up @@ -246,7 +248,7 @@ export function loadCommentList({ name, filters = {}, restart = false }) {
name,
restart,
filters,

processList: processCommentList,

schemaName: 'comments',
Expand All @@ -257,6 +259,66 @@ export function loadCommentList({ name, filters = {}, restart = false }) {
}
}


export function updateComment(filters) {
return async (dispatch, getState) => {

let accessToken = getState().user.accessToken

let variables = []

for (let i in filters) {

let v = ''

switch (typeof filters[i]) {
case 'string':
v = '"'+filters[i]+'"'
break
case 'number':
v = filters[i]
break
default:
v = filters[i]
break
}

variables.push(i+':'+v)
}

let sql = `
mutation {
updateComment(${variables}){
success
}
}
`

let [ err, res ] = await grapgQLClient({
mutation:sql,
headers: accessToken ? { 'AccessToken': accessToken } : null
})

if (err) return alert('提交失败')

let _id = filters._id

delete filters._id

dispatch({ type: 'UPDATE_COMMENT', id: _id, update: filters })
let list = getState().comment

for (let i in list) {
if (list[i].data) {
list[i].data = processPostsList(list[i].data)
}
}

dispatch({ type: 'UPDATE_COMMENT', state: list })
}
}

/*
export function updateComment({ query = {}, update = {}, options = {} }) {
return (dispatch, getState) => {
Expand Down Expand Up @@ -287,6 +349,7 @@ export function updateComment({ query = {}, update = {}, options = {} }) {
})
}
}
*/

/*
export function loadCommentList({ name, filters = {}, callback = ()=>{} }) {
Expand Down
52 changes: 51 additions & 1 deletion src/actions/notification.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,59 @@
import Ajax from '../common/ajax'
import merge from 'lodash/merge'

import loadList from './common/load-list'
import loadList from './common/new-load-list'

export function loadNotifications({ name, filters = {}, restart = false }) {
return (dispatch, getState) => {

if (!filters.select) {
filters.select = `
has_read
deleted
create_at
_id
type
comment_id {
_id
content_html
posts_id {
_id
title
content_html
}
reply_id {
_id
content_html
}
parent_id {
_id
content_html
}
}
sender_id {
create_at
avatar
_id
nickname
avatar_url
id
}
addressee_id {
create_at
avatar
_id
nickname
avatar_url
id
}
posts_id {
title
content_html
_id
}
`
}

return loadList({
dispatch,
getState,
Expand All @@ -15,6 +64,7 @@ export function loadNotifications({ name, filters = {}, restart = false }) {

// processList: processPostsList,

schemaName: 'userNotifications',
reducerName: 'notification',
api: '/user-notifications',
type: 'post',
Expand Down
14 changes: 5 additions & 9 deletions src/components/comment/list-item/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,8 @@ export class CommentItem extends PureComponent {
updateComment(e, data) {
this.stopPropagation(e)
const { comment, updateComment } = this.props
updateComment({
query: {
_id: comment._id
},
update: data
})
data._id = comment._id
updateComment(data)
}

// 用户的dom
Expand Down Expand Up @@ -107,11 +103,11 @@ export class CommentItem extends PureComponent {
{comment._create_at}
</td>
<td width="200">
<a href="javascript:void(0)" onClick={updateComment({ weaken: comment.weaken ? false : true })}>弱化</a>
<a href="javascript:void(0)" onClick={updateComment({ weaken: comment.weaken ? false : true })}>{comment.weaken ? '已弱化' : '弱化'}</a>
{' '}
<a href="javascript:void(0)" onClick={updateComment({ recommend: comment.recommend ? false : true })}>推荐</a>
<a href="javascript:void(0)" onClick={updateComment({ recommend: comment.recommend ? false : true })}>{comment.recommend ? '已推荐' : '推荐'}</a>
{' '}
<a href="javascript:void(0)" onClick={updateComment({ deleted: comment.deleted ? false : true })}>删除</a>
<a href="javascript:void(0)" onClick={updateComment({ deleted: comment.deleted ? false : true })}>{comment.deleted ? '已删除' : '删除'}</a>
</td>
</tr>
</tbody>
Expand Down
9 changes: 7 additions & 2 deletions src/components/comment/list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import PropTypes from 'prop-types'
import { getCommentListByName } from '../../../reducers/comment'
import { loadCommentList } from '../../../actions/comment'

// import ListLoading from '../list-loading'
import ListLoading from '../../list-loading'
import CommentItem from '../list-item'

import connectReudx from '../../../common/connect-redux'
Expand Down Expand Up @@ -63,10 +63,13 @@ export class CommentList extends Component {

if (!list.data) return null

const { data, loading, more } = list

return (
<div>
<div>
{/* <div className={styles.comments}> */}
{list.data.map((comment)=>{
{data.map((comment)=>{
return (<div key={comment._id}><CommentItem comment={comment} /></div>)
})}
{/*commentList.data.length == 0 ?
Expand All @@ -79,6 +82,8 @@ export class CommentList extends Component {
{/*<div className={styles.nothing}>目前尚无回复</div>*/}

{/* </div> */}
</div>
<ListLoading loading={loading} more={more} handleLoad={this.load} />
</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/notification/list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export class NotificationList extends Component {
}

if (content) {

let backgroundColor = ''
if (notice.deleted) {
backgroundColor = '#ffe3e3'
Expand Down
Loading

0 comments on commit b611503

Please sign in to comment.