docbrown/app/javascript/chat/content.jsx
narender2031 e78a0078a7
[deploy] Refactor 🚀 : Replaced Chat Channel Setting page with Preact component. (#8271)
* Feature 🚀 : Ability to delete messages in chat channels

- Sending message ID to frontend
- Deleting Message
- Use pusher to delete message realtime

* Minor Bug 🐞: Show message action only for current user

- User can delete or edit their own messages

* Test cases added

* Bug 🐞: Update message id for receiver

Message id was not sent to receiver by pusher

* Refactoring🛠: Message controller refactoring

* Test Cases📝 : Specs for Delete message added

* Feature 🚀 : Ability to edit messages

* Test Cases📝 : Specs for Edit message added

* 🐞 Channel List bug in mobile view

* changes in joining request responses

* 🛠  Request Managers Frontend ready

* changes in routes for adding and removing remembership

* 🚀 New routes implemented for request manager

* fix issues

* changes in api for remove membership

* Merge conflict resolved

* 🐞 Channel List bug in mobile view

* changes in joining request responses

* 🛠  Request Managers Frontend ready

* changes in routes for adding and removing remembership

* 🚀 New routes implemented for request manager

* fix issues

* changes in api for remove membership

* 🛠Optimizing for CodeClimate

* 🛠Optimizing again for CodeClimate

* 🛠Optimizing again 2 for CodeClimate

* 🛠 Added more test cases

* 🛠 Optimizing code

* 🚀 Action to open setting page added

* 🛠  Dummy page added for chat setting

* add JSON routes for chat channel settings

* Integrate chat channel settings API with UI

* 🐞 Channel List bug in mobile view

* 🛠  Request Managers Frontend ready

* changes in routes for adding and removing remembership

* 🚀 New routes implemented for request manager

* fix issues

* 🐞 Channel List bug in mobile view

* 🛠  Request Managers Frontend ready

* changes in routes for adding and removing remembership

* 🚀 New routes implemented for request manager

* fix issues

* 🛠Optimizing again for CodeClimate

* 🚀 Action to open setting page added

* 🛠  Dummy page added for chat setting

* add JSON routes for chat channel settings

* Integrate chat channel settings API with UI

* Fix PR requested changes

* Add JSDoc documentation to exported functions

* fix/add rspec test cases

* refactor channelSettinngs render part

* add test cases for chat channel settings component

* fix code-climate

* add rest component tests

* add more test coverage

* fix code-climate bugs

* add API function test

Co-authored-by: Sarthak Sharma <7lovesharma7@gmail.com>
Co-authored-by: Parasgr-code <paras.gaur@skynox.tech>
2020-06-10 16:58:37 -04:00

93 lines
3 KiB
JavaScript

import { h, Component } from 'preact';
import PropTypes from 'prop-types';
import Article from './article';
import ChannelRequest from './channelRequest';
import RequestManager from './requestManager';
import ChatChannelSettings from './ChatChannelSettings/ChatChannelSettings';
export default class Content extends Component {
static propTypes = {
resource : PropTypes.object,
activeChannelId : PropTypes.number,
pusherKey : PropTypes.string,
fullscreen : PropTypes.bool
};
render() {
const { onTriggerContent, fullscreen } = this.props;
if (!this.props.resource) {
return '';
}
const smartSvgIcon = (content, d) => (
<svg data-content={content} xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
<path data-content={content} fill="none" d="M0 0h24v24H0z" />
<path data-content={content} d={d} />
</svg>
);
return (
<div
className="activechatchannel__activecontent activechatchannel__activecontent--sidecar"
id="chat_activecontent"
onClick={onTriggerContent}
>
<button
className="activechatchannel__activecontentexitbutton crayons-btn crayons-btn--secondary"
data-content="exit"
>
{smartSvgIcon(
'exit',
'M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z'
)}
</button>
<button
className="activechatchannel__activecontentexitbutton activechatchannel__activecontentexitbutton--fullscreen crayons-btn crayons-btn--secondary"
data-content="fullscreen"
style={{ left: '39px' }}
>
{' '}
{fullscreen ? (
smartSvgIcon(
'fullscreen',
'M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z'
)
) : (
smartSvgIcon(
'fullscreen',
'M20 3h2v6h-2V5h-4V3h4zM4 3h4v2H4v4H2V3h2zm16 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z'
)
)}
</button>
{display(this.props)}
</div>
);
}
}
function display(props) {
const { resource } = props;
switch(resource.type_of) {
case 'loading-user':
return <div className="loading-user" />
case 'article':
return <Article resource={resource} />;
case 'channel-request':
return <ChannelRequest resource={resource.data} handleJoiningRequest={resource.handleJoiningRequest} />;
case 'channel-request-manager':
return (
<RequestManager
resource={resource.data}
handleRequestRejection={resource.handleRequestRejection}
handleRequestApproval={resource.handleRequestApproval}
/>
)
case 'chat-channel-setting':
return (
<ChatChannelSettings resource={resource.data} activeMembershipId={resource.activeMembershipId} />
);
default:
return null;
}
}