Skip to content

Commit 8fcf83a

Browse files
authored
Merge pull request #179 from boostcamp-2020/develop
4주차 배포 수정
2 parents e18f097 + f4512b5 commit 8fcf83a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+660
-130
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { INIT_CHANNELS_ASYNC } from '../types/channel-types';
2+
3+
export const initChannels = () => ({ type: INIT_CHANNELS_ASYNC });

client/src/common/store/actions/chatroom-action.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
PICK_CHANNEL_ASYNC,
55
INSERT_MESSAGE,
66
ADD_CHANNEL_ASYNC,
7+
RESET_SELECTED_CHANNEL,
78
LOAD_NEXT_MESSAGES_ASYNC
89
} from '../types/chatroom-types';
910

@@ -12,4 +13,5 @@ export const initSidebarAsync = () => ({ type: INIT_SIDEBAR_ASYNC });
1213
export const pickChannel = (payload: any) => ({ type: PICK_CHANNEL_ASYNC, payload });
1314
export const insertMessage = (payload: any) => ({ type: INSERT_MESSAGE, payload });
1415
export const addChannel = (payload: any) => ({ type: ADD_CHANNEL_ASYNC, payload });
16+
export const resetSelectedChannel = () => ({ type: RESET_SELECTED_CHANNEL });
1517
export const loadNextMessages = (payload: any) => ({ type: LOAD_NEXT_MESSAGES_ASYNC, payload });
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
import { CREATE_MODAL_OPEN, CREATE_MODAL_CLOSE, CHANNEL_MODAL_OPEN, CHANNEL_MODAL_CLOSE } from '@store/types/modal-types';
1+
import {
2+
CREATE_MODAL_OPEN,
3+
CREATE_MODAL_CLOSE,
4+
CHANNEL_MODAL_OPEN,
5+
CHANNEL_MODAL_CLOSE,
6+
USERBOX_MODAL_OPEN,
7+
USERBOX_MODAL_CLOSE
8+
} from '@store/types/modal-types';
29

310
export const createModalOpen = () => ({ type: CREATE_MODAL_OPEN });
411
export const createModalClose = () => ({ type: CREATE_MODAL_CLOSE });
512
export const channelModalOpen = (payload: any) => ({ type: CHANNEL_MODAL_OPEN, payload });
613
export const channelModalClose = () => ({ type: CHANNEL_MODAL_CLOSE });
14+
export const userboxModalOpen = () => ({ type: USERBOX_MODAL_OPEN });
15+
export const userboxModalClose = () => ({ type: USERBOX_MODAL_CLOSE });
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { channelsState, ChannelTypes, INIT_CHANNELS } from '../types/channel-types';
2+
3+
const initialState: channelsState = {
4+
channelCount: 0,
5+
channels: []
6+
};
7+
8+
export default function channelReducer(state = initialState, action: ChannelTypes) {
9+
switch (action.type) {
10+
case INIT_CHANNELS:
11+
return {
12+
channelCount: action.payload.channelCount,
13+
channels: action.payload.channels
14+
};
15+
default:
16+
return state;
17+
}
18+
}

client/src/common/store/reducers/chatroom-reducer.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
INIT_SIDEBAR,
99
INSERT_MESSAGE,
1010
ADD_CHANNEL,
11+
RESET_SELECTED_CHANNEL,
1112
LOAD_NEXT_MESSAGES
1213
} from '../types/chatroom-types';
1314

@@ -66,6 +67,22 @@ export default function chatroomReducer(state = initialState, action: ChatroomTy
6667
...state,
6768
channels: newChannels
6869
};
70+
case RESET_SELECTED_CHANNEL:
71+
const selectedChatroom = {
72+
chatType: '',
73+
description: '',
74+
isPrivate: false,
75+
title: '',
76+
topic: '',
77+
userCount: 0,
78+
users: []
79+
};
80+
return {
81+
...state,
82+
selectedChatroom,
83+
selectedChatroomId: null,
84+
messages: []
85+
};
6986
case LOAD_NEXT_MESSAGES:
7087
const nextMessages = action.payload.messages;
7188
nextMessages.push(...state.messages);

