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
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

+2
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 });
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 });
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

+17
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

+3-1
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

+16-2
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
}
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+
}
+2-1
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
}
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;

client/src/common/store/types/chatroom-types.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const PICK_CHANNEL_ASYNC = 'PICK_CHANNEL_ASYNC';
77
export const INSERT_MESSAGE = 'INSERT_MESSAGE';
88
export const ADD_CHANNEL = 'ADD_CHANNEL';
99
export const ADD_CHANNEL_ASYNC = 'ADD_CHANNEL_ASYNC';
10+
export const RESET_SELECTED_CHANNEL = 'RESET_SELECTED_CHANNEL';
1011
export const LOAD_NEXT_MESSAGES = 'LOAD_NEXT_MESSAGES';
1112
export const LOAD_NEXT_MESSAGES_ASYNC = 'LOAD_NEXT_MESSAGES_ASYNC';
1213

@@ -78,9 +79,20 @@ interface AddChannelAction {
7879
payload: selectedChatroomState;
7980
}
8081

82+
interface ResetSelectedChannel {
83+
type: typeof RESET_SELECTED_CHANNEL;
84+
}
85+
8186
interface LoadNextAction {
8287
type: typeof LOAD_NEXT_MESSAGES;
8388
payload: messagesState;
8489
}
8590

86-
export type ChatroomTypes = LoadChatroomAction | InitSidebarAction | PickChannelAction | InsertMessageAction | AddChannelAction | LoadNextAction;
91+
export type ChatroomTypes =
92+
| LoadChatroomAction
93+
| InitSidebarAction
94+
| PickChannelAction
95+
| InsertMessageAction
96+
| AddChannelAction
97+
| ResetSelectedChannel
98+
| LoadNextAction;

client/src/common/store/types/modal-types.ts

+22-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ export const CREATE_MODAL_OPEN = 'CREATE_MODAL_OPEN';
22
export const CREATE_MODAL_CLOSE = 'CREATE_MODAL_CLOSE';
33
export const CHANNEL_MODAL_OPEN = 'CHANNEL_MODAL_OPEN';
44
export const CHANNEL_MODAL_CLOSE = 'CHANNEL_MODAL_CLOSE';
5+
export const USERBOX_MODAL_OPEN = 'USERBOX_MODAL_OPEN';
6+
export const USERBOX_MODAL_CLOSE = 'USERBOX_MODAL_CLOSE';
57

68
export interface CreateChannelModalState {
79
isOpen: boolean;
@@ -13,9 +15,14 @@ export interface ChannelModalState {
1315
y: number;
1416
}
1517

18+
export interface UserBoxModalState {
19+
isOpen: boolean;
20+
}
21+
1622
export interface ModalState {
1723
createModal: CreateChannelModalState;
1824
channelModal: ChannelModalState;
25+
userboxModal: UserBoxModalState;
1926
}
2027

2128
interface CreateChannelModalOpenAction {
@@ -38,4 +45,18 @@ interface ChannelModalCloseAction {
3845
payload: ChannelModalState;
3946
}
4047

41-
export type ModalTypes = CreateChannelModalOpenAction | CreateChannelModalCloseAction | ChannelModalOpenAction | ChannelModalCloseAction;
48+
interface UserBoxModalOpenAction {
49+
type: typeof USERBOX_MODAL_OPEN;
50+
}
51+
52+
interface UserBoxModalCloseAction {
53+
type: typeof USERBOX_MODAL_CLOSE;
54+
}
55+
56+
export type ModalTypes =
57+
| CreateChannelModalOpenAction
58+
| CreateChannelModalCloseAction
59+
| ChannelModalOpenAction
60+
| ChannelModalCloseAction
61+
| UserBoxModalOpenAction
62+
| UserBoxModalCloseAction;

client/src/common/utils/api.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default {
5555
},
5656

5757
getNextMessages: async (chatroomId: number, offsetId: number) => {
58-
const response = await axios.get(`api/messages/${chatroomId}/${offsetId}`);
58+
const response = await axios.get(`api/messages/${chatroomId}/?offsetId=${offsetId}`);
5959
return response.data;
6060
},
6161

@@ -67,5 +67,10 @@ export default {
6767
} catch (e) {
6868
throw new Error('Channel creation failed.');
6969
}
70+
},
71+
72+
getChannels: async () => {
73+
const response = await axios.get(`api/chatrooms`);
74+
return response.data;
7075
}
7176
};

