add scrolling to the comment if there is any id in url
e.g. https://demo.remark42.com/web/#remark__comment-3669787380
This commit is contained in:
@@ -23,6 +23,7 @@ export default class Root extends Component {
|
||||
this.addComment = this.addComment.bind(this);
|
||||
this.onSignIn = this.onSignIn.bind(this);
|
||||
this.onSignOut = this.onSignOut.bind(this);
|
||||
this.checkUrlHash = this.checkUrlHash.bind(this);
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
@@ -36,10 +37,14 @@ export default class Root extends Component {
|
||||
.finally(() => {
|
||||
api.find({ url })
|
||||
.then(({ comments } = {}) => store.set('comments', comments))
|
||||
.finally(() => this.setState({
|
||||
loaded: true,
|
||||
user: store.get('user'),
|
||||
}));
|
||||
.finally(() => {
|
||||
this.setState({
|
||||
loaded: true,
|
||||
user: store.get('user'),
|
||||
});
|
||||
|
||||
setTimeout(this.checkUrlHash);
|
||||
});
|
||||
|
||||
api.getConfig().then(config => {
|
||||
store.set('config', config);
|
||||
@@ -48,6 +53,19 @@ export default class Root extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
checkUrlHash() {
|
||||
if (window.parent.location.hash.indexOf('#remark__comment-') === 0) {
|
||||
const comment = document.querySelector(window.parent.location.hash);
|
||||
|
||||
if (comment) {
|
||||
setTimeout(() => {
|
||||
comment.scrollIntoView();
|
||||
window.scrollTo(window.scrollX, 0); // sometimes smth goes wrong and iframe scrolls; we return it here
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onSignOut() {
|
||||
api.logOut().then(() => {
|
||||
store.set('user', {});
|
||||
|
||||
Reference in New Issue
Block a user