Skip to content

HeeyeonJeong/comment-board

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

16 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

comment-board

React์™€ Redux๋กœ ๊ตฌํ˜„ํ•œ API์„œ๋ฒ„์™€ ํ†ต์‹ ํ•˜์—ฌ ์ž‘๋™ํ•˜๋Š” ๋Œ“๊ธ€ ๊ฒŒ์‹œํŒ

โš™ Stack

  • json-server๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Mock API ์‚ฌ์šฉ

  • ๋ฐฐํฌ : heroku

React

  • styled-components

Redux-thunk


๐Ÿ–ผ UI

image


๐Ÿ“š Features

  • Container components์™€ Presentational components ๋ถ„๋ฆฌํ•˜์—ฌ ์ž‘์„ฑ
  • Pagination
  • ๋Œ“๊ธ€ ์ž‘์„ฑ ํ›„, 1 ํŽ˜์ด์ง€๋กœ ์ด๋™ + form ์ดˆ๊ธฐํ™”
  • ๋Œ“๊ธ€ ์ˆ˜์ • ํ›„, ํ˜„์žฌ ๋ณด๊ณ  ์žˆ๋Š” ํŽ˜์ด์ง€ ์œ ์ง€ + form ์ดˆ๊ธฐํ™”
  • ๋Œ“๊ธ€ ์‚ญ์ œ ํ›„, 1 ํŽ˜์ด์ง€๋กœ ๋Œ์•„์˜ค๊ธฐ

๊ตฌ์กฐ

  • api

    • GET, POST, PUT, DELETE
  • CommentListContainer

    • CommentList component : ํŽ˜์ด์ง€์— ๋”ฐ๋ฅธ comments๋ฅผ ๋ฐ›์•„์˜ค๋Š” ์ปดํฌ๋„ŒํŠธ
  • FormContainer

    • Form component : form ์–‘์‹์„ ์ „๋‹ฌ, ๋ฐ›์•„์˜ค๋Š” ์ปดํฌ๋„ŒํŠธ
  • PageListContainer

    • pageList component : ์ด comment๋ฅผ ๋ฐ›์•„์™€์„œ page number์„ ์ „๋‹ฌํ•˜๋Š” ์ปดํฌ๋„ŒํŠธ

redux-thunk๋ฅผ ๊ฐ„๋‹จํ•˜๊ฒŒ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋Š” ์œ ํ‹ธํ•จ์ˆ˜

//reducerUtils
export const reducerUtils = {
  initial: (data = []) => ({
    loading: false,
    data,
    error: null,
  }),
  loading: (prevState) => ({
    loading: true,
    data: prevState,
    error: null,
  }),
  success: (payload) => ({
    loading: false,
    data: payload,
    error: null,
  }),
  error: (error) => ({
    loading: false,
    data: null,
    error: error,
  }),
};

//createThunk
export const createPromiseThunk = (type, promiseCreator) => {
  const [SUCCESS, ERROR] = [`${type}_SUCCESS`, `${type}_ERROR`];

  const thunkCreator = (param) => async (dispatch) => {
    dispatch({ type });
    try {
      const payload = await promiseCreator(param);
      dispatch({
        type: SUCCESS,
        payload,
      });
    } catch (e) {
      dispatch({
        type: ERROR,
        payload: e,
        error: true,
      });
    }
  };
  return thunkCreator;
};

//handleAsyncActions
export const handleAsyncActions = (type, key) => {
  const [SUCCESS, ERROR] = [`${type}_SUCCESS`, `${type}_ERROR`];

  const reducer = (state, action) => {
    switch (action.type) {
      case type:
        return {
          ...state,
          [key]: reducerUtils.loading(),
        };
      case SUCCESS:
        return {
          ...state,
          [key]: reducerUtils.success(action.payload),
        };
      case ERROR:
        return {
          ...state,
          [key]: reducerUtils.error(action.payload),
        };
      default:
        return state;
    }
  };
  return reducer;
};

About

๐Ÿ“‹ ๋Œ“๊ธ€ ๊ฒŒ์‹œํŒ

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published