mirror of
https://github.com/Safe-Support-Chat/ocrcc-chatbox
synced 2024-11-22 02:34:55 +00:00
pass homeserver query param to get chatbox with settings
This commit is contained in:
parent
22c17d314d
commit
004f88d5cd
2
dist/bookmarklet.js
vendored
2
dist/bookmarklet.js
vendored
File diff suppressed because one or more lines are too long
2
dist/chatbox.js
vendored
2
dist/chatbox.js
vendored
File diff suppressed because one or more lines are too long
3
dist/index.html
vendored
3
dist/index.html
vendored
@ -13,7 +13,8 @@
|
|||||||
<script src="./chatbox.js"></script>
|
<script src="./chatbox.js"></script>
|
||||||
<script>
|
<script>
|
||||||
var config = {
|
var config = {
|
||||||
settingsEndpoint: 'https://safesupport-admin.herokuapp.com/api/get-settings'
|
settingsEndpoint: 'https://safesupport-admin.herokuapp.com/api/get-settings',
|
||||||
|
matrixServerUrl: 'https://matrix.safesupport.chat'
|
||||||
}
|
}
|
||||||
|
|
||||||
EmbeddableChatbox.mount(config);
|
EmbeddableChatbox.mount(config);
|
||||||
|
@ -13,7 +13,8 @@
|
|||||||
<script src="./chatbox.js"></script>
|
<script src="./chatbox.js"></script>
|
||||||
<script>
|
<script>
|
||||||
var config = {
|
var config = {
|
||||||
settingsEndpoint: 'https://safesupport-admin.herokuapp.com/api/get-settings'
|
settingsEndpoint: 'https://safesupport-admin.herokuapp.com/api/get-settings',
|
||||||
|
matrixServerUrl: 'https://matrix.safesupport.chat'
|
||||||
}
|
}
|
||||||
|
|
||||||
EmbeddableChatbox.mount(config);
|
EmbeddableChatbox.mount(config);
|
||||||
|
@ -3,22 +3,22 @@ import PropTypes from 'prop-types';
|
|||||||
import Chatbox from './chatbox';
|
import Chatbox from './chatbox';
|
||||||
|
|
||||||
|
|
||||||
const ChatboxWithSettings = ({ settingsEndpoint, ...rest }) => {
|
const ChatboxWithSettings = ({ settingsEndpoint, matrixServerUrl, ...rest }) => {
|
||||||
const [settings, setSettings] = useState({});
|
const [settings, setSettings] = useState({});
|
||||||
|
|
||||||
const settingsObj = {};
|
const settingsObj = {};
|
||||||
|
|
||||||
const getSettings = async () => {
|
const getSettings = async () => {
|
||||||
if (!settingsEndpoint) {
|
if (!settingsEndpoint) {
|
||||||
const props = {
|
const props = {
|
||||||
...rest,
|
...rest,
|
||||||
enabled: true
|
enabled: true,
|
||||||
}
|
};
|
||||||
|
|
||||||
return setSettings(props);
|
return setSettings(props);
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await fetch(settingsEndpoint);
|
const url = `${settingsEndpoint}?homeserver=${encodeURIComponent(matrixServerUrl)}`;
|
||||||
|
const res = await fetch(url);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const { fields } = data;
|
const { fields } = data;
|
||||||
|
|
||||||
@ -42,12 +42,17 @@ const ChatboxWithSettings = ({ settingsEndpoint, ...rest }) => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Chatbox {...settings} {...rest} />
|
<Chatbox matrixServerUrl={matrixServerUrl} {...settings} {...rest} />
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
ChatboxWithSettings.propTypes = {
|
ChatboxWithSettings.propTypes = {
|
||||||
|
matrixServerUrl: PropTypes.string.isRequired,
|
||||||
settingsEndpoint: PropTypes.string,
|
settingsEndpoint: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ChatboxWithSettings.defaultProps = {
|
||||||
|
settingsEndpoint: null,
|
||||||
|
};
|
||||||
|
|
||||||
export default ChatboxWithSettings;
|
export default ChatboxWithSettings;
|
||||||
|
Loading…
Reference in New Issue
Block a user