post.js 789 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import moment from 'moment';
  2. import { hydrateUser } from './users';
  3. export const PATCH_POST = 'PATCH_POST';
  4. export function hydrate(json) {
  5. return Object.assign({}, json, {
  6. posted_on: moment(json.posted_on),
  7. updated_on: moment(json.updated_on),
  8. hidden_on: moment(json.hidden_on),
  9. poster: json.poster ? hydrateUser(json.poster) : null,
  10. isSelected: false,
  11. isBusy: false,
  12. isDeleted: false
  13. });
  14. }
  15. export function patch(post, patch) {
  16. return {
  17. type: PATCH_POST,
  18. post,
  19. patch
  20. };
  21. }
  22. export default function post(state={}, action=null) {
  23. switch (action.type) {
  24. case PATCH_POST:
  25. if (state.id == action.post.id) {
  26. return Object.assign({}, state, action.patch);
  27. }
  28. return state;
  29. default:
  30. return state;
  31. }
  32. }