client/src/common/store/reducers/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import { combineReducers } from 'redux';
22
import userReducer from './user-reducer';
33
import chatroomReducer from './chatroom-reducer';
44
import modalReducer from './modal-reducer';
5+
import channelReducer from './channel-reducer';
56

67
export const rootReducer = combineReducers({
78
user: userReducer,
89
chatroom: chatroomReducer,
9-
modal: modalReducer
10+
modal: modalReducer,
11+
channel: channelReducer
1012
});
1113

1214
export type RootState = ReturnType<typeof rootReducer>;

client/src/common/store/reducers/modal-reducer.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
import { ModalState, ModalTypes, CREATE_MODAL_OPEN, CREATE_MODAL_CLOSE, CHANNEL_MODAL_OPEN, CHANNEL_MODAL_CLOSE } from '@store/types/modal-types';
1+
import {
2+
ModalState,
3+
ModalTypes,
4+
CREATE_MODAL_OPEN,
5+
CREATE_MODAL_CLOSE,
6+
CHANNEL_MODAL_OPEN,
7+
CHANNEL_MODAL_CLOSE,
8+
USERBOX_MODAL_OPEN,
9+
USERBOX_MODAL_CLOSE
10+
} from '@store/types/modal-types';
211

312
const initialState: ModalState = {
413
createModal: { isOpen: false },
5-
channelModal: { isOpen: false, x: 0, y: 0 }
14+
channelModal: { isOpen: false, x: 0, y: 0 },
15+
userboxModal: { isOpen: false }
616
};
717

818
const ModalReducer = (state = initialState, action: ModalTypes) => {
@@ -15,6 +25,10 @@ const ModalReducer = (state = initialState, action: ModalTypes) => {
1525
return { ...state, channelModal: { isOpen: true, x: action.payload.x, y: action.payload.y } };
1626
case CHANNEL_MODAL_CLOSE:
1727
return { ...state, channelModal: { isOpen: false } };
28+
case USERBOX_MODAL_OPEN:
29+
return { ...state, userboxModal: { isOpen: true } };
30+
case USERBOX_MODAL_CLOSE:
31+
return { ...state, userboxModal: { isOpen: false } };
1832
default:
1933
return state;
2034
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { call, put, takeEvery } from 'redux-saga/effects';
2+
import API from '@utils/api';
3+
import { INIT_CHANNELS, INIT_CHANNELS_ASYNC } from '../types/channel-types';
4+
5+
function* initChannelsSaga() {
6+
try {
7+
const channelCount = 0;
8+
const channels = yield call(API.getChannels);
9+
yield put({ type: INIT_CHANNELS, payload: { channelCount, channels } });
10+
} catch (e) {
11+
console.log(e);
12+
}
13+
}
14+
15+
export function* channelSaga() {
16+
yield takeEvery(INIT_CHANNELS_ASYNC, initChannelsSaga);
17+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { all } from 'redux-saga/effects';
22
import { chatroomSaga } from './chatroom-saga';
33
import { userSaga } from './user-saga';
4+
import { channelSaga } from './channel-saga';
45

56
export function* rootSaga() {
6-
yield all([chatroomSaga(), userSaga()]);
7+
yield all([chatroomSaga(), userSaga(), channelSaga()]);
78
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export const INIT_CHANNELS = 'INIT_CHANNELS';
2+
export const INIT_CHANNELS_ASYNC = 'INIT_CHANNELS_ASYNC';
3+
4+
export interface channelState {
5+
channelId: number;
6+
title: string;
7+
description: string;
8+
isPrivate: boolean;
9+
members: number;
10+
isJoined: boolean;
11+
}
12+
13+
export interface channelsState {
14+
channelCount: number;
15+
channels: Array<channelState>;
16+
}
17+
18+
interface InitChannelsAction {
19+
type: typeof INIT_CHANNELS;
20+
payload: channelsState;
21+
}
22+
23+
export type ChannelTypes = InitChannelsAction;

0 commit comments

Comments
 (0)