-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Channel Store Type 정의 * feat: Channel Store Action 정의 * feat: getChannels API 구현 - 초기 채널 정보를 받아오는 getChannels API 구현 * feat: Channel Store Reducer, Saga 정의
- Loading branch information
1 parent
8b3b23f
commit 96265c9
Showing
7 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { INIT_CHANNELS_ASYNC } from '../types/channel-types'; | ||
|
||
export const initChannels = () => ({ type: INIT_CHANNELS_ASYNC }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { channelsState, ChannelTypes, INIT_CHANNELS } from '../types/channel-types'; | ||
|
||
const initialState: channelsState = { | ||
channelCount: 0, | ||
channels: [] | ||
}; | ||
|
||
export default function channelReducer(state = initialState, action: ChannelTypes) { | ||
switch (action.type) { | ||
case INIT_CHANNELS: | ||
return { | ||
channelCount: action.payload.channelCount, | ||
channels: action.payload.channels | ||
}; | ||
default: | ||
return state; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { call, put, takeEvery } from 'redux-saga/effects'; | ||
import API from '@utils/api'; | ||
import { INIT_CHANNELS, INIT_CHANNELS_ASYNC } from '../types/channel-types'; | ||
|
||
function* initChannelsSaga() { | ||
try { | ||
const channelCount = 0; | ||
const channels = yield call(API.getChannels); | ||
yield put({ type: INIT_CHANNELS, payload: { channelCount, channels } }); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
} | ||
|
||
export function* channelSaga() { | ||
yield takeEvery(INIT_CHANNELS_ASYNC, initChannelsSaga); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { all } from 'redux-saga/effects'; | ||
import { chatroomSaga } from './chatroom-saga'; | ||
import { userSaga } from './user-saga'; | ||
import { channelSaga } from './channel-saga'; | ||
|
||
export function* rootSaga() { | ||
yield all([chatroomSaga(), userSaga()]); | ||
yield all([chatroomSaga(), userSaga(), channelSaga()]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export const INIT_CHANNELS = 'INIT_CHANNELS'; | ||
export const INIT_CHANNELS_ASYNC = 'INIT_CHANNELS_ASYNC'; | ||
|
||
export interface channelState { | ||
channelId: number; | ||
title: string; | ||
description: string; | ||
isPrivate: boolean; | ||
members: number; | ||
isJoined: boolean; | ||
} | ||
|
||
export interface channelsState { | ||
channelCount: number; | ||
channels: Array<channelState>; | ||
} | ||
|
||
interface InitChannelsAction { | ||
type: typeof INIT_CHANNELS; | ||
payload: channelsState; | ||
} | ||
|
||
export type ChannelTypes = InitChannelsAction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters