Skip to content

Commit

Permalink
Revert "Merge pull request #2062 from daostack/refactor/circle-visibi…
Browse files Browse the repository at this point in the history
…lity"

This reverts commit 5d8c104.
  • Loading branch information
andreymikhadyuk authored and danielr18 committed Sep 21, 2023
1 parent b0ec8a4 commit 9e020d8
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ export default function DiscussionDetailModal({
);

useEffect(() => {
if (discussion?.circleVisibilityByCommon?.[governance.commonId]) {
if (discussion?.circleVisibility) {
(async () => {
const governanceCircles = await getCommonGovernanceCircles(
governance.id,
);
const filteredByIdCircles = getFilteredByIdCircles(
governanceCircles ? Object.values(governanceCircles) : null,
discussion?.circleVisibilityByCommon?.[governance.commonId],
discussion?.circleVisibility,
);
const names = getCirclesWithLowestTier(filteredByIdCircles)
.map(({ name }) => name)
Expand All @@ -102,7 +102,7 @@ export default function DiscussionDetailModal({
return () => {
dispatch(chatActions.clearCurrentDiscussionMessageReply());
};
}, [governance.id, governance.commonId, discussion]);
}, [governance.id, discussion]);

const sendMessage = useCallback(
(message: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,22 @@ export default function DiscussionItemComponent({
const date = new Date();

useEffect(() => {
if (discussion.circleVisibilityByCommon) {
if (discussion.circleVisibility) {
(async () => {
const governanceCircles = await getCommonGovernanceCircles(
governance.id,
);
const filteredByIdCircles = getFilteredByIdCircles(
governanceCircles ? Object.values(governanceCircles) : null,
discussion.circleVisibilityByCommon?.[governance.commonId],
discussion.circleVisibility,
);
const names = getCirclesWithLowestTier(filteredByIdCircles)
.map(({ name }) => name)
.join(", ");
setCircleNames(names);
})();
}
}, [governance.id, governance.commonId, discussion.circleVisibilityByCommon]);
}, [governance.id, discussion.circleVisibility]);

return (
<div className="discussion-item-wrapper">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,19 @@ export default function CommonDetail(props: CommonDetailProps = {}) {
const circleIds = new Set(
commonMember ? Object.values(commonMember.circles.map) : [],
);
return discussions.filter(({ circleVisibilityByCommon, moderation }) => {
return discussions.filter(({ circleVisibility, moderation }) => {
if (moderation?.flag === ModerationFlags.Hidden) {
return false;
}

const circleVisibility = circleVisibilityByCommon?.[id];
if (!circleVisibility?.length) {
return true;
}
return circleVisibility?.some((discussionCircleId) =>
circleIds.has(discussionCircleId),
);
});
}, [discussions, commonMember, id]);
}, [discussions, commonMember]);

const activeProposals = useMemo(
() => proposals.filter((d) => checkIsCountdownState(d)),
Expand Down
36 changes: 5 additions & 31 deletions src/pages/OldCommon/interfaces/CreateProposalPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,66 +10,40 @@ import {
Survey,
} from "@/shared/models/governance/proposals";

type CircleVisibility = string[] | null;

interface CreateFundsAllocation {
type: ProposalsTypes.FUNDS_ALLOCATION;
args: Omit<FundsAllocation["data"]["args"], "proposerId">;
}

interface CreateMemberAdmittance {
type: ProposalsTypes.MEMBER_ADMITTANCE;
args: Omit<
MemberAdmittance["data"]["args"],
"proposerId" | "circleVisibilityByCommon"
> & {
args: Omit<MemberAdmittance["data"]["args"], "proposerId"> & {
contributionSourceType?: ContributionSourceType;
feeMonthly: PaymentAmount | null;
feeOneTime: PaymentAmount | null;
fromSupportersFlow?: boolean;
receiveEmails?: boolean;
userWhatsapp?: boolean;
circleVisibility?: CircleVisibility;
};
}

interface CreateAssignCircle {
type: ProposalsTypes.ASSIGN_CIRCLE;
args: Omit<
AssignCircle["data"]["args"],
"proposerId" | "circleVisibilityByCommon"
> & {
circleVisibility?: CircleVisibility;
};
args: Omit<AssignCircle["data"]["args"], "proposerId">;
}
interface CreateRemoveCircle {
type: ProposalsTypes.REMOVE_CIRCLE;
args: Omit<
RemoveCircle["data"]["args"],
"proposerId" | "circleVisibilityByCommon"
> & {
circleVisibility?: CircleVisibility;
};
args: Omit<RemoveCircle["data"]["args"], "proposerId">;
}

interface CreateSurvey {
type: ProposalsTypes.SURVEY;
args: Omit<
Survey["data"]["args"],
"proposerId" | "circleVisibilityByCommon"
> & {
circleVisibility?: CircleVisibility;
};
args: Omit<Survey["data"]["args"], "proposerId">;
}

interface CreateDeleteCommon {
type: ProposalsTypes.DELETE_COMMON;
args: Omit<
DeleteCommon["data"]["args"],
"proposerId" | "circleVisibilityByCommon"
> & {
circleVisibility?: CircleVisibility;
};
args: Omit<DeleteCommon["data"]["args"], "proposerId">;
}

interface Request<P, R> {
Expand Down
7 changes: 2 additions & 5 deletions src/pages/common/components/ChatComponent/ChatComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,9 @@ export default function ChatComponent({

useEffect(() => {
if (commonId && !isChatChannel) {
fetchDiscussionUsers(
commonId,
discussion?.circleVisibilityByCommon?.[commonId],
);
fetchDiscussionUsers(commonId, discussion?.circleVisibility);
}
}, [commonId, discussion?.circleVisibilityByCommon]);
}, [commonId, discussion?.circleVisibility]);

useEffect(() => {
if (chatChannel?.id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,7 @@ const DiscussionFeedCard = forwardRef<FeedItemRef, DiscussionFeedCardProps>(
}

const circleVisibility = governanceCircles
? getVisibilityString(
governanceCircles,
discussion?.circleVisibilityByCommon?.[commonId],
)
? getVisibilityString(governanceCircles, discussion?.circleVisibility)
: undefined;

return (
Expand Down
2 changes: 1 addition & 1 deletion src/shared/models/Discussion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface Discussion extends BaseEntity, SoftDeleteEntity {
* If array is empty, everyone in common can view.
* If discussion is attached to a proposal, this field will be not exist.
*/
circleVisibilityByCommon?: Record<string, string[]>;
circleVisibility?: string[];
}

export interface DiscussionWithOwnerInfo extends Discussion {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface BasicArgsProposal {

links: CommonLink[];

circleVisibilityByCommon?: Record<string, string[]> | null;
circleVisibility?: string[] | null;
}

export interface ProposalImage {
Expand Down
13 changes: 6 additions & 7 deletions src/shared/utils/firebase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ interface FirebaseError extends Error {
}

firebase.initializeApp(config.firebase);
firebase
.firestore()
.enablePersistence()
.catch((error) => {
console.error("Error enabling persistence", error);
});

if (REACT_APP_ENV === Environment.Local) {
firebase.auth().useEmulator(local.firebase.authDomain);
Expand All @@ -20,13 +26,6 @@ if (REACT_APP_ENV === Environment.Local) {
"localhost",
Number(local.firebase.databaseURL.split(/:/g)[2]),
);
} else {
firebase
.firestore()
.enablePersistence()
.catch((error) => {
console.error("Error enabling persistence", error);
});
}

export const isFirebaseError = (error: any): error is FirebaseError => {
Expand Down

0 comments on commit 9e020d8

Please sign in to comment.