Skip to content

Commit

Permalink
Merge pull request #2729 from daostack/CW-Optimistic-streams
Browse files Browse the repository at this point in the history
Instant opening of a stream
  • Loading branch information
MeyerPV authored Oct 1, 2024
2 parents c85af4d + 6c332c7 commit d0483cf
Show file tree
Hide file tree
Showing 56 changed files with 1,140 additions and 145 deletions.
3 changes: 3 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import "./projectSetupImports";
import React from "react";
import ReactDOM from "react-dom";
import { enableMapSet } from "immer";
import { App, AppWrapper } from "@/pages/App";

enableMapSet();

ReactDOM.render(
<AppWrapper>
<App />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import classNames from "classnames";
import { Formik } from "formik";
import { omit } from "lodash";
import * as Yup from "yup";
import { v4 as uuidv4 } from "uuid";
import { createDiscussion } from "@/pages/OldCommon/store/actions";
import { getCommonGovernanceCircles } from "@/pages/OldCommon/store/api";
import { Modal } from "@/shared/components";
Expand Down Expand Up @@ -109,10 +110,14 @@ const AddDiscussionComponent = ({
);
const payload = omit(values, "isLimitedDiscussion");


// TODO: CHECK if it needed for optimistic
const discussionId = uuidv4();
dispatch(
createDiscussion.request({
payload: {
...payload,
id: discussionId,
ownerId: uid,
commonId: commonId,
circleVisibility,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import React, {
useState,
} from "react";
import { useSelector } from "react-redux";
import { v4 as uuidv4 } from "uuid";
import classNames from "classnames";
import { Modal } from "@/shared/components";
import { AllocateFundsTo, ScreenSize } from "@/shared/constants";
Expand Down Expand Up @@ -67,6 +68,8 @@ export const AddProposalComponent = ({
const [fundingRequest, setFundingRequest] =
useState<CreateFundsAllocationData>({
args: {
id: "",
discussionId: "",
title: "",
description: "",
links: [],
Expand Down Expand Up @@ -125,8 +128,10 @@ export const AddProposalComponent = ({

const saveProposalState = useCallback(
(payload: Partial<CreateFundsAllocationFormData>) => {
const proposalId = uuidv4();
const discussionId = uuidv4();
const fundingRequestData = {
args: { ...fundingRequest.args, ...payload },
args: { ...fundingRequest.args, ...payload, id: proposalId, discussionId },
};
setFundingRequest(fundingRequestData);
if (!payload?.amount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useDispatch } from "react-redux";
import classNames from "classnames";
import { Formik } from "formik";
import * as Yup from "yup";
import { v4 as uuidv4 } from "uuid";
import { getBankDetails } from "@/pages/OldCommon/store/actions";
import { Button, ButtonIcon, Loader, ModalFooter } from "@/shared/components";
import {
Expand Down Expand Up @@ -101,6 +102,8 @@ export const AddProposalForm = ({
}, [dispatch, hidden]);

const [formValues] = useState<CreateFundsAllocationFormData>({
id: "",
discussionId: "",
title: "",
description: "",
links: [{ title: "", value: "" }],
Expand Down Expand Up @@ -168,7 +171,9 @@ export const AddProposalForm = ({
validationSchema={schema}
onSubmit={(values, { setSubmitting }) => {
setSubmitting(false);
saveProposalState({ ...values, images: uploadedFiles });
const proposalId = uuidv4();
const discussionId = uuidv4();
saveProposalState({ ...values, images: uploadedFiles, id: proposalId, discussionId });
}}
initialValues={formValues}
validateOnChange={true}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { FC, useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { v4 as uuidv4 } from "uuid";
import { selectUser } from "@/pages/Auth/store/selectors";
import { useCommonMembers } from "@/pages/OldCommon/hooks";
import { CreateProposal } from "@/pages/OldCommon/interfaces";
Expand Down Expand Up @@ -79,11 +80,15 @@ const AssignCircleStage: FC<AssignCircleStageProps> = (props) => {
}

setIsProposalCreating(true);
const proposalId = uuidv4();
const discussionId = uuidv4();
const payload: Omit<
CreateProposal[ProposalsTypes.ASSIGN_CIRCLE]["data"],
"type"
> = {
args: {
id: proposalId,
discussionId,
commonId: common.id,
// TODO: Use here name of common member
title: `Request to join ${
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { FC, useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { v4 as uuidv4 } from "uuid";
import { selectUser } from "@/pages/Auth/store/selectors";
import { CreateProposal } from "@/pages/OldCommon/interfaces";
import { createDeleteCommonProposal } from "@/pages/OldCommon/store/actions";
Expand Down Expand Up @@ -68,11 +69,15 @@ const DeleteCommonStage: FC<DeleteCommonStageProps> = (props) => {
}

setIsProposalCreating(true);
const proposalId = uuidv4();
const discussionId = uuidv4();
const payload: Omit<
CreateProposal[ProposalsTypes.DELETE_COMMON]["data"],
"type"
> = {
args: {
id: proposalId,
discussionId,
commonId: common.id,
title: `Delete common proposal from ${getUserName(user)}`,
description: deleteCommonData.description,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { FC, useEffect, useState, useMemo } from "react";
import { useDispatch, useSelector } from "react-redux";
import { v4 as uuidv4 } from "uuid";
import { useCommonMembers } from "@/pages/OldCommon/hooks";
import { CreateProposal } from "@/pages/OldCommon/interfaces";
import {
Expand Down Expand Up @@ -133,12 +134,16 @@ const FundsAllocationStage: FC<FundsAllocationStageProps> = (props) => {
: { otherMemberId: fundsAllocationData.otherMemberId };

setIsProposalCreating(true);
const proposalId = uuidv4();
const discussionId = uuidv4();
const description = `${fundsAllocationData.description}\n\nGoal of Payment:\n${fundsAllocationData.goalOfPayment}`;
const payload: Omit<
CreateProposal[ProposalsTypes.FUNDS_ALLOCATION]["data"],
"type"
> = {
args: {
id: proposalId,
discussionId,
description,
amount: {
amount: fundsAllocationData.amount * 100,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { FC, useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { v4 as uuidv4 } from "uuid";
import { selectUser } from "@/pages/Auth/store/selectors";
import { useCommonMembers } from "@/pages/OldCommon/hooks";
import { CreateProposal } from "@/pages/OldCommon/interfaces";
Expand Down Expand Up @@ -74,11 +75,15 @@ const RemoveCircleStage: FC<RemoveCircleStageProps> = (props) => {
}

setIsProposalCreating(true);
const proposalId = uuidv4();
const discussionId = uuidv4();
const payload: Omit<
CreateProposal[ProposalsTypes.REMOVE_CIRCLE]["data"],
"type"
> = {
args: {
id: proposalId,
discussionId,
commonId: common.id,
title: `Remove circle proposal for ${getUserName(
removeCircleData.commonMember.user,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { FC, useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { v4 as uuidv4 } from "uuid";
import { CreateProposal } from "@/pages/OldCommon/interfaces";
import { createSurvey } from "@/pages/OldCommon/store/actions";
import { Loader, Modal } from "@/shared/components";
Expand Down Expand Up @@ -68,9 +69,14 @@ const SurveyStage: FC<SurveyStageProps> = (props) => {
}

setIsProposalCreating(true);

const proposalId = uuidv4();
const discussionId = uuidv4();
const payload: Omit<CreateProposal[ProposalsTypes.SURVEY]["data"], "type"> =
{
args: {
id: proposalId,
discussionId,
description: surveyData.description,
commonId: common.id,
title: surveyData.title,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { v4 as uuidv4 } from "uuid";
import { selectUser } from "@/pages/Auth/store/selectors";
import { Loader } from "@/shared/components";
import { ContributionSourceType, Currency } from "@/shared/models";
Expand Down Expand Up @@ -39,10 +40,14 @@ export default function MembershipRequestCreating(
return;
}

const proposalId = uuidv4();
const discussionId = uuidv4();
dispatch(
createMemberAdmittanceProposal.request({
payload: {
args: {
id: proposalId,
discussionId,
commonId: common.id,
title: `Membership request from ${userName}`,
description: userData.intro,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { FC, useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { v4 as uuidv4 } from "uuid";
import { selectUser } from "@/pages/Auth/store/selectors";
import { DeadSeaUserDetailsFormValuesWithoutUserDetails } from "@/pages/OldCommon/components";
import { useSupportersDataContext } from "@/pages/OldCommon/containers/SupportersContainer/context";
Expand Down Expand Up @@ -106,10 +107,14 @@ const MemberAdmittanceForProjectStep: FC<

const title = `Membership request from ${userName}`;

const proposalId = uuidv4();
const discussionId = uuidv4();
dispatch(
createMemberAdmittanceProposal.request({
payload: {
args: {
id: proposalId,
discussionId,
commonId: parentCommonId,
title,
description: data.supportPlan || title,
Expand Down Expand Up @@ -180,13 +185,17 @@ const MemberAdmittanceForProjectStep: FC<
return;
}

const proposalId = uuidv4();
const discussionId = uuidv4();
try {
const title = `${userName} joins and supports ${circleName}`;
const payload: Omit<
CreateProposal[ProposalsTypes.ASSIGN_CIRCLE]["data"],
"type"
> = {
args: {
id: proposalId,
discussionId,
commonId: parentCommonId,
title,
description: data.supportPlan || title,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { FC, useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { v4 as uuidv4 } from "uuid";
import { selectUser } from "@/pages/Auth/store/selectors";
import { DeadSeaUserDetailsFormValuesWithoutUserDetails } from "@/pages/OldCommon/components";
import { useSupportersDataContext } from "@/pages/OldCommon/containers/SupportersContainer/context";
Expand Down Expand Up @@ -64,10 +65,14 @@ const MemberAdmittanceStep: FC<MemberAdmittanceStepProps> = (props) => {

const title = `Membership request from ${userName}`;

const proposalId = uuidv4();
const discussionId = uuidv4();
dispatch(
createMemberAdmittanceProposal.request({
payload: {
args: {
id: proposalId,
discussionId,
commonId,
title,
description: data.supportPlan || title,
Expand Down
1 change: 1 addition & 0 deletions src/pages/OldCommon/interfaces/CreateDiscussionDto.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CommonLink } from "@/shared/models";

export interface CreateDiscussionDto {
id: string;
title: string;
message: string;
ownerId: string;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/OldCommon/store/saga.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ export function* createDiscussionSaga(
);
}

yield put(startLoading());
// yield put(startLoading());

const discussion = (yield createDiscussion(
action.payload.payload,
Expand Down
Loading

0 comments on commit d0483cf

Please sign in to comment.