Skip to content

Commit

Permalink
Add randdom room name generation
Browse files Browse the repository at this point in the history
  • Loading branch information
saghul committed May 20, 2020
1 parent a1a52c4 commit d2f4928
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 26 deletions.
144 changes: 126 additions & 18 deletions app/features/welcome/components/Welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SpotlightTarget } from '@atlaskit/onboarding';
import Page from '@atlaskit/page';
import { AtlasKitThemeProvider } from '@atlaskit/theme';

import { generateRoomWithoutSeparator } from 'js-utils/random';
import React, { Component } from 'react';
import type { Dispatch } from 'redux';
import { connect } from 'react-redux';
Expand All @@ -16,7 +17,7 @@ import { Onboarding, startOnboarding } from '../../onboarding';
import { RecentList } from '../../recent-list';
import { normalizeServerURL } from '../../utils';

import { Body, Form, Header, Wrapper } from '../styled';
import { Body, FieldWrapper, Form, Header, Label, Wrapper } from '../styled';


type Props = {
Expand All @@ -34,6 +35,26 @@ type Props = {

type State = {

/**
* Timer for animating the room name geneeration.
*/
animateTimeoutId: ?TimeoutID,

/**
* Generated room name.
*/
generatedRoomname: string,

/**
* Current room name placeholder.
*/
roomPlaceholder: string,

/**
* Timer for re-generating a new room name.
*/
updateTimeoutId: ?TimeoutID,

/**
* URL of the room to join.
* If this is not a url it will be treated as room name for default domain.
Expand Down Expand Up @@ -65,23 +86,43 @@ class Welcome extends Component<Props, State> {
}
}

this.state = { url };
this.state = {
animateTimeoutId: undefined,
generatedRoomname: '',
roomPlaceholder: '',
updateTimeoutId: undefined,
url
};

// Bind event handlers.
this._animateRoomnameChanging = this._animateRoomnameChanging.bind(this);
this._onURLChange = this._onURLChange.bind(this);
this._onFormSubmit = this._onFormSubmit.bind(this);
this._onJoin = this._onJoin.bind(this);
this._updateRoomname = this._updateRoomname.bind(this);
}

/**
* Start Onboarding once component is mounted.
* Start generating randdom room names.
*
* NOTE: It autonatically checks if the onboarding is shown or not.
*
* @returns {void}
*/
componentDidMount() {
this.props.dispatch(startOnboarding('welcome-page'));

this._updateRoomname();
}

/**
* Stop all timers when unmounting.
*
* @returns {voidd}
*/
componentWillUnmount() {
this._clearTimeouts();
}

/**
Expand All @@ -103,6 +144,46 @@ class Welcome extends Component<Props, State> {
);
}

_animateRoomnameChanging: (string) => void;

/**
* Animates the changing of the room name.
*
* @param {string} word - The part of room name that should be added to
* placeholder.
* @private
* @returns {void}
*/
_animateRoomnameChanging(word: string) {
let animateTimeoutId;
const roomPlaceholder = this.state.roomPlaceholder + word.substr(0, 1);

if (word.length > 1) {
animateTimeoutId
= setTimeout(
() => {
this._animateRoomnameChanging(
word.substring(1, word.length));
},
70);
}
this.setState({
animateTimeoutId,
roomPlaceholder
});
}

/**
* Method that clears timeouts for animations and updates of room name.
*
* @private
* @returns {void}
*/
_clearTimeouts() {
clearTimeout(this.state.animateTimeoutId);
clearTimeout(this.state.updateTimeoutId);
}

_onFormSubmit: (*) => void;

/**
Expand All @@ -124,7 +205,7 @@ class Welcome extends Component<Props, State> {
* @returns {void}
*/
_onJoin() {
const inputURL = this.state.url;
const inputURL = this.state.url || this.state.generatedRoomname;
const lastIndexOfSlash = inputURL.lastIndexOf('/');
let room;
let serverURL;
Expand Down Expand Up @@ -195,26 +276,53 @@ class Welcome extends Component<Props, State> {
<Header>
<SpotlightTarget name = 'conference-url'>
<Form onSubmit = { this._onFormSubmit }>
<FieldTextStateless
autoFocus = { true }
isInvalid = { locationError }
isLabelHidden = { true }
onChange = { this._onURLChange }
placeholder = 'Enter a name for your conference or a Jitsi URL'
shouldFitContainer = { true }
type = 'text'
value = { this.state.url } />
<Label>{ 'Enter a name for your conference or a Jitsi URL' } </Label>
<FieldWrapper>
<FieldTextStateless
autoFocus = { true }
isInvalid = { locationError }
isLabelHidden = { true }
onChange = { this._onURLChange }
placeholder = { this.state.roomPlaceholder }
shouldFitContainer = { true }
type = 'text'
value = { this.state.url } />
<Button
appearance = 'primary'
onClick = { this._onJoin }
type = 'button'>
GO
</Button>
</FieldWrapper>
</Form>
</SpotlightTarget>
<Button
appearance = 'primary'
onClick = { this._onJoin }
type = 'button'>
GO
</Button>
</Header>
);
}

_updateRoomname: () => void;

/**
* Triggers the generation of a new room name and initiates an animation of
* its changing.
*
* @protected
* @returns {void}
*/
_updateRoomname() {
const generatedRoomname = generateRoomWithoutSeparator();
const roomPlaceholder = '';
const updateTimeoutId = setTimeout(this._updateRoomname, 10000);

this._clearTimeouts();
this.setState(
{
generatedRoomname,
roomPlaceholder,
updateTimeoutId
},
() => this._animateRoomnameChanging(generatedRoomname));
}
}

export default connect()(Welcome);
10 changes: 10 additions & 0 deletions app/features/welcome/styled/FieldWrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @flow

import styled from 'styled-components';

export default styled.div`
align-items: center;
display: flex;
justify-content: space-between;
magin: auto;
`;
8 changes: 8 additions & 0 deletions app/features/welcome/styled/Label.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @flow

import styled from 'styled-components';

export default styled.span`
color: white;
font-weight: bold;
`;
2 changes: 2 additions & 0 deletions app/features/welcome/styled/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export { default as Body } from './Body';
export { default as FieldWrapper } from './FieldWrapper';
export { default as Form } from './Form';
export { default as Header } from './Header';
export { default as Label } from './Label';
export { default as Wrapper } from './Wrapper';
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"electron-window-state": "5.0.3",
"history": "4.10.1",
"jitsi-meet-electron-utils": "github:jitsi/jitsi-meet-electron-utils#v2.0.6",
"js-utils": "github:jitsi/js-utils#0c53500a5120be2aa3fc590f0f932a0d4771920f",
"js-utils": "github:jitsi/js-utils#cf11996bd866fdb47326c59a5d3bc24be17282d4",
"moment": "2.23.0",
"mousetrap": "1.6.2",
"react": "16.6.3",
Expand Down

0 comments on commit d2f4928

Please sign in to comment.