Skip to content

Commit

Permalink
CW-Optimistic-streams
Browse files Browse the repository at this point in the history
Full support of proposal optimistic streams
Clean up code
  • Loading branch information
MeyerPV committed Sep 2, 2024
1 parent a6eaa74 commit a4476a6
Show file tree
Hide file tree
Showing 51 changed files with 130 additions and 1,229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export default function ChatComponent({

const optimisticFeedItems = useSelector(selectOptimisticFeedItems);

console.log("--optimisticFeedItems", optimisticFeedItems);
// console.log("--optimisticFeedItems", optimisticFeedItems);
const optimisticDiscussionMessages = useSelector(
selectOptimisticDiscussionMessages,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React, { FC, useCallback, useEffect, useMemo } from "react";
import { useDispatch, useSelector } from "react-redux";
import { Timestamp as FirestoreTimestamp } from "firebase/firestore";
import { v4 as uuidv4 } from "uuid";
import { selectUser } from "@/pages/Auth/store/selectors";
import { DiscussionMessageOwnerType } from "@/shared/constants";
import {
NewDiscussionCreationFormValues,
UploadFile,
Expand All @@ -15,13 +13,12 @@ import {
CommonFeedType,
CommonMember,
Governance,
OptimisticFeedItemState,
} from "@/shared/models";
import {
TextEditorValue,
parseStringToTextEditorValue,
} from "@/shared/ui-kit/TextEditor";
import { getUserName } from "@/shared/utils";
import { generateOptimisticFeedItem } from "@/shared/utils";
import {
selectDiscussionCreationData,
selectIsDiscussionCreationLoading,
Expand Down Expand Up @@ -123,52 +120,19 @@ const NewDiscussionCreation: FC<NewDiscussionCreationProps> = (props) => {
);
} else {
const discussionId = uuidv4();
const currentDate = FirestoreTimestamp.now();

const optimisticFeedItemId = uuidv4();
dispatch(
commonActions.setOptimisticFeedItem({
id: optimisticFeedItemId,
createdAt: currentDate,
updatedAt: currentDate,
isDeleted: false,
userId,
commonId: common.id,
data: {
type: CommonFeedType.OptimisticDiscussion,
id: discussionId,
discussionId: null,
lastMessage: {
userName: getUserName(user),
ownerId: userId,
content: JSON.stringify(values.content),
ownerType: DiscussionMessageOwnerType.User,
},
hasFiles: false,
hasImages: false,
},
optimisticData: {
id: discussionId,
title: values.title,
message: JSON.stringify(values.content),
ownerId: userId,
commonActions.setOptimisticFeedItem(
generateOptimisticFeedItem({
userId,
commonId: common.id,
lastMessage: currentDate,
updatedAt: currentDate,
createdAt: currentDate,
messageCount: 0,
followers: [],
files: [],
images: [],
discussionMessages: [],
isDeleted: false,
type: CommonFeedType.OptimisticDiscussion,
circleVisibility,
circleVisibilityByCommon: null,
linkedCommonIds: [],
state: OptimisticFeedItemState.loading,
},
circleVisibility,
}),
discussionId,
title: values.title,
content: JSON.stringify(values.content),
}),
),
);

dispatch(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import React, { FC, ReactNode, useCallback, useMemo } from "react";
import { useDispatch, useSelector } from "react-redux";
import { Timestamp as FirestoreTimestamp } from "firebase/firestore";
import { v4 as uuidv4 } from "uuid";
import { selectUser } from "@/pages/Auth/store/selectors";
import {
DiscussionMessageOwnerType,
PROPOSAL_TYPE_SELECT_OPTIONS,
ProposalsTypes,
} from "@/shared/constants";
Expand All @@ -15,10 +13,9 @@ import {
CommonFeedType,
CommonMember,
Governance,
OptimisticFeedItemState,
} from "@/shared/models";
import { parseStringToTextEditorValue } from "@/shared/ui-kit/TextEditor";
import { getUserName } from "@/shared/utils";
import { generateOptimisticFeedItem } from "@/shared/utils";
import {
selectIsProposalCreationLoading,
selectProposalCreationData,
Expand Down Expand Up @@ -90,52 +87,19 @@ const NewProposalCreation: FC<NewProposalCreationProps> = (props) => {

const proposalId = uuidv4();
const discussionId = uuidv4();
const currentDate = FirestoreTimestamp.now();

const optimisticFeedItemId = uuidv4();
dispatch(
commonActions.setOptimisticFeedItem({
id: optimisticFeedItemId,
createdAt: currentDate,
updatedAt: currentDate,
isDeleted: false,
userId,
commonId: common.id,
data: {
type: CommonFeedType.OptimisticDiscussion,
id: discussionId,
discussionId: null,
lastMessage: {
userName: getUserName(user),
ownerId: userId,
content: JSON.stringify(values.content),
ownerType: DiscussionMessageOwnerType.User,
},
hasFiles: false,
hasImages: false,
},
optimisticData: {
id: discussionId,
title: values.title,
message: JSON.stringify(values.content),
ownerId: userId,
commonActions.setOptimisticFeedItem(
generateOptimisticFeedItem({
userId,
commonId: common.id,
lastMessage: currentDate,
updatedAt: currentDate,
createdAt: currentDate,
messageCount: 0,
followers: [],
files: [],
images: [],
discussionMessages: [],
isDeleted: false,
type: CommonFeedType.OptimisticProposal,
circleVisibility: userCircleIds,
circleVisibilityByCommon: null,
linkedCommonIds: [],
state: OptimisticFeedItemState.loading,
},
circleVisibility: userCircleIds,
}),
discussionId,
title: values.title,
content: JSON.stringify(values.content),
}),
),
);
switch (values.proposalType.value) {
case ProposalsTypes.FUNDS_ALLOCATION: {
Expand All @@ -158,25 +122,16 @@ const NewProposalCreation: FC<NewProposalCreationProps> = (props) => {
break;
}
case ProposalsTypes.SURVEY: {
console.log(
"----getSurveyProposalPayload",
getSurveyProposalPayload(
values,
commonId,
proposalId,
discussionId,
),
dispatch(
commonActions.createSurveyProposal.request({
payload: getSurveyProposalPayload(
values,
commonId,
proposalId,
discussionId,
),
}),
);
// dispatch(
// commonActions.createSurveyProposal.request({
// payload: getSurveyProposalPayload(
// values,
// commonId,
// proposalId,
// discussionId,
// ),
// }),
// );
break;
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/pages/common/components/FeedItem/FeedItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { checkIsItemVisibleForUser } from "@/shared/utils";
import { useFeedItemSubscription } from "../../hooks";
import { DiscussionFeedCard } from "../DiscussionFeedCard";
import { OptimisticDiscussionFeedCard } from "../OptimisticDiscussionFeedCard";
import { OptimisticFeedCard } from "../OptimisticFeedCard";
import { ProposalFeedCard } from "../ProposalFeedCard";
import { ProjectFeedItem } from "./components";
import { useFeedItemContext } from "./context";
Expand Down Expand Up @@ -145,7 +145,6 @@ const FeedItem = forwardRef<FeedItemRef, FeedItemProps>((props, ref) => {
onFeedItemUnfollowed,
]);


const generalProps = useMemo(
() => ({
ref,
Expand Down Expand Up @@ -207,7 +206,6 @@ const FeedItem = forwardRef<FeedItemRef, FeedItemProps>((props, ref) => {
],
);


if (
shouldCheckItemVisibility &&
!checkIsItemVisibleForUser({
Expand All @@ -221,11 +219,15 @@ const FeedItem = forwardRef<FeedItemRef, FeedItemProps>((props, ref) => {
return null;
}

if (item.data.type === CommonFeedType.OptimisticDiscussion) {
if (
item.data.type === CommonFeedType.OptimisticDiscussion ||
item.data.type === CommonFeedType.OptimisticProposal
) {
return (
<OptimisticDiscussionFeedCard
<OptimisticFeedCard
{...generalProps}
discussion={item.optimisticData}
type={item.data.type}
/>
);
}
Expand Down

This file was deleted.

Loading

0 comments on commit a4476a6

Please sign in to comment.