Skip to content

Commit

Permalink
feat: custom pages menu - set number of custom pages in Settings menu
Browse files Browse the repository at this point in the history
  • Loading branch information
olzzon authored and olzzon committed Oct 22, 2020
1 parent 3bf4d60 commit 2167faa
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
6 changes: 1 addition & 5 deletions client/components/Channels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Channels extends React.Component<IChannelsInjectProps & Store> {
this.props.faders.length !== nextProps.faders.length ||
this.props.settings.currentPage !==
nextProps.settings.currentPage ||
this.props.settings.pageLength !== nextProps.settings.pageLength ||
this.props.settings.numberOfCustomPages !== nextProps.settings.numberOfCustomPages ||
!!nextProps.faders.find(
(f, i) =>
this.props.faders[i].ignoreAutomation !== f.ignoreAutomation
Expand Down Expand Up @@ -98,10 +98,6 @@ class Channels extends React.Component<IChannelsInjectProps & Store> {
handlePages(type: PageType, i: number | string) {
if (typeof i === 'string') {
this.props.dispatch(storeSetPage(type, i))
} else {
this.props.dispatch(
storeSetPage(type, i * this.props.settings.pageLength)
)
}
}

Expand Down
6 changes: 3 additions & 3 deletions client/components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,11 @@ class Settings extends React.PureComponent<IAppProps & Store, IState> {
</label>
<br />
<label className="settings-input-field">
PAGE LENGTH:
NUMBER OF CUSTOM PAGES:
<input
name="pageLength"
name="numberOfCustomPages"
type="text"
value={this.state.settings.pageLength}
value={this.state.settings.numberOfCustomPages}
onChange={this.handleChange}
/>
</label>
Expand Down
29 changes: 28 additions & 1 deletion server/MainThreadHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ import {
} from './reducers/channelActions'
import { IChannel } from './reducers/channelsReducer'
import { logger } from './utils/logger'
import { ICustomPages } from './reducers/settingsReducer'
const path = require('path')

export class MainThreadHandlers {
Expand Down Expand Up @@ -204,7 +205,33 @@ export class MainThreadHandlers {
})
.on(SOCKET_GET_PAGES_LIST, () => {
logger.info('Get custom pages list', {})
socketServer.emit(SOCKET_RETURN_PAGES_LIST, getCustomPages())
let customPages: ICustomPages[] = getCustomPages()
if (
customPages.length === state.settings[0].numberOfCustomPages
) {
socketServer.emit(SOCKET_RETURN_PAGES_LIST, customPages)
} else {
for (
let i = 0;
i < state.settings[0].numberOfCustomPages;
i++
) {
if (!customPages[i]) {
customPages.push({
id: 'custom' + String(i),
label: 'Custom ' + String(i),
faders: [],
})
}
}
socketServer.emit(
SOCKET_RETURN_PAGES_LIST,
customPages.slice(
0,
state.settings[0].numberOfCustomPages
)
)
}
})
.on(SOCKET_SET_PAGES_LIST, (payload: any) => {
saveCustomPages(payload)
Expand Down
4 changes: 2 additions & 2 deletions server/reducers/settingsReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface ISettings {
offtubeMode: boolean
showPfl: boolean
enablePages: boolean
pageLength: number
numberOfCustomPages: number
chanStripFollowsPFL: boolean

/** Connection state */
Expand Down Expand Up @@ -121,7 +121,7 @@ const defaultSettingsReducerState: Array<ISettings> = [
voFadeTime: 280,
showPfl: false,
enablePages: true,
pageLength: 16,
numberOfCustomPages: 16,
chanStripFollowsPFL: true,
serverOnline: true,
},
Expand Down
5 changes: 3 additions & 2 deletions server/utils/SettingsStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { storeSetCompleteFaderState } from '../reducers/faderActions'
import { logger } from './logger'
import { InumberOfChannels } from '../reducers/channelsReducer'
import { IFaders } from '../reducers/fadersReducer'
import { ICustomPages } from '../reducers/settingsReducer'

export const loadSettings = (storeRedux: any) => {
let settingsInterface = storeRedux.settings[0]
Expand Down Expand Up @@ -181,14 +182,14 @@ export const setCcgDefault = (fileName: string) => {
})
}

export const getCustomPages = (): object | undefined => {
export const getCustomPages = (): ICustomPages[] => {
try {
return JSON.parse(
fs.readFileSync(path.resolve('storage', 'pages.json'))
)
} catch (error) {
logger.error('Couldn´t read pages.json file', {})
return
return []
}
}

Expand Down
6 changes: 5 additions & 1 deletion storage/pages.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[
{ "id": "example", "label": "LIVE", "faders": [2, 3] },
{
"id": "example",
"label": "LIVE",
"faders": [0, 2, 3, 4, 8, 13, 14, 15, 31]
},
{ "id": "studio", "label": "STUDIO", "faders": [0, 1, 4, 5, 9, 11] }
]

0 comments on commit 2167faa

Please sign in to comment.