Skip to content

Commit 0c4a1bd

Browse files
authored
Merge pull request #127 from Dataport/fix/icon-menu-initially-open-prod
Fix initiallyOpen not working in prod mode
2 parents 8ee7b71 + 993eb21 commit 0c4a1bd

File tree

9 files changed

+30
-13
lines changed

9 files changed

+30
-13
lines changed

packages/core/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## unpublished
4+
5+
- Feature: Add new state parameter `mapHasDimensions` to let plugins have a "hook" to react on when the map is ready.
6+
37
## 1.4.1
48

59
- Feature: Additionally export `PolarCore` type.

packages/core/src/utils/createMap/updateSizeOnReady.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ export const updateSizeOnReady = (instance: Vue) => {
2020
console.error(
2121
`@polar/core: The POLAR map client could not update its size. The map is probably invisible due to having 0 width or 0 height. This might be a CSS issue – please check the wrapper's size.`
2222
)
23+
instance.$store.commit('setMapHasDimensions', false)
2324
} else {
2425
// OL prints warnings – add this log to reduce confusion
2526
// eslint-disable-next-line no-console
2627
console.log(
2728
`@polar/core: The map now has dimensions and can be rendered.`
2829
)
30+
instance.$store.commit('setMapHasDimensions', true)
2931
clearInterval(intervalId)
3032
}
3133
}, 0)

packages/core/src/vuePlugins/vuex.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const getInitialState = (): CoreState => ({
7474
hasSmallDisplay: false,
7575
errors: [],
7676
language: '',
77+
mapHasDimensions: false,
7778
})
7879

7980
// OK for store creation

packages/lib/testMountParameters/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## unpublished
4+
5+
- Feature: Extend mock state to match current core state type.
6+
37
## 1.2.1
48

59
- Fix: Test now uses a mock EPSG code instead of an empty string.

packages/lib/testMountParameters/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export default (): MockParameters => {
6161
moveHandleActionButton: 0,
6262
plugin: {},
6363
language: '',
64+
mapHasDimensions: false,
6465
zoomLevel: 0,
6566
hovered: 0,
6667
selected: 0,

packages/plugins/IconMenu/src/components/IconMenu.vue

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export default Vue.extend({
6868
computed: {
6969
...mapGetters([
7070
'clientHeight',
71-
'clientWidth',
7271
'hasSmallDisplay',
7372
'hasSmallHeight',
7473
'hasSmallWidth',
@@ -97,17 +96,6 @@ export default Vue.extend({
9796
},
9897
},
9998
watch: {
100-
// The map initially has a height of 0, so initially opening a menu only works after the height has changed
101-
clientHeight(newValue: number, oldValue: number) {
102-
if (
103-
oldValue === 0 &&
104-
newValue > 0 &&
105-
!this.hasSmallHeight &&
106-
!this.hasSmallWidth
107-
) {
108-
this.openMenuById(this.initiallyOpen)
109-
}
110-
},
11199
// Fixes an issue if the orientation of a mobile device is changed while a plugin is open
112100
isHorizontal(newVal: boolean) {
113101
if (!newVal) {

packages/plugins/IconMenu/src/store/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const makeStoreModule = () => {
1818
namespaced: true,
1919
state: getInitialState(),
2020
actions: {
21-
setupModule({ commit, rootGetters }): void {
21+
setupModule({ commit, dispatch, getters, rootGetters }): void {
2222
const menus = rootGetters.configuration?.iconMenu?.menus || []
2323
const initializedMenus = menus
2424
.filter(({ id }) => {
@@ -45,6 +45,20 @@ export const makeStoreModule = () => {
4545
})
4646

4747
commit('setMenus', initializedMenus)
48+
49+
// The map initially has a height of 0, so initially opening a menu only works after the height has changed
50+
this.watch(
51+
() => rootGetters.mapHasDimensions,
52+
(value) => {
53+
if (
54+
value &&
55+
!rootGetters.hasSmallHeight &&
56+
!rootGetters.hasSmallWidth
57+
) {
58+
dispatch('openMenuById', getters.initiallyOpen)
59+
}
60+
}
61+
)
4862
},
4963
openMenuById({ commit, dispatch, getters }, openId: string) {
5064
const index = getters.menus.findIndex(({ id }) => id === openId)

packages/types/custom/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## unpublished
44

5+
- Feature: Add `mapHasDimensions` to `CoreState` and `CoreGetters`.
56
- Fix: Add `string` as option for `SearchType` since arbitrary strings can be registered.
67

78
## 1.4.1

packages/types/custom/core.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ export interface CoreState {
648648
hovered: number
649649
language: string
650650
map: number
651+
mapHasDimensions: boolean
651652
moveHandle: number
652653
moveHandleActionButton: number
653654
plugin: object
@@ -665,6 +666,7 @@ export interface CoreGetters {
665666
hovered: Feature | null
666667
errors: PolarError[]
667668
map: Map
669+
mapHasDimensions: boolean
668670
moveHandle: MoveHandleProperties
669671
moveHandleActionButton: MoveHandleActionButton
670672
selected: Feature | null

0 commit comments

Comments
 (0)