From a176ad5dc6d1c387ec3ecd432d7389ee86864aa6 Mon Sep 17 00:00:00 2001 From: oereo Date: Mon, 5 Sep 2022 22:56:14 +0900 Subject: [PATCH 01/10] =?UTF-8?q?feat:=20redux=20action=20types=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/_actions/types.ts | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/_actions/types.ts diff --git a/src/_actions/types.ts b/src/_actions/types.ts new file mode 100644 index 0000000..585040d --- /dev/null +++ b/src/_actions/types.ts @@ -0,0 +1,4 @@ +export const NEW_CHAT_ROOM = "new_chat_room"; +export const LEAVE_CHAT_ROOM = "leave_chat_room"; +export const SEND_MESSAGE = "send_message"; +export const RECEIVE_MESSAGE = "receive_message"; \ No newline at end of file From ccc1f6971a408fe7d81f29145b7b98b2fbb7ea4a Mon Sep 17 00:00:00 2001 From: oereo Date: Tue, 6 Sep 2022 14:04:18 +0900 Subject: [PATCH 02/10] =?UTF-8?q?feat:=20redux=20action=20types=EC=97=90?= =?UTF-8?q?=20type=20=ED=91=9C=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/_actions/types.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/_actions/types.ts b/src/_actions/types.ts index 585040d..aa888e0 100644 --- a/src/_actions/types.ts +++ b/src/_actions/types.ts @@ -1,4 +1,4 @@ -export const NEW_CHAT_ROOM = "new_chat_room"; -export const LEAVE_CHAT_ROOM = "leave_chat_room"; -export const SEND_MESSAGE = "send_message"; -export const RECEIVE_MESSAGE = "receive_message"; \ No newline at end of file +export const NEW_CHAT_ROOM = "new_chat_room" as const; +export const LEAVE_CHAT_ROOM = "leave_chat_room" as const; +export const SEND_MESSAGE = "send_message" as const; +export const RECEIVE_MESSAGE = "receive_message" as const; \ No newline at end of file From 92e5606c4571e85f69444bdc83a72dd5681ae607 Mon Sep 17 00:00:00 2001 From: oereo Date: Tue, 6 Sep 2022 14:15:53 +0900 Subject: [PATCH 03/10] =?UTF-8?q?refactor:=20constants=20export=20?= =?UTF-8?q?=ED=98=95=EC=8B=9D=EC=97=90=EC=84=9C=20function=20export=20?= =?UTF-8?q?=ED=98=95=EC=8B=9D=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/_actions/types.ts | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/_actions/types.ts b/src/_actions/types.ts index aa888e0..128aeb9 100644 --- a/src/_actions/types.ts +++ b/src/_actions/types.ts @@ -1,4 +1,20 @@ -export const NEW_CHAT_ROOM = "new_chat_room" as const; -export const LEAVE_CHAT_ROOM = "leave_chat_room" as const; -export const SEND_MESSAGE = "send_message" as const; -export const RECEIVE_MESSAGE = "receive_message" as const; \ No newline at end of file +const NEW_CHAT_ROOM = "new_chat_room" as const; +const LEAVE_CHAT_ROOM = "leave_chat_room" as const; +const SEND_MESSAGE = "send_message" as const; +const RECEIVE_MESSAGE = "receive_message" as const; + +export const new_chat_room = () => ({ + type: NEW_CHAT_ROOM +}); + +export const leave_chat_room = () => ({ + type: LEAVE_CHAT_ROOM +}); + +export const send_message = () => ({ + type: SEND_MESSAGE +}); + +export const receive_message = () => ({ + type: RECEIVE_MESSAGE +}); \ No newline at end of file From c3664b7492a66bb994d9f9523fe0863dfafd0e69 Mon Sep 17 00:00:00 2001 From: oereo Date: Tue, 6 Sep 2022 14:23:55 +0900 Subject: [PATCH 04/10] =?UTF-8?q?feat:=20ChatReducer=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20=EB=B0=8F=20ChatAction,=20ChatState=20type=20=EC=A7=80?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/_actions/types.ts | 8 ++++---- src/_reducers/ChatReducer.ts | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 src/_reducers/ChatReducer.ts diff --git a/src/_actions/types.ts b/src/_actions/types.ts index 128aeb9..ac9aeec 100644 --- a/src/_actions/types.ts +++ b/src/_actions/types.ts @@ -3,18 +3,18 @@ const LEAVE_CHAT_ROOM = "leave_chat_room" as const; const SEND_MESSAGE = "send_message" as const; const RECEIVE_MESSAGE = "receive_message" as const; -export const new_chat_room = () => ({ +export const newChatRoom = () => ({ type: NEW_CHAT_ROOM }); -export const leave_chat_room = () => ({ +export const leaveChatRoom = () => ({ type: LEAVE_CHAT_ROOM }); -export const send_message = () => ({ +export const sendMessage = () => ({ type: SEND_MESSAGE }); -export const receive_message = () => ({ +export const receiveMessage = () => ({ type: RECEIVE_MESSAGE }); \ No newline at end of file diff --git a/src/_reducers/ChatReducer.ts b/src/_reducers/ChatReducer.ts new file mode 100644 index 0000000..00e531d --- /dev/null +++ b/src/_reducers/ChatReducer.ts @@ -0,0 +1,16 @@ +import { + newChatRoom, + leaveChatRoom, + sendMessage, + receiveMessage +} from '_actions/types'; + +type ChatAction = + | ReturnType + | ReturnType + | ReturnType + | ReturnType; + +type ChatState = { + chat: Array>; +} From 4e22f5e88ce9508bda89259696be12975749b251 Mon Sep 17 00:00:00 2001 From: oereo Date: Tue, 6 Sep 2022 17:31:52 +0900 Subject: [PATCH 05/10] =?UTF-8?q?feat:=20TargetChatRoom=20interface=20type?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80=20-=20redux=20action=20payload=20data=20t?= =?UTF-8?q?ype?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/_actions/ChatActionTypes.ts | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/_actions/ChatActionTypes.ts diff --git a/src/_actions/ChatActionTypes.ts b/src/_actions/ChatActionTypes.ts new file mode 100644 index 0000000..88f3db5 --- /dev/null +++ b/src/_actions/ChatActionTypes.ts @@ -0,0 +1,3 @@ +export interface TargetChatRoom { + title: String +} \ No newline at end of file From 989624e3d2eb0b04ac1692f499d705169195f778 Mon Sep 17 00:00:00 2001 From: oereo Date: Tue, 6 Sep 2022 17:32:31 +0900 Subject: [PATCH 06/10] =?UTF-8?q?feat:=20ChatAction=20function=EC=97=90?= =?UTF-8?q?=EC=84=9C=20createChatRoom=20method=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/_actions/ChatAction.ts | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/_actions/ChatAction.ts diff --git a/src/_actions/ChatAction.ts b/src/_actions/ChatAction.ts new file mode 100644 index 0000000..514fd1e --- /dev/null +++ b/src/_actions/ChatAction.ts @@ -0,0 +1,7 @@ +import { NEW_CHAT_ROOM, LEAVE_CHAT_ROOM, RECEIVE_MESSAGE, SEND_MESSAGE } from "./types"; +import { TargetChatRoom } from "./ChatActionTypes"; + +export const createChatRoom = (targetChatRoom: TargetChatRoom) => ({ + type: NEW_CHAT_ROOM, + payload: targetChatRoom, +}); From 65e0f47e65ba7d49c43dc8460c025e9ff3e2a012 Mon Sep 17 00:00:00 2001 From: oereo Date: Tue, 6 Sep 2022 17:37:10 +0900 Subject: [PATCH 07/10] =?UTF-8?q?feat:=20TargetMessage=20payload=20type=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/_actions/ChatActionTypes.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/_actions/ChatActionTypes.ts b/src/_actions/ChatActionTypes.ts index 88f3db5..1a40e8b 100644 --- a/src/_actions/ChatActionTypes.ts +++ b/src/_actions/ChatActionTypes.ts @@ -1,3 +1,7 @@ export interface TargetChatRoom { title: String +} + +export interface TargetMessage { + content: String } \ No newline at end of file From 962fd2b9e5131da6f9093fafd66a8f235154f713 Mon Sep 17 00:00:00 2001 From: oereo Date: Tue, 6 Sep 2022 17:37:38 +0900 Subject: [PATCH 08/10] =?UTF-8?q?refactor:=20function=20format=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=EC=9C=BC=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20method=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/_actions/types.ts | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/_actions/types.ts b/src/_actions/types.ts index ac9aeec..a8e29bd 100644 --- a/src/_actions/types.ts +++ b/src/_actions/types.ts @@ -1,20 +1,4 @@ -const NEW_CHAT_ROOM = "new_chat_room" as const; -const LEAVE_CHAT_ROOM = "leave_chat_room" as const; -const SEND_MESSAGE = "send_message" as const; -const RECEIVE_MESSAGE = "receive_message" as const; - -export const newChatRoom = () => ({ - type: NEW_CHAT_ROOM -}); - -export const leaveChatRoom = () => ({ - type: LEAVE_CHAT_ROOM -}); - -export const sendMessage = () => ({ - type: SEND_MESSAGE -}); - -export const receiveMessage = () => ({ - type: RECEIVE_MESSAGE -}); \ No newline at end of file +export const NEW_CHAT_ROOM = "new_chat_room" as const; +export const LEAVE_CHAT_ROOM = "leave_chat_room" as const; +export const SEND_MESSAGE = "send_message" as const; +export const RECEIVE_MESSAGE = "receive_message" as const; From bf76d9695e6bcc0969a0271df769e329ce04d28f Mon Sep 17 00:00:00 2001 From: oereo Date: Tue, 6 Sep 2022 17:40:08 +0900 Subject: [PATCH 09/10] =?UTF-8?q?feat:=20sendMessage,=20receiveMessage,=20?= =?UTF-8?q?leaveChatRoom=20function=20=EC=9E=AC=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/_actions/ChatAction.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/_actions/ChatAction.ts b/src/_actions/ChatAction.ts index 514fd1e..a18cb27 100644 --- a/src/_actions/ChatAction.ts +++ b/src/_actions/ChatAction.ts @@ -1,7 +1,22 @@ import { NEW_CHAT_ROOM, LEAVE_CHAT_ROOM, RECEIVE_MESSAGE, SEND_MESSAGE } from "./types"; -import { TargetChatRoom } from "./ChatActionTypes"; +import { TargetChatRoom, TargetMessage } from "./ChatActionTypes"; export const createChatRoom = (targetChatRoom: TargetChatRoom) => ({ type: NEW_CHAT_ROOM, payload: targetChatRoom, }); + +export const leaveChatRoom = (targetChatRoom: TargetChatRoom) => ({ + type: LEAVE_CHAT_ROOM, + payload: targetChatRoom, +}); + +export const sendMessage = (targetMessage: TargetMessage) => ({ + type: SEND_MESSAGE, + payload: targetMessage, +}); + +export const receiveMessage = (targetMessage: TargetMessage) => ({ + type: RECEIVE_MESSAGE, + payload: targetMessage, +}); \ No newline at end of file From e4cc50dea83c6500a39c7ada4c98a267621c785f Mon Sep 17 00:00:00 2001 From: oereo Date: Tue, 6 Sep 2022 17:44:14 +0900 Subject: [PATCH 10/10] =?UTF-8?q?feat:=20chatReducer=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=20=EB=B0=8F=20new=5Fchat=5Froom=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/_actions/ChatActionTypes.ts | 4 +++- src/_reducers/ChatReducer.ts | 35 ++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/_actions/ChatActionTypes.ts b/src/_actions/ChatActionTypes.ts index 1a40e8b..c93cc86 100644 --- a/src/_actions/ChatActionTypes.ts +++ b/src/_actions/ChatActionTypes.ts @@ -1,5 +1,7 @@ export interface TargetChatRoom { - title: String + id: number + title: String, + messages: Array } export interface TargetMessage { diff --git a/src/_reducers/ChatReducer.ts b/src/_reducers/ChatReducer.ts index 00e531d..c6f6094 100644 --- a/src/_reducers/ChatReducer.ts +++ b/src/_reducers/ChatReducer.ts @@ -1,12 +1,19 @@ import { - newChatRoom, - leaveChatRoom, - sendMessage, - receiveMessage + NEW_CHAT_ROOM, + LEAVE_CHAT_ROOM, + SEND_MESSAGE, + RECEIVE_MESSAGE } from '_actions/types'; +import { + createChatRoom, + leaveChatRoom, + sendMessage, + receiveMessage +} from '_actions/ChatAction' + type ChatAction = - | ReturnType + | ReturnType | ReturnType | ReturnType | ReturnType; @@ -14,3 +21,21 @@ type ChatAction = type ChatState = { chat: Array>; } + +const initialState: ChatState = { + chat : [] +} + +export default function chatReducer( + state: ChatState = initialState, + action: ChatAction + ) : ChatState { + switch(action.type) { + case NEW_CHAT_ROOM: + state.chat[action.payload.id] = [...action.payload.messages]; + return {...state}; + default: + return state; + } + +} \ No newline at end of file