Skip to content

Commit 7d08876

Browse files
authored
fix: keymap navigation (#2258)
1 parent c0dca8a commit 7d08876

File tree

7 files changed

+42
-17
lines changed

7 files changed

+42
-17
lines changed

packages/uhk-web/src/app/components/keymap/edit/keymap-edit.component.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,15 @@ export class KeymapEditComponent implements OnDestroy {
9191
this.store.dispatch(new SelectLayerAction(LayerName.base));
9292
}
9393

94-
if (params.module && params.key) {
95-
this.store.dispatch(new OpenPopoverAction({
96-
moduleId: +params.module,
97-
keyId: +params.key,
98-
remapOnAllKeymap: params.remapOnAllKeymap === 'true',
99-
remapOnAllLayer: params.remapOnAllLayer === 'true'
100-
}));
101-
}
94+
const moduleId = +params.module;
95+
const keyId = +params.key;
96+
97+
this.store.dispatch(new OpenPopoverAction({
98+
moduleId: Number.isNaN(moduleId) ? undefined : moduleId,
99+
keyId: Number.isNaN(keyId) ? undefined : keyId,
100+
remapOnAllKeymap: params.remapOnAllKeymap === 'true',
101+
remapOnAllLayer: params.remapOnAllLayer === 'true'
102+
}));
102103
});
103104

104105
this.backlightingMode$ = store.select(backlightingMode);

packages/uhk-web/src/app/components/popover/popover.component.html

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
[selectedKey]="selectedKey"
4646
[defaultKeyAction]="defaultKeyAction"
4747
[macroPlaybackSupported]="macroPlaybackSupported$ | async"
48+
[remapInfo]="remapInfo"
4849
(assignNewMacro)="onAssignNewMacro()"
4950
(validAction)="setKeyActionValidState($event)"
5051
></macro-tab>

packages/uhk-web/src/app/components/popover/tab/macro/macro-tab.component.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Tab } from '../tab';
88

99
import { AppState, getMacros } from '../../../../store';
1010
import { SelectedKeyModel } from '../../../../models';
11+
import { RemapInfo } from '../../../../models/remap-info';
1112
import { SelectOptionData } from '../../../../models/select-option-data';
1213

