From e0c90cdcb2b602e890fb123ceaaf4b5192865abc Mon Sep 17 00:00:00 2001 From: Gorji Date: Wed, 26 May 2021 12:12:50 +0430 Subject: [PATCH] need fix --- src/Redux/actions/chat.js | 8 + src/Redux/actions/index.js | 1 + src/Redux/actions/message.js | 13 + src/Redux/proxy.js | 2 +- src/Redux/reducers/chat.js | 13 + src/Redux/reducers/index.js | 1 + src/Redux/reducers/message.js | 16 ++ src/views/ChatRoom/Body/Body.js | 253 ++---------------- .../DraggableMessage/DraggableMessage.js | 12 +- src/views/ChatRoom/Body/Message/Message.js | 14 +- .../Body/Message/Message2D/Message2D.js | 12 +- .../Message/NormalMessage/NormalMessage.js | 40 ++- .../Body/Message/RadioMessage/RadioMessage.js | 12 +- .../Message/SliderMessage/SliderMessage.js | 12 +- 14 files changed, 126 insertions(+), 283 deletions(-) create mode 100644 src/Redux/actions/message.js create mode 100644 src/Redux/reducers/message.js diff --git a/src/Redux/actions/chat.js b/src/Redux/actions/chat.js index 0a12d5c..2ffa612 100644 --- a/src/Redux/actions/chat.js +++ b/src/Redux/actions/chat.js @@ -3,3 +3,11 @@ export const list = (data = {}) => async (dispatch) => (await proxy.get('chat/list', data)).dispatch(dispatch); +export const info = + (data = {}) => + async (dispatch) => + (await proxy.get('chat/info', data)).dispatch(dispatch); +export const bio = + (data = {}) => + async (dispatch) => + (await proxy.get('chat/bio', data)).dispatch(dispatch); diff --git a/src/Redux/actions/index.js b/src/Redux/actions/index.js index 1723be2..8605f81 100644 --- a/src/Redux/actions/index.js +++ b/src/Redux/actions/index.js @@ -1,6 +1,7 @@ // @create-index export { default as chat } from './chat.js'; +export { default as message } from './message.js'; export { default as public } from './public.js'; export { default as user } from './user.js'; diff --git a/src/Redux/actions/message.js b/src/Redux/actions/message.js new file mode 100644 index 0000000..064898f --- /dev/null +++ b/src/Redux/actions/message.js @@ -0,0 +1,13 @@ +import proxy from '../proxy'; +export const list = + (data = {}) => + async (dispatch) => + (await proxy.get('message/list', data)).dispatch(dispatch); +export const send = + (data = {}) => + async (dispatch) => + (await proxy.post('message/send', data)).dispatch(dispatch); +export const sendKeys = + (data = {}) => + async (dispatch) => + (await proxy.post('message/sendKeys', data)).dispatch(dispatch); diff --git a/src/Redux/proxy.js b/src/Redux/proxy.js index 25f4400..0b64b80 100644 --- a/src/Redux/proxy.js +++ b/src/Redux/proxy.js @@ -43,7 +43,7 @@ class Proxy { }; login = async (data, opt = { headers: { Authorization: `Bearer ${token}` } }) => { const login = await this.post(loginURL, data, opt); - if (!login) this.result('login', false); + if (!login || !login.refreshToken) this.result('login', false); localStorage.setItem('refresh', login.refreshToken); delete login.refreshToken; if (data != {}) setTimeout(() => (window.location.href = '/'), 100); diff --git a/src/Redux/reducers/chat.js b/src/Redux/reducers/chat.js index 39fbfa8..4aa72da 100644 --- a/src/Redux/reducers/chat.js +++ b/src/Redux/reducers/chat.js @@ -1,11 +1,24 @@ const initialState = { list: [], + info: { users: [] }, + bio: { + album: [], + images: [], + videos: [], + music: [], + documnet: [], + link: [], + }, }; export default function chat(state = initialState, action) { let { type, data } = action; switch (type) { case 'chat/list': return { ...state, list: data }; + case 'chat/info': + return { ...state, info: data }; + case 'chat/bio': + return { ...state, bio: data }; default: return state; } diff --git a/src/Redux/reducers/index.js b/src/Redux/reducers/index.js index 1723be2..8605f81 100644 --- a/src/Redux/reducers/index.js +++ b/src/Redux/reducers/index.js @@ -1,6 +1,7 @@ // @create-index export { default as chat } from './chat.js'; +export { default as message } from './message.js'; export { default as public } from './public.js'; export { default as user } from './user.js'; diff --git a/src/Redux/reducers/message.js b/src/Redux/reducers/message.js new file mode 100644 index 0000000..fd8dba5 --- /dev/null +++ b/src/Redux/reducers/message.js @@ -0,0 +1,16 @@ +const initialState = { + list: [], +}; +export default function chat(state = initialState, action) { + let { type, data } = action; + switch (type) { + case 'message/list': + return { ...state, list: data }; + case 'message/send': + return { ...state, list: [...list, ...data] }; + case 'message/sendKeys': + return { ...state, list: [...list, ...data] }; + default: + return state; + } +} diff --git a/src/views/ChatRoom/Body/Body.js b/src/views/ChatRoom/Body/Body.js index c909491..a586dcd 100644 --- a/src/views/ChatRoom/Body/Body.js +++ b/src/views/ChatRoom/Body/Body.js @@ -9,231 +9,15 @@ import ReactAudioPlayer from 'react-audio-player'; import photo from '../../../assets/images/reza.png'; import photo1 from '../../../assets/images/user2.png'; import './Body.scss'; -export default class Body extends Component { +import { list, send, sendKeys } from '../../../Redux/actions/message'; +import { info, bio } from '../../../Redux/actions/chat'; +import { connect } from 'react-redux'; +class Body extends Component { constructor(props) { super(props); this.state = { - data: { - id: '1', - users: [ - { - id: 'u1', - name: 'حسن', - imageUri: photo, - }, - { - id: 'u2', - name: 'علی', - imageUri: photo1, - }, - ], - messages: [ - { - id: 'm1', - type: 'normal', - text: 'چظوری!', - voice: null, - image: null, - video: null, - music: null, - document: null, - createdAt: '2020-10-10T12:48:00.000Z', - user: { - id: 'u1', - name: 'علی', - }, - }, - { - id: 'm2', - type: 'normal', - text: 'من خیلی خوبم', - voice: null, - image: null, - video: null, - music: null, - document: null, - createdAt: '2020-10-03T14:49:00.000Z', - user: { - id: 'u2', - name: 'رضا', - }, - }, - { - id: 'm3', - type: 'normal', - text: 'تو خودت چطوری؟', - voice: null, - image: null, - video: null, - music: null, - document: null, - createdAt: '2020-10-03T14:49:40.000Z', - user: { - id: 'u2', - name: 'رضا', - }, - }, - { - id: 'm4', - type: 'normal', - text: 'خوبی', - voice: null, - image: null, - video: null, - music: null, - document: null, - createdAt: '2020-10-03T14:50:00.000Z', - user: { - id: 'u1', - name: 'علی', - }, - }, - { - id: 'm5', - type: 'normal', - text: 'کجا رفتی؟', - voice: null, - image: null, - video: null, - music: null, - document: null, - createdAt: '2020-10-03T14:51:00.000Z', - user: { - id: 'u1', - name: 'علی', - }, - }, - { - id: 'm6', - type: 'normal', - text: 'نشد که بشه', - voice: null, - image: null, - video: null, - music: null, - document: null, - createdAt: '2020-10-03T14:49:00.000Z', - user: { - id: 'u2', - name: 'رضا', - }, - }, - { - id: 'm7', - type: 'normal', - text: 'من که به نظرم خوب نمیاد', - voice: null, - image: null, - video: null, - music: null, - document: null, - createdAt: '2020-10-03T14:53:00.000Z', - user: { - id: 'u1', - name: 'علی', - }, - }, - { - id: 'm7', - type: 'normal', - text: 'یک تماس جدید', - voice: null, - image: null, - video: null, - music: null, - document: null, - createdAt: '2020-10-03T14:53:00.000Z', - user: { - id: 'u1', - name: 'علی', - }, - }, - { - id: 'm10', - type: '2d', - options: [ - [{ id: 0, name: 'تکنولوژی' }], - [ - { id: 1, name: 'ورزشی' }, - { id: 2, name: 'علمی' }, - ], - [ - { id: 3, name: 'مذهبی' }, - { id: 4, name: 'اجتماعی' }, - { id: 5, name: 'سیاسی' }, - ], - ], - text: 'به دنبال چی میگردی؟', - voice: null, - image: null, - video: null, - music: null, - document: null, - createdAt: '2020-10-03T14:53:00.000Z', - user: { - id: 'u2', - name: 'رضا', - }, - }, - { - id: 'm11', - type: 'draggable', - options: [ - [{ id: 0, name: 'پرسپولیس', position: 1 }], - [{ id: 1, name: 'سپاهان', position: 2 }], - [{ id: 2, name: 'استقلال', position: 3 }], - ], - text: ' موقعیت تیم‌های زیر را در پایان مسابقات جدول لیگ برتر را پیش بینی کنید!', - voice: null, - image: null, - video: null, - music: null, - document: null, - createdAt: '2020-10-03T14:53:00.000Z', - user: { - id: 'u2', - name: 'رضا', - }, - }, - { - id: 'm12', - type: 'slider', - options: null, - text: 'معدل شما درآزمون دکتری', - voice: null, - image: null, - video: null, - music: null, - document: null, - createdAt: '2020-10-03T14:53:00.000Z', - user: { - id: 'u2', - name: 'رضا', - }, - }, - { - id: 'm13', - type: 'radio', - options: [ - { id: 0, name: 'مادرید' }, - { id: 1, name: 'میلان' }, - { id: 2, name: 'رم' }, - { id: 3, name: 'ونیز' }, - ], - text: 'پایتخت کشور ایتالیا؟', - voice: null, - image: null, - video: null, - music: null, - document: null, - createdAt: '2020-10-03T14:53:00.000Z', - user: { - id: 'u2', - name: 'رضا', - }, - }, - ], - }, + id: window.location.href.split('/').pop() * 1, + data: {}, message: '', voice: null, file: null, @@ -548,8 +332,9 @@ export default class Body extends Component { }; componentDidMount() { - let chatroom = document.getElementById('chatroom'); - chatroom.scrollTop = chatroom.scrollHeight + 40; + this.props.list({ chatId: this.state.id }); + this.props.info({ id: this.state.id }); + // this.componentDidUpdate(); } componentDidUpdate() { @@ -562,8 +347,8 @@ export default class Body extends Component { return (
setPage('info')}> -

محسن محمدی

-

2 دقیقه پیش آنلاین بوده

+

{this.props.info.title}

+

{this.props.info.subtitle}

- {this.state.data.messages.map((item, i) => + {this.props.message_list.map((item, i) => this.state.image === null && this.state.music === null && this.state.video === null ? ( ) : null )} @@ -604,7 +389,7 @@ export default class Body extends Component { {this.state.document !== null ? (
-

{`ارسال (${this.state.document.name}) به ${this.state.data.users[1].name}؟`}

+

{`ارسال (${this.state.document.name}) به ${this.props.info.title}؟`}