-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/1338 anchor bug fix #1339
Conversation
Can you please check if the behaviour is still correct when Do the live hash update and the Anchor plugin (both its initial value and live updating of the input in |
So I tried https://oversiktsplan-utv.varberg.se/?/enableAppStateInHash and the anchor gets set the same way as it does without the query, and the live update seems to work aswell (if you mean registering changes like moving the map, zooming etc.) |
That sound good, thanks for the test. We'll take a proper look next week! |
componentDidMount() { | ||
// We check if anchor is a string, to avoid error in render() below. | ||
// This because the getAnchor() sometimes returns a Promise instead of a string. | ||
typeof anchor === "string" && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anchor
is not defined here and won't be of type string. When i test your implementation, the view results in an empty field:
(It renders an empty field if you have the anchor plugin enabled at start).
I think this issue could be resolved with:
async componentDidMount() {
const a = await this.props.model.getAnchor();
this.setState({ anchor: a });
// Subscribe to changes to anchor URL caused by other components. This ensure
// that we have a live update of the anchor whether user does anything in the map.
this.props.globalObserver.subscribe(
"core.mapUpdated",
({ url, source }) => {
this.setState({
anchor: this.appendCleanModeIfActive(url),
});
}
);
}
Maybe you could test that and see if it works for you as well? The strange thing is that the original implementation also works for me...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I tried having the dela-window opened at start aswell, and the link does appear. But I'll try your fix :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So your codes seems to be working fine. Although, if I scroll while the page is starting the link does not appear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean it doesn't get updated?
The componentDidMount
part runs only on initial component load. The following updates of anchor string are taken care of elsewhere, please ensure to use the same methodology (await this.props.model.getAnchor()
) before calling setState()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... Seems like getAnchor
never resolves in some cases... It's not pretty but this should do the trick:
async componentDidMount() {
// Subscribe to changes to anchor URL caused by other components. This ensure
// that we have a live update of the anchor whether user does anything in the map.
this.props.globalObserver.subscribe(
"core.mapUpdated",
({ url, source }) => {
this.setState({
anchor: this.appendCleanModeIfActive(url),
});
}
);
const a = await this.props.model.getAnchor();
this.setState({ anchor: a });
}
(We have to make sure the subscription is made. If getAnchor
never resolves, the subscription is never made, and the anchor-url is never updated).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works on my end :)
This PR refers to this issue: Oversiktsplan - Url link missing from Anchor View (Dela) #1338
closes #1338