client/src/common/utils/auth.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const checkAuthToToken = () => {
2+
return !!localStorage.getItem('token');
3+
};

client/src/common/utils/blockPage.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
const checkAuthToToken = () => {
2-
return !!localStorage.getItem('token');
3-
};
1+
import { auth } from '@utils/index';
42

53
const blockPage = () => {
6-
if (checkAuthToToken() && window.location.pathname === '/login') {
4+
if (auth.checkAuthToToken() && window.location.pathname === '/login') {
75
window.location.href = '/';
86
}
9-
if (!checkAuthToToken() && window.location.pathname !== '/login') {
7+
if (!auth.checkAuthToToken() && window.location.pathname !== '/login') {
108
window.location.href = '/login';
119
}
1210
};

client/src/common/utils/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import * as uriParser from './uriParser';
33
import { blockPage } from './blockPage';
44
import registerToken from './registerToken';
55
import { logout } from './logout';
6+
import * as auth from './auth';
67

7-
export { API, uriParser, blockPage, registerToken, logout };
8+
export { API, uriParser, blockPage, registerToken, logout, auth };
+5-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { API, uriParser } from '@utils/index';
1+
import { API, uriParser, auth } from '@utils/index';
22

33
const registerToken = async () => {
4-
if (uriParser.isExistParseCode()) {
4+
if (uriParser.isExistParseCodeUrl()) {
55
const code = uriParser.getCode();
66
const token = await API.getToken(code);
77
if (token) {
88
localStorage.setItem('token', token);
9-
window.location.href = '/';
9+
window.location.href = '/client/1';
1010
}
11-
}
11+
} else if (auth.checkAuthToToken()) window.location.href = '/client/1';
12+
else window.location.href = '/login';
1213
};
1314

1415
export default registerToken;

client/src/common/utils/uriParser.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const isExistParseCode = () => {
1+
export const isExistParseCodeUrl = () => {
22
const pattern = new RegExp(/^\?code=\w+$/);
33
return pattern.test(window.location.search);
44
};
@@ -10,9 +10,19 @@ export const getCode = () => {
1010
};
1111

1212
export const getChatroomId = () => {
13-
const isChatroomUrlpattern = new RegExp(/^\/client\/[0-9]+$/);
13+
const isChatroomUrlpattern = new RegExp(/^\/client\/[0-9]+(\/thread\/[0-9]+)*$/);
1414
if (isChatroomUrlpattern.test(window.location.pathname)) {
15-
const pattern = new RegExp(/[^(/client/)]/);
15+
const pattern = new RegExp(/[0-9]+/g);
16+
const code = pattern.exec(window.location.pathname);
17+
return code ? Number(code[0]) : null;
18+
}
19+
return null;
20+
};
21+
22+
export const getThreadId = () => {
23+
const isThreadUrlpattern = new RegExp(/^\/client\/[0-9]+(\/thread\/[0-9]+)*$/);
24+
if (isThreadUrlpattern.test(window.location.pathname)) {
25+
const pattern = new RegExp(/[0-9]+$/g);
1626
const code = pattern.exec(window.location.pathname);
1727
return code ? Number(code[0]) : null;
1828
}

client/src/components/molecules/BrowsePageControls/BrowsePageControls.stories.tsx

+1-6
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@ export default {
77
component: BrowsePageControls
88
} as Meta;
99

10-
const handlingSortButton = () => {};
11-
const handlingFilterButton = () => {};
12-
1310
const Template: Story<BrowsePageControlsProps> = (args) => <BrowsePageControls {...args} />;
1411

1512
export const BlackBrowsePageControls = Template.bind({});
1613
BlackBrowsePageControls.args = {
17-
channelCount: 193,
18-
handlingSortButton,
19-
handlingFilterButton
14+
channelCount: 193
2015
};

0 commit comments

Comments
 (0)