Prettified Code!

This commit is contained in:
gabek
2021-07-31 23:22:00 +00:00
committed by GitHub Action
parent 7e6f53c846
commit a791d9c910

View File

@@ -8,10 +8,7 @@ import Websocket, {
SOCKET_MESSAGE_TYPES, SOCKET_MESSAGE_TYPES,
} from './utils/websocket.js'; } from './utils/websocket.js';
import { registerChat } from './chat/register.js'; import { registerChat } from './chat/register.js';
import { import { getLocalStorage, setLocalStorage } from './utils/helpers.js';
getLocalStorage,
setLocalStorage,
} from './utils/helpers.js';
import { import {
CHAT_MAX_MESSAGE_LENGTH, CHAT_MAX_MESSAGE_LENGTH,
EST_SOCKET_PAYLOAD_BUFFER, EST_SOCKET_PAYLOAD_BUFFER,
@@ -24,7 +21,6 @@ import {
TIMER_STATUS_UPDATE, TIMER_STATUS_UPDATE,
} from './utils/constants.js'; } from './utils/constants.js';
export default class StandaloneChat extends Component { export default class StandaloneChat extends Component {
constructor(props, context) { constructor(props, context) {
super(props, context); super(props, context);
@@ -128,10 +124,7 @@ export default class StandaloneChat extends Component {
if (!status) { if (!status) {
return; return;
} }
const { const { online, lastDisconnectTime } = status;
online,
lastDisconnectTime,
} = status;
if (status.online && !curStreamOnline) { if (status.online && !curStreamOnline) {
// stream has just come online. // stream has just come online.
@@ -157,7 +150,6 @@ export default class StandaloneChat extends Component {
this.setState({ this.setState({
streamOnline: false, streamOnline: false,
}); });
} }
handleOnlineMode() { handleOnlineMode() {
@@ -177,7 +169,6 @@ export default class StandaloneChat extends Component {
this.sendUsernameChange(newName); this.sendUsernameChange(newName);
} }
disableChatInput() { disableChatInput() {
this.setState({ this.setState({
chatInputEnabled: false, chatInputEnabled: false,
@@ -241,10 +232,14 @@ export default class StandaloneChat extends Component {
async setupChatAuth(force) { async setupChatAuth(force) {
const { readonly } = this.props; const { readonly } = this.props;
var accessToken = readonly ? getLocalStorage(KEY_EMBED_CHAT_ACCESS_TOKEN) : getLocalStorage(KEY_ACCESS_TOKEN); var accessToken = readonly
? getLocalStorage(KEY_EMBED_CHAT_ACCESS_TOKEN)
: getLocalStorage(KEY_ACCESS_TOKEN);
var randomIntArray = new Uint32Array(1); var randomIntArray = new Uint32Array(1);
window.crypto.getRandomValues(randomIntArray); window.crypto.getRandomValues(randomIntArray);
var username = readonly ? 'chat-embed-' + randomIntArray[0] : getLocalStorage(KEY_USERNAME); var username = readonly
? 'chat-embed-' + randomIntArray[0]
: getLocalStorage(KEY_USERNAME);
if (!accessToken || force) { if (!accessToken || force) {
try { try {
@@ -296,45 +291,39 @@ export default class StandaloneChat extends Component {
} }
render(props, state) { render(props, state) {
const { const { username, websocket, accessToken, chatInputEnabled, configData } =
username, state;
websocket,
accessToken,
chatInputEnabled,
configData,
} = state;
const { const { chatDisabled, maxSocketPayloadSize, customStyles, name } =
chatDisabled, configData;
maxSocketPayloadSize,
customStyles,
name,
} = configData;
const { readonly } = props; const { readonly } = props;
return this.state.websocket ? return this.state.websocket
html`${!readonly ? ? html`${!readonly
html`<style> ? html`<style>
${customStyles} ${customStyles}
</style> </style>
<header class="flex flex-row-reverse fixed z-10 w-full bg-gray-900"> <header
<${UsernameForm} class="flex flex-row-reverse fixed z-10 w-full bg-gray-900"
>
<${UsernameForm}
username=${username}
onUsernameChange=${this.handleUsernameChange}
onFocus=${this.handleFormFocus}
onBlur=${this.handleFormBlur}
/>
</header>`
: ''}
<${Chat}
websocket=${websocket}
username=${username} username=${username}
onUsernameChange=${this.handleUsernameChange} accessToken=${accessToken}
onFocus=${this.handleFormFocus} readonly=${readonly}
onBlur=${this.handleFormBlur} instanceTitle=${name}
/> chatInputEnabled=${chatInputEnabled && !chatDisabled}
</header>` : ''} inputMaxBytes=${maxSocketPayloadSize - EST_SOCKET_PAYLOAD_BUFFER ||
<${Chat} CHAT_MAX_MESSAGE_LENGTH}
websocket=${websocket} />`
username=${username}
accessToken=${accessToken}
readonly=${readonly}
instanceTitle=${name}
chatInputEnabled=${chatInputEnabled && !chatDisabled}
inputMaxBytes=${maxSocketPayloadSize - EST_SOCKET_PAYLOAD_BUFFER ||
CHAT_MAX_MESSAGE_LENGTH}
/>`
: null; : null;
} }
} }