From 08e87f625ee8c3b1566930c06e9fff2a92509ab1 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Wed, 28 Jul 2021 14:24:35 -0400 Subject: [PATCH] Add support for display name, initial value and url parameters --- README.md | 11 ++++++++++- app.js | 31 +++++++++++++++++++++++++++++-- components/client.jsx | 8 ++++++-- components/message-composer.jsx | 5 +++-- 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7a36435..d43f331 100644 --- a/README.md +++ b/README.md @@ -67,4 +67,13 @@ To set custom highlight colors, change the Sass variables `$color-highlight-cust * `signInPrompt` (*string*) - Show sign in prompts - `'none'` - Never show (default) - `'guests'` - Show if signed in as guest - - `'all'` - Always show \ No newline at end of file + - `'all'` - Always show +* `displayName` (*string*) - Display name of user, useful when using guest accounts +* `composerIntialValue` (*string*) - Initial value of the composer for prepoulating a sample message +* `signInPrompt` (*string*) - Show sign in prompts + - `'none'` - Never show (default) + - `'guests'` - Show if signed in as guest + - `'all'` - Always show +* `urlParameters` (*boolean*) - Allow adding to config with url prameters (`#displayName=Something`) + - `'true'` (default) + - `'false'` \ No newline at end of file diff --git a/app.js b/app.js index cd24ca6..aeecda4 100644 --- a/app.js +++ b/app.js @@ -6,6 +6,33 @@ import ThemeContext from './components/theme-context.jsx'; require('./styles/main.scss'); ReactDOM.render( - , + , document.getElementById('root') -); \ No newline at end of file +); + +function getConfigFromURL() { + if (!config.urlParameters) return {}; + + const hash = window.location.hash.substr(1); + const params = hash.split('&').reduce((acc, param) => { + const [key, value] = param.split('='); + acc[key] = parseValue(value); + console.log(value) + return acc; + }, {}); + + console.log(params) + + return params; +} + +function parseValue(value) { + if (value === 'true') { + return true; + } else if (value === 'false') { + return false; + } else if (Number.isFinite(value)) { + return Number(value); + } + return decodeURI(value); +} \ No newline at end of file diff --git a/components/client.jsx b/components/client.jsx index 9b4965f..559b418 100644 --- a/components/client.jsx +++ b/components/client.jsx @@ -40,7 +40,9 @@ export default class Client extends Component{ roomsList: PropTypes.bool, // Enable roomsList? Overrides readOnly msgComposer: PropTypes.bool, // Enable msgComposer? Overrides readOnly whitelist: PropTypes.array, // Whitelisted origins - ignore to allow all - signInPrompt: PropTypes.string // Show signInPrompt for - none, guests, all + signInPrompt: PropTypes.string, // Show signInPrompt for - none, guests, all + displayName: PropTypes.string, // Display name for user (used for guests) + composerIntialValue: PropTypes.string // Initial value of composer }; constructor(props) { @@ -119,6 +121,7 @@ export default class Client extends Component{ userId: userId }); this.client.setGuest(true); + if (this.props.displayName) this.client.setDisplayName(this.props.displayName); if (props.readOnly) { this.client.peekInRoom(this.props.roomId, {syncRoom: true}).then(() => { this.init(); @@ -537,7 +540,7 @@ export default class Client extends Component{ }
- {this.state.roomsList && ( 1 && ()} : <>} {this.state.msgComposer ?