1314
@Component({
@@ -20,6 +21,7 @@ export class MacroTabComponent extends Tab implements OnInit, OnChanges, OnDestr
2021
@Input() currentKeymap: Keymap;
2122
@Input() defaultKeyAction: KeyAction;
2223
@Input() macroPlaybackSupported: boolean;
24+
@Input() remapInfo: RemapInfo;
2325
@Input() selectedKey: SelectedKeyModel;
2426

2527
@Output() assignNewMacro = new EventEmitter<void>();
@@ -54,8 +56,14 @@ export class MacroTabComponent extends Tab implements OnInit, OnChanges, OnDestr
5456
this.validAction.emit(true);
5557

5658
if (changes.currentKeymap || changes.selectedKey) {
59+
let remapQueryParams = '';
60+
61+
if (this.remapInfo) {
62+
remapQueryParams = `&remapOnAllKeymap=${this.remapInfo.remapOnAllKeymap}&remapOnAllLayer=${this.remapInfo.remapOnAllLayer}`;
63+
}
64+
5765
this.jumpToMacroQueryParams = {
58-
backUrl: `/keymap/${this.currentKeymap.abbreviation}?layer=${this.selectedKey.layerId}&module=${this.selectedKey.moduleId}&key=${this.selectedKey.keyId}`,
66+
backUrl: `/keymap/${this.currentKeymap.abbreviation}?layer=${this.selectedKey.layerId}&module=${this.selectedKey.moduleId}&key=${this.selectedKey.keyId}${remapQueryParams}`,
5967
backText: `"${this.currentKeymap.name}" keymap`,
6068
};
6169
}

packages/uhk-web/src/app/components/side-menu/side-menu.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@
177177
<ul [@toggler]="this.sideMenuState.keymap.animation">
178178
<li *ngFor="let keymap of state.keymaps" class="sidebar__level-2--item">
179179
<div class="sidebar__level-2" [routerLinkActive]="['active']">
180-
<a [routerLink]="['/keymap', keymap.abbreviation]" [queryParamsHandling]="state.keymapQueryParamsHandling"
180+
<a [routerLink]="['/keymap', keymap.abbreviation]" [queryParams]="state.keymapQueryParams"
181181
[class.disabled]="state.updatingFirmware">{{keymap.name}}</a>
182182
<fa-icon *ngIf="keymap.isDefault"
183183
[icon]="faStar"

packages/uhk-web/src/app/models/side-menu-page-state.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { QueryParamsHandling } from '@angular/router';
1+
import { Params } from '@angular/router';
22
import { Keymap, UhkDeviceProduct } from 'uhk-common';
33

44
import { MacroMenuItem } from './macro-menu-item';
@@ -10,7 +10,7 @@ export interface SideMenuPageState {
1010
updatingFirmware: boolean;
1111
deviceName: string;
1212
keymaps: Keymap[];
13-
keymapQueryParamsHandling: QueryParamsHandling;
13+
keymapQueryParams: Params;
1414
macros: MacroMenuItem[];
1515
maxMacroCountReached: boolean;
1616
restoreUserConfiguration: boolean;

packages/uhk-web/src/app/store/index.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ export const getSideMenuPageState = createSelector(
474474
calculateDeviceUiState,
475475
getConnectedDevice,
476476
getIsAdvancedSettingsMenuVisible,
477-
getRouterState,
477+
getSelectedLayerOption,
478478
(
479479
runningInElectronValue: boolean,
480480
updatingFirmwareValue: boolean,
@@ -483,7 +483,7 @@ export const getSideMenuPageState = createSelector(
483483
uiState,
484484
connectedDevice,
485485
isAdvancedSettingsMenuVisible,
486-
routerState
486+
selectedLayerOption
487487
): SideMenuPageState => {
488488
const macros = getMacroMenuItems(userConfiguration);
489489

@@ -494,7 +494,9 @@ export const getSideMenuPageState = createSelector(
494494
updatingFirmware: updatingFirmwareValue,
495495
deviceName: userConfiguration.deviceName,
496496
keymaps: userConfiguration.keymaps,
497-
keymapQueryParamsHandling: routerState?.state?.url?.startsWith('/keymap') ? 'merge' : '',
497+
keymapQueryParams: {
498+
layer: selectedLayerOption.id
499+
},
498500
macros,
499501
maxMacroCountReached: macros.length >= Constants.MAX_ALLOWED_MACROS,
500502
restoreUserConfiguration,

packages/uhk-web/src/app/store/reducers/user-configuration.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -891,12 +891,25 @@ export function reducer(
891891
return newState;
892892
}
893893

894-
case KeymapActions.ActionTypes.SelectLayer:
894+
case KeymapActions.ActionTypes.SelectLayer: {
895+
let selectedLayer = (action as KeymapActions.SelectLayerAction).payload;
896+
897+
if (selectedLayer === state.selectedLayerOption.id) {
898+
return state;
899+
}
900+
901+
const currentLayerOption = state.layerOptions.get(selectedLayer);
902+
903+
if (!currentLayerOption.selected) {
904+
selectedLayer = LayerName.base;
905+
}
906+
895907
return {
896908
...state,
897-
selectedLayerOption: state.layerOptions.get((action as KeymapActions.SelectLayerAction).payload),
909+
selectedLayerOption: state.layerOptions.get(selectedLayer),
898910
openedPopover: undefined,
899911
};
912+
}
900913

901914
case KeymapActions.ActionTypes.OpenPopover:
902915
return {

0 commit comments

Comments
 (0)