Skip to content

Commit

Permalink
Fix routing and make linking macros
Browse files Browse the repository at this point in the history
  • Loading branch information
cherry-john committed Jun 29, 2022
1 parent bd4d1a0 commit 39f31ce
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
8 changes: 7 additions & 1 deletion src/api/preset/presetRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ export const presetRouter = (
e131.convertObjectToChannelData(value.data),
value.fadeTime * 1000
)
resolve({})
} else if (value.type === 'osc' && value.data !== null) {
Object.entries(value.data).forEach(presetData => {
osc.send(presetData)
})
resolve({})
} else if (value.type === 'http' && value.data !== null) {
// Make the HTTP request
axios({
Expand All @@ -42,15 +44,19 @@ export const presetRouter = (
}).catch(err => {
logger.info('Preset HTTP request failed', { err })
})
resolve({})
} else if (value.type === 'macro' && value.data !== null) {
value.data.forEach((step: { type: string; value: string; key: string }) => {
logger.info(step)
if (step.type === 'preset' && parseInt(step.value) !== value.id) {
// Trigger the presets in the macro
presetRouter(['recall', step.value], 'GET', {})
resolve({})
} else if (step.type === 'link') {
resolve({ redirect: step.value })
}
})
}
resolve({})
})
} else if (method === 'PUT') {
return PresetRepository.setAllFromApp(payload as Array<DatabasePreset>)
Expand Down
12 changes: 11 additions & 1 deletion src/app/Components/Admin/Controls/Presets/EditModal/Macro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ export const MacroPresetEditModal = (props: GetInputProps<'input'>) => {
<Group key={item.key} mt="xs">
<Select
{...form.getListInputProps('steps', index, 'type')}
data={[{ value: 'preset', label: 'Trigger Preset' }]}
data={[
{ value: 'preset', label: 'Trigger Preset' },
{ value: 'link', label: 'Open a Page' },
]}
/>
{form.values.steps[index].type === 'preset' ? (
<Select
Expand All @@ -61,6 +64,13 @@ export const MacroPresetEditModal = (props: GetInputProps<'input'>) => {
data={presetsForSelect}
/>
) : null}
{form.values.steps[index].type === 'link' ? (
<Select
placeholder="Page"
{...form.getListInputProps('steps', index, 'value')}
data={[{ value: '/controlPanel/lxKeypad', label: 'Lighting Keypad' }]}
/>
) : null}
<ActionIcon color="red" variant="hover" onClick={() => form.removeListItem('steps', index)}>
<FaTrash />
</ActionIcon>
Expand Down
1 change: 0 additions & 1 deletion src/app/Navigation/ControlPanelNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export const ControlPanelNavigation = () => {
<TopLevelPresetFolders active={active} setActive={setActive} />
</Navbar.Section>
<Navbar.Section className={classes.footer}>
<NavbarItem link="utilities" label="Utilities" Icon={FaCogs} active={active} setActive={setActive} />
<NavbarItem link="help" label="Help" Icon={FaQuestion} active={active} setActive={setActive} />
</Navbar.Section>
</Navbar>
Expand Down
26 changes: 12 additions & 14 deletions src/app/Pages/ControlPanel/Keypad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const KeypadPage = () => {
* @returns True if the command array is valid, false otherwise
*/
function validCommand(command: string[]) {
console.log(command)
if (
command.length === 0 ||
command.length > 3 ||
Expand Down Expand Up @@ -76,100 +75,99 @@ export const KeypadPage = () => {

return (
<Container>
<Space h="xl" />
<TextInput disabled aria-label="Command Output" size="xl" value={commandText} />
<Space h="xl" />
<SimpleGrid cols={3}>
<Button
size="xl"
size="lg"
onClick={() => {
updateCommandString('7')
}}
>
7
</Button>
<Button
size="xl"
size="lg"
onClick={() => {
updateCommandString('8')
}}
>
8
</Button>
<Button
size="xl"
size="lg"
onClick={() => {
updateCommandString('9')
}}
>
9
</Button>
<Button
size="xl"
size="lg"
onClick={() => {
updateCommandString('4')
}}
>
4
</Button>
<Button
size="xl"
size="lg"
onClick={() => {
updateCommandString('5')
}}
>
5
</Button>
<Button
size="xl"
size="lg"
onClick={() => {
updateCommandString('6')
}}
>
6
</Button>
<Button
size="xl"
size="lg"
onClick={() => {
updateCommandString('1')
}}
>
1
</Button>
<Button
size="xl"
size="lg"
onClick={() => {
updateCommandString('2')
}}
>
2
</Button>
<Button
size="xl"
size="lg"
onClick={() => {
updateCommandString('3')
}}
>
3
</Button>
<Button
size="xl"
size="lg"
onClick={() => {
updateCommandString('clear')
}}
>
Clear
</Button>
<Button
size="xl"
size="lg"
onClick={() => {
updateCommandString('0')
}}
>
0
</Button>
<Button
size="xl"
size="lg"
onClick={() => {
updateCommandString(' thru ')
}}
Expand Down
10 changes: 8 additions & 2 deletions src/app/Pages/ControlPanel/Preset.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { Link, useParams } from 'react-router-dom'
import { Link, useNavigate, useParams } from 'react-router-dom'
import { DatabasePresetFolder } from './../../../database/repository/presetFolder'
import { Button, Paper } from '@mantine/core'
import { FaLevelUpAlt } from '@react-icons/all-files/fa/FaLevelUpAlt'
Expand All @@ -9,6 +9,8 @@ import { useAppSelector } from './../../apis/redux/mainStore'
import { ApiCall } from './../../apis/wrapper'
import { PresetFolderIconReact } from './../../Components/ControlPanel/PresetFolderIcon'
const PresetButton = ({ text, presetId, color }: { text: string; presetId: number; color: string }) => {
const navigate = useNavigate()

return (
<Button
variant="default"
Expand All @@ -18,7 +20,11 @@ const PresetButton = ({ text, presetId, color }: { text: string; presetId: numbe
color: pickTextColorBasedOnBgColor(color),
})}
onClick={() => {
ApiCall.get('/presets/recall/' + presetId, {})
ApiCall.get('/presets/recall/' + presetId, {}).then(function (value) {
if (value.redirect) {
navigate(value.redirect)
}
})
}}
size="xl"
mx="xs"
Expand Down
17 changes: 0 additions & 17 deletions src/app/Pages/ControlPanel/Utilities.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions src/app/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { FadersConfigurationPage } from './Pages/Admin/Faders'
import { ControlsConfigurationPage } from './Pages/Admin/Controls'
import { Locked } from './Components/Locked'
import { KeypadPage } from './Pages/ControlPanel/Keypad'
import { UtilitiesPage } from './Pages/ControlPanel/Utilities'

const Router = () => {
return (
Expand All @@ -30,7 +29,6 @@ const Router = () => {
>
<Route path="presetFolder/:folderId" element={<PresetPage />} />
<Route path="help" element={<HelpPage />} />
<Route path="utilities" element={<UtilitiesPage />} />
<Route path="lxkeypad" element={<KeypadPage />} />
</Route>
<Route path="e131sampler" element={<div>Sampling E1.31</div>} />
Expand Down

0 comments on commit 39f31ce

Please sign in to comment.