Add react-modal, replace confirm usage with it
This commit is contained in:
parent
63cf65100d
commit
0085cea5a1
17 changed files with 443 additions and 152 deletions
|
@ -19,6 +19,9 @@ export const FETCH_MESSAGES = 'FETCH_MESSAGES';
|
|||
export const RAW = 'RAW';
|
||||
export const UPDATE_MESSAGE_HEIGHT = 'UPDATE_MESSAGE_HEIGHT';
|
||||
|
||||
export const OPEN_MODAL = 'OPEN_MODAL';
|
||||
export const CLOSE_MODAL = 'CLOSE_MODAL';
|
||||
|
||||
export const CLOSE_PRIVATE_CHAT = 'CLOSE_PRIVATE_CHAT';
|
||||
export const OPEN_PRIVATE_CHAT = 'OPEN_PRIVATE_CHAT';
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import assign from 'lodash/assign';
|
||||
import createReducer from 'utils/createReducer';
|
||||
import * as actions from './actions';
|
||||
|
||||
|
@ -31,7 +30,7 @@ const initialState = {
|
|||
export default createReducer(initialState, {
|
||||
[actions.APP_SET](state, { key, value }) {
|
||||
if (typeof key === 'object') {
|
||||
assign(state, key);
|
||||
Object.assign(state, key);
|
||||
} else {
|
||||
state[key] = value;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import app from './app';
|
|||
import channels from './channels';
|
||||
import input from './input';
|
||||
import messages from './messages';
|
||||
import modals from './modals';
|
||||
import privateChats from './privateChats';
|
||||
import search from './search';
|
||||
import servers from './servers';
|
||||
|
@ -20,6 +21,7 @@ export default function createReducer(router) {
|
|||
channels,
|
||||
input,
|
||||
messages,
|
||||
modals,
|
||||
privateChats,
|
||||
search,
|
||||
servers,
|
||||
|
|
50
client/js/state/modals.js
Normal file
50
client/js/state/modals.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
import { createSelector } from 'reselect';
|
||||
import createReducer from 'utils/createReducer';
|
||||
import * as actions from './actions';
|
||||
|
||||
export const getModals = state => state.modals;
|
||||
|
||||
export const getHasOpenModals = createSelector(
|
||||
getModals,
|
||||
modals => {
|
||||
const keys = Object.keys(modals);
|
||||
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
if (modals[keys[i]].isOpen) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
export default createReducer(
|
||||
{},
|
||||
{
|
||||
[actions.OPEN_MODAL](state, { name, payload = {} }) {
|
||||
state[name] = {
|
||||
isOpen: true,
|
||||
payload
|
||||
};
|
||||
},
|
||||
|
||||
[actions.CLOSE_MODAL](state, { name }) {
|
||||
state[name].isOpen = false;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export function openModal(name, payload) {
|
||||
return {
|
||||
type: actions.OPEN_MODAL,
|
||||
name,
|
||||
payload
|
||||
};
|
||||
}
|
||||
|
||||
export function closeModal(name) {
|
||||
return {
|
||||
type: actions.CLOSE_MODAL,
|
||||
name
|
||||
};
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
import assign from 'lodash/assign';
|
||||
import createReducer from 'utils/createReducer';
|
||||
import * as actions from './actions';
|
||||
|
||||
|
@ -41,7 +40,7 @@ export default createReducer(
|
|||
|
||||
[actions.SETTINGS_SET](state, { key, value, settings }) {
|
||||
if (settings) {
|
||||
assign(state, settings);
|
||||
Object.assign(state, settings);
|
||||
} else {
|
||||
state[key] = value;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue