Skip to content

Commit

Permalink
Add reactions to meetings. Rewrote meeting from class component -> hook.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasdeluna committed Feb 10, 2023
1 parent 93c892d commit 6eb1282
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 133 deletions.
2 changes: 2 additions & 0 deletions app/models.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type Comment from 'app/store/models/Comment';
import type { ReactionsGrouped } from './store/models/Reaction';
import type { Moment } from 'moment';
// TODO: Id handling could be opaque
export type ID = number;
Expand Down Expand Up @@ -316,6 +317,7 @@ export type Meeting = {
comments?: ID[];
contentTarget?: string;
actionGrant?: ActionGrant;
reactionsGrouped?: ReactionsGrouped;
};

export type AddPenalty = {
Expand Down
1 change: 1 addition & 0 deletions app/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const meetingSchema = new schema.Entity('meetings', {
reportAuthor: userSchema,
createdBy: userSchema,
comments: [commentSchema],
reactions: [reactionSchema],
});
export const frontpageSchema = new schema.Entity('frontpage', {
events: [eventSchema],
Expand Down
21 changes: 20 additions & 1 deletion app/reducers/meetings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { createSelector } from 'reselect';
import type { Dateish } from 'app/models';
import { mutateComments } from 'app/reducers/comments';
import createEntityReducer from 'app/utils/createEntityReducer';
import joinReducers from 'app/utils/joinReducers';
import { Meeting } from '../actions/ActionTypes';
import { mutateReactions } from './reactions';
import type { ReactionEntity } from './reactions';

export type MeetingEntity = {
id: number;
Expand All @@ -16,14 +19,18 @@ export type MeetingEntity = {
reportAuthor: number;
createdBy: number;
mazemapPoi: number;
reactionsGrouped?: Array<ReactionEntity>;
};

export type MeetingSection = {
title: string;
meetings: Array<MeetingEntity>;
};

const mutate = mutateComments('meetings');
const mutate = joinReducers(
mutateComments('meetings'),
mutateReactions('meetings')
);

export default createEntityReducer({
key: 'meetings',
Expand Down Expand Up @@ -52,6 +59,18 @@ export const selectCommentsForMeeting = createSelector(
return meeting.comments.map((commentId) => commentsById[commentId]);
}
);

export const selectReactionsForMeeting = createSelector(
selectMeetingById,
(state) => state.reactions.byId,
(meeting, reactionsById) => {
if (!meeting) return [];
return (meeting.reactionsGrouped || []).map(
(reactionId) => reactionsById[reactionId]
);
}
);

export const selectGroupedMeetings = createSelector(
selectMeetings,
(meetings) => {
Expand Down
15 changes: 14 additions & 1 deletion app/routes/meetings/MeetingDetailRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import qs from 'qs';
import { connect } from 'react-redux';
import { compose } from 'redux';
import { deleteComment } from 'app/actions/CommentActions';
import { fetchEmojis } from 'app/actions/EmojiActions';
import {
fetchMeeting,
setInvitationStatus,
answerMeetingInvitation,
resetMeetingsToken,
} from 'app/actions/MeetingActions';
import { addReaction, deleteReaction } from 'app/actions/ReactionActions';
import type { User } from 'app/models';
import { selectEmojis } from 'app/reducers/emojis';
import { selectMeetingById } from 'app/reducers/meetings';
import type { ReactionEntity } from 'app/reducers/reactions';
import withPreparedDispatch from 'app/utils/withPreparedDispatch';
import MeetingDetailLoginRoute from './MeetingDetailLoginRoute';
import MeetingAnswer from './components/MeetingAnswer';
Expand All @@ -22,7 +26,10 @@ const loadMeeting = (
},
},
dispatch
) => (loggedIn ? dispatch(fetchMeeting(meetingId)) : Promise.resolve());
) =>
loggedIn
? dispatch(fetchMeeting(meetingId), fetchEmojis())
: Promise.resolve();

const loadData = (props, dispatch): any => {
const search = qs.parse(props.location.search, {
Expand Down Expand Up @@ -63,12 +70,14 @@ const mapStateToProps = (state, props) => {
const showAnswer = Boolean(
meetingsToken.response === 'SUCCESS' && action && token
);
const emojis = selectEmojis(state);
return {
meetingsToken,
user: props.currentUser,
showAnswer,
meeting,
currentUser,
emojis,
};
};

Expand All @@ -79,6 +88,7 @@ type Props = {
user: User;
response: string;
meeting: number;
reactionsGrouped: Array<ReactionEntity>;
};
router: any;
resetMeetingsToken: () => void;
Expand All @@ -105,6 +115,9 @@ const mapDispatchToProps = {
setInvitationStatus,
resetMeetingsToken,
deleteComment,
fetchEmojis,
addReaction,
deleteReaction,
};
export default compose(
withPreparedDispatch('fetchMeetingDetail', loadData, (props) => [
Expand Down
6 changes: 6 additions & 0 deletions app/routes/meetings/components/MeetingDetail.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@
display: flex;
margin-bottom: 10px;
}

.meetingReactions {
display: flex;
flex-direction: row;
margin: 0.5em 0 0.5em 0;
}

0 comments on commit 6eb1282

Please sign in to comment.