Skip to content

Commit

Permalink
Set correct default in multi mapping, disables selection on non selec…
Browse files Browse the repository at this point in the history
…table actions
  • Loading branch information
Pelsin authored and bsstephan committed Mar 9, 2024
1 parent f5bd417 commit f6f64f6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
4 changes: 2 additions & 2 deletions www/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ app.get('/api/getCustomTheme', (req, res) => {
app.get('/api/getPinMappingsV2', (req, res) => {
return res.send(
Object.entries(picoController).reduce(
(acc, [key]) => ({
(acc, [key, value]) => ({
...acc,
[key]: { action: 0, customButtonMask: 0, customDpadMask: 0 },
[key]: { action: value, customButtonMask: 0, customDpadMask: 0 },
}),
{},
),
Expand Down
2 changes: 1 addition & 1 deletion www/src/Data/Controllers.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"pin26": -10,
"pin27": -10,
"pin28": -10,
"pin29": -10
"pin29": -5
}
}
5 changes: 5 additions & 0 deletions www/src/Locales/en/MultiMapping.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export default {
'header-text': 'Multi Mapping',
placeholder: `Select Option(s)`,
actions: {
RESERVED: 'Reserved',
ASSIGNED_TO_ADDON: 'Assigned to addon',
BUTTON_PRESS_TURBO: 'Assigned to turbo',
},
};
22 changes: 21 additions & 1 deletion www/src/Pages/MultiMappingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ import Section from '../Components/Section';
import { BUTTON_MASKS, DPAD_MASKS, getButtonLabels } from '../Data/Buttons';
import useMultiPinStore, { MaskPayload } from '../Store/useMultiPinStore';
import usePinStore from '../Store/usePinStore';
import {
NON_SELECTABLE_BUTTON_ACTIONS,
BUTTON_ACTIONS,
PinActionValues,
} from '../Data/Pins';
import invert from 'lodash/invert';

const isNonSelectable = (value: PinActionValues) =>
NON_SELECTABLE_BUTTON_ACTIONS.filter(
(action) => action !== BUTTON_ACTIONS.CUSTOM_BUTTON_COMBO,
).includes(value);

const MASK_OPTIONS = [
...BUTTON_MASKS.map((mask) => ({ ...mask, type: 'customButtonMask' })),
Expand Down Expand Up @@ -82,7 +93,16 @@ export default function MultiMappingPage() {
isClearable
isSearchable
options={MASK_OPTIONS}
placeholder={t('MultiMapping:placeholder')}
placeholder={
isNonSelectable(pinValue.action)
? t(
`MultiMapping:actions.${
invert(BUTTON_ACTIONS)[pinValue.action]
}`,
)
: t('MultiMapping:placeholder')
}
isDisabled={isNonSelectable(pinValue.action)}
value={MASK_OPTIONS.filter(
({ value, type }) =>
(pinValue.customButtonMask & value &&
Expand Down
2 changes: 1 addition & 1 deletion www/src/Pages/PinMapping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type PinCell = [string, PinActionValues];
type PinRow = [PinCell, PinCell];
type PinList = [PinRow];

const isNonSelectable = (value) =>
const isNonSelectable = (value: PinActionValues) =>
NON_SELECTABLE_BUTTON_ACTIONS.includes(value);

const options = Object.entries(BUTTON_ACTIONS)
Expand Down
8 changes: 4 additions & 4 deletions www/src/Store/useMultiPinStore.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { create } from 'zustand';

import WebApi from '../Services/WebApi';
import { BUTTON_ACTIONS } from '../Data/Pins';
import { BUTTON_ACTIONS, PinActionValues } from '../Data/Pins';

type CustomMasks = {
customButtonMask: number;
customDpadMask: number;
};
export type MaskPayload = {
action: number;
action: PinActionValues;
} & CustomMasks;

type State = {
Expand All @@ -25,7 +25,7 @@ type Actions = {
savePins: () => Promise<object>;
};
const DEFAULT_MASKS_STATE = {
action: 0,
action: BUTTON_ACTIONS.NONE,
customButtonMask: 0,
customDpadMask: 0,
};
Expand Down Expand Up @@ -85,7 +85,7 @@ const useMultiPinStore = create<State & Actions>()((set, get) => ({
action:
customButtonMask || customDpadMask
? BUTTON_ACTIONS.CUSTOM_BUTTON_COMBO
: 0,
: BUTTON_ACTIONS.NONE,
customButtonMask,
customDpadMask: customDpadMask,
},
Expand Down

0 comments on commit f6f64f6

Please sign in to comment.