Skip to content

Commit

Permalink
Fix actions
Browse files Browse the repository at this point in the history
  • Loading branch information
MeyerPV committed Nov 20, 2024
1 parent d145e24 commit a051e96
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const NewDiscussionCreation: FC<NewDiscussionCreationProps> = (props) => {
);

const handleCancel = () => {
dispatch(commonActions.setCommonAction({ action: null, commonId }));
dispatch(commonActions.setCommonAction(null));
dispatch(commonActions.setDiscussionCreationData({ data: null, commonId }));
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const NewProposalCreation: FC<NewProposalCreationProps> = (props) => {
);

const handleCancel = () => {
dispatch(commonActions.setCommonAction({ action: null, commonId }));
dispatch(commonActions.setCommonAction(null));
dispatch(commonActions.setProposalCreationData({ data: null, commonId }));
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,7 @@ export const useMenuItems = (
},
}),
);
dispatch(
commonActions.setCommonAction({
action: CommonAction.EditDiscussion,
commonId: commonId ?? "",
}),
);
dispatch(commonActions.setCommonAction(CommonAction.EditDiscussion));
animateScroll.scrollToTop({ containerId: document.body, smooth: true });
},
icon: <Edit3Icon />,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/commonFeed/CommonFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ const CommonFeedComponent: FC<CommonFeedProps> = (props) => {
<ErrorBoundary
fallback={null}
onError={() => {
dispatch(commonActions.setCommonAction({ action: null, commonId }));
dispatch(commonActions.setCommonAction(null));
}}
>
{(commonAction === CommonAction.NewDiscussion ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ const NewStreamButton: FC<NewStreamButtonProps> = (props) => {
const dispatch = useDispatch();

const onNewDiscussion = () => {
dispatch(
commonActions.setCommonAction({
action: CommonAction.NewDiscussion,
commonId,
}),
);
dispatch(commonActions.setCommonAction(CommonAction.NewDiscussion));
animateScroll.scrollToTop({ containerId: document.body, smooth: true });
};
const items = useMenuItems({
Expand Down
5 changes: 1 addition & 4 deletions src/store/states/common/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ export const resetCommon = createStandardAction(

export const setCommonAction = createStandardAction(
CommonActionType.SET_COMMON_ACTION,
)<{
commonId: string;
action: CommonAction | null;
}>();
)<CommonAction | null>();

export const setCommonMember = createStandardAction(
CommonActionType.SET_COMMON_MEMBER,
Expand Down
5 changes: 2 additions & 3 deletions src/store/states/common/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const initialState: CommonState = {
pinnedFeedItems: {},
searchState: {},
sharedFeedItem: {},
commonActions: {},
commonAction: null,
discussionCreations: {},
proposalCreations: {},
isNewProjectCreated: {},
Expand Down Expand Up @@ -312,8 +312,7 @@ export const reducer = createReducer<CommonState, Action>(initialState)
// Common Actions
.handleAction(actions.setCommonAction, (state, { payload }) =>
produce(state, (nextState) => {
const { commonId, action: commonAction } = payload;
nextState.commonActions[commonId] = commonAction;
nextState.commonAction = payload;
}),
)
.handleAction(actions.setCommonMember, (state, { payload }) =>
Expand Down
2 changes: 1 addition & 1 deletion src/store/states/common/saga/editDiscussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function* editDiscussion(
}),
);

yield put(actions.setCommonAction({ action: null, commonId }));
yield put(actions.setCommonAction(null));
yield put(actions.editDiscussion.success({ discussion, commonId }));

if (payload.callback) {
Expand Down
4 changes: 2 additions & 2 deletions src/store/states/common/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { AppState } from "@/shared/interfaces";

export const selectCommonState = (state: AppState) => state.common;

export const selectCommonAction = (commonId: string) => (state: AppState) =>
state.common.commonActions[commonId] || null;
export const selectCommonAction = (state: AppState) =>
state.common.commonAction || null;

export const selectCommonMember = (commonId: string) => (state: AppState) =>
state.common.commonMembers[commonId] || {};
Expand Down
2 changes: 1 addition & 1 deletion src/store/states/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface CommonState {
feedItems: Record<string, FeedItems>;
pinnedFeedItems: Record<string, PinnedFeedItems>;
sharedFeedItem: Record<string, FeedItemFollowLayoutItem | null>;
commonActions: Record<string, CommonAction | null>;
commonAction: CommonAction | null;
discussionCreations: Record<
string,
EntityCreation<NewDiscussionCreationFormValues>
Expand Down

0 comments on commit a051e96

Please sign in to comment.