Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function emitterTabsReducer(state: Tabs = initialState, action: EmitterTabsActions.All) {
switch (action.type) {
case EmitterTabsActions.ADD:
return push(state, 'tabs', {index: state.tabs.length, name: action.payload.name, emitName: '', emitBody: {}});
case EmitterTabsActions.REMOVE:
return splice(state, 'tabs', action.payload.index, 1);
case EmitterTabsActions.SELECT_TAB:
return set(state, 'selectedTabIndex', action.payload.index);
case EmitterTabsActions.CHANGE_EMIT_NAME:
return set(state, `tabs[${action.payload.tabIndex}].emitName`, action.payload.name);
case EmitterTabsActions.CHANGE_EMIT_BODY:
return set(state, `tabs[${action.payload.tabIndex}].emitBody`, action.payload.body);
case EmitterTabsActions.REMOVE_ALL:
return cloneDeep(initialState);
case EmitterTabsActions.CHANGE_STATE:
return cloneDeep(action.payload);
default:
return state;
}
}
}
export function socketAppReducer(state: SocketApp = initialState, action: SocketAppActions.All) {
switch (action.type) {
case SocketAppActions.SET_CONNECT_URL:
return set(state, 'connectUrl', action.payload.connectUrl);
case SocketAppActions.REMOVE_CONNECT_URL:
return set(state, 'connectUrl', '');
default:
return state;
}
}
}
export function emitterTabsReducer(state: Tabs = initialState, action: EmitterTabsActions.All) {
switch (action.type) {
case EmitterTabsActions.ADD:
return push(state, 'tabs', {index: state.tabs.length, name: action.payload.name, emitName: '', emitBody: {}});
case EmitterTabsActions.REMOVE:
return splice(state, 'tabs', action.payload.index, 1);
case EmitterTabsActions.SELECT_TAB:
return set(state, 'selectedTabIndex', action.payload.index);
case EmitterTabsActions.CHANGE_EMIT_NAME:
return set(state, `tabs[${action.payload.tabIndex}].emitName`, action.payload.name);
case EmitterTabsActions.CHANGE_EMIT_BODY:
return set(state, `tabs[${action.payload.tabIndex}].emitBody`, action.payload.body);
case EmitterTabsActions.REMOVE_ALL:
return cloneDeep(initialState);
case EmitterTabsActions.CHANGE_STATE:
return cloneDeep(action.payload);
default:
return state;
}
}
}
export function emitterTabsReducer(state: Tabs = initialState, action: EmitterTabsActions.All) {
switch (action.type) {
case EmitterTabsActions.ADD:
return push(state, 'tabs', {index: state.tabs.length, name: action.payload.name, emitName: '', emitBody: {}});
case EmitterTabsActions.REMOVE:
return splice(state, 'tabs', action.payload.index, 1);
case EmitterTabsActions.SELECT_TAB:
return set(state, 'selectedTabIndex', action.payload.index);
case EmitterTabsActions.CHANGE_EMIT_NAME:
return set(state, `tabs[${action.payload.tabIndex}].emitName`, action.payload.name);
case EmitterTabsActions.CHANGE_EMIT_BODY:
return set(state, `tabs[${action.payload.tabIndex}].emitBody`, action.payload.body);
case EmitterTabsActions.REMOVE_ALL:
return cloneDeep(initialState);
case EmitterTabsActions.CHANGE_STATE:
return cloneDeep(action.payload);
default:
return state;
}
}
}
export const updateSpeakerToTalk = async (action, store) => {
const { uid, talkId } = action.payload
const talk = store.data.talks.get(talkId)
if (talk) {
let updated
if (action.type === '@@ui/ADD_SPEAKER_TO_TALK') {
updated = set(talk, `speakers.${uid}`, true)
} else if (action.type === '@@ui/REMOVE_SPEAKER_TO_TALK') {
updated = unset(talk, `speakers.${uid}`)
}
if (updated && Object.keys(updated.speakers).length > 0) {
await talkCrud.update(updated)
store.data.talks.update(updated)
}
}
}
function generateWeeksForMonth(date) {
const startDay = getDay(startOfMonth(date))
const weeks = chunk(
[...Array(startDay).fill(null), ...range(getDaysInMonth(date)).map(add(1))],
7,
)
const lastWeek = weeks[weeks.length - 1]
const fillOffset = 7 - lastWeek.length
return set(weeks, weeks.length - 1, [...lastWeek, ...Array(fillOffset).fill(null)])
}
export function progressBarReducer(state: ProgressBarState = initialState, action: ProgressBarActions.All) {
switch (action.type) {
case ProgressBarActions.SHOW:
return set(state, 'show', true);
case ProgressBarActions.HIDE:
return set(state, 'show', false);
default:
return state;
}
}
}
export const reducer = (state = initialState, action) => {
switch (action.type) {
case LOGIN_ERROR:
return set(state, 'error', action.error)
default:
return state
}
}
const search = (state = initialState, action) => {
switch (action.type) {
case types.SEARCH:
const filtered = new Fuse(state.questions, fuseOptions)
.search(action.text)
.filter(q => q.score < fuseOptions.threshold)
return set(state, 'filtered', filtered)
case types.CLEAR_SEARCH:
return set(state, 'filtered', [])
default:
return state
}
}