-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2098 from daostack/feature/CW-2045-enable-follow-…
…space Enable follow\unfollow space #2045
- Loading branch information
Showing
34 changed files
with
448 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/pages/commonFeed/components/HeaderContent/components/ActionsButton/ActionsButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React, { FC } from "react"; | ||
import { ShareModal } from "@/shared/components"; | ||
import { useModal } from "@/shared/hooks"; | ||
import { CommonFollowState } from "@/shared/hooks/useCases/useCommonFollow"; | ||
import { CirclesPermissions, Common, CommonMember } from "@/shared/models"; | ||
import { DesktopMenu, MenuButton } from "@/shared/ui-kit"; | ||
import { StaticLinkType, generateStaticShareLink } from "@/shared/utils"; | ||
import { useMenuItems } from "./hooks"; | ||
|
||
interface ActionsButtonProps { | ||
common: Common; | ||
commonMember: (CommonMember & CirclesPermissions) | null; | ||
commonFollow: CommonFollowState; | ||
isMobileVersion: boolean; | ||
} | ||
|
||
const ActionsButton: FC<ActionsButtonProps> = (props) => { | ||
const { common, commonMember, commonFollow, isMobileVersion } = props; | ||
const { | ||
isShowing: isShareModalOpen, | ||
onOpen: onShareModalOpen, | ||
onClose: onShareModalClose, | ||
} = useModal(false); | ||
const items = useMenuItems( | ||
{ | ||
common, | ||
commonMember, | ||
isMobileVersion, | ||
isFollowInProgress: commonFollow.isFollowInProgress, | ||
}, | ||
{ | ||
share: onShareModalOpen, | ||
onFollowToggle: commonFollow.onFollowToggle, | ||
}, | ||
); | ||
const shareLink = generateStaticShareLink(StaticLinkType.Common, common); | ||
|
||
return ( | ||
<> | ||
{items.length > 0 && ( | ||
<DesktopMenu triggerEl={<MenuButton />} items={items} /> | ||
)} | ||
<ShareModal | ||
sourceUrl={shareLink} | ||
isShowing={isShareModalOpen} | ||
onClose={onShareModalClose} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default ActionsButton; |
1 change: 1 addition & 0 deletions
1
src/pages/commonFeed/components/HeaderContent/components/ActionsButton/hooks/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./useMenuItems"; |
45 changes: 45 additions & 0 deletions
45
...pages/commonFeed/components/HeaderContent/components/ActionsButton/hooks/useMenuItems.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from "react"; | ||
import { CommonFollowState } from "@/shared/hooks/useCases"; | ||
import { FollowIcon, Share3Icon, UnfollowIcon } from "@/shared/icons"; | ||
import { MenuItem as Item } from "@/shared/interfaces"; | ||
import { CommonFeedMenuItem } from "../../../../../constants"; | ||
import { | ||
Options as GetAllowedItemsOptions, | ||
getAllowedItems, | ||
} from "../../../../../utils"; | ||
|
||
interface Actions { | ||
share: () => void; | ||
onFollowToggle: CommonFollowState["onFollowToggle"]; | ||
} | ||
|
||
export const useMenuItems = ( | ||
options: GetAllowedItemsOptions, | ||
actions: Actions, | ||
): Item[] => { | ||
const { common } = options; | ||
const { share, onFollowToggle } = actions; | ||
|
||
const items: Item[] = [ | ||
{ | ||
id: CommonFeedMenuItem.Share, | ||
text: "Share", | ||
onClick: share, | ||
icon: <Share3Icon />, | ||
}, | ||
{ | ||
id: CommonFeedMenuItem.Follow, | ||
text: `Follow ${common.name}`, | ||
onClick: () => onFollowToggle(), | ||
icon: <FollowIcon />, | ||
}, | ||
{ | ||
id: CommonFeedMenuItem.Mute, | ||
text: `Unfollow ${common.name}`, | ||
onClick: () => onFollowToggle(), | ||
icon: <UnfollowIcon />, | ||
}, | ||
]; | ||
|
||
return getAllowedItems(items, options); | ||
}; |
1 change: 1 addition & 0 deletions
1
src/pages/commonFeed/components/HeaderContent/components/ActionsButton/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as ActionsButton } from "./ActionsButton"; |
1 change: 1 addition & 0 deletions
1
src/pages/commonFeed/components/HeaderContent/components/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./NewStreamButton"; | ||
export * from "./ShareButton"; | ||
export * from "./ActionsButton"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum CommonFeedMenuItem { | ||
Share = "share", | ||
Follow = "follow", | ||
Mute = "mute", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const MIN_CHAT_WIDTH = 384; | ||
export * from "./commonFeedMenuItem"; | ||
export * from "./minChatWidth"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const MIN_CHAT_WIDTH = 384; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { MenuItem as Item } from "@/shared/interfaces"; | ||
import { CirclesPermissions, Common, CommonMember } from "@/shared/models"; | ||
import { CommonFeedMenuItem } from "../constants"; | ||
|
||
export interface Options { | ||
common: Common; | ||
commonMember: (CommonMember & CirclesPermissions) | null; | ||
isFollowInProgress: boolean; | ||
isMobileVersion: boolean; | ||
} | ||
|
||
const MENU_ITEM_TO_CHECK_FUNCTION_MAP: Record< | ||
CommonFeedMenuItem, | ||
(options: Options) => boolean | ||
> = { | ||
[CommonFeedMenuItem.Share]: ({ isMobileVersion }) => !isMobileVersion, | ||
[CommonFeedMenuItem.Follow]: ({ commonMember, isFollowInProgress }) => | ||
!isFollowInProgress && Boolean(commonMember && !commonMember.isFollowing), | ||
[CommonFeedMenuItem.Mute]: ({ commonMember, isFollowInProgress }) => | ||
!isFollowInProgress && Boolean(commonMember?.isFollowing), | ||
}; | ||
|
||
export const getAllowedItems = (items: Item[], options: Options): Item[] => | ||
items.filter(({ id }) => MENU_ITEM_TO_CHECK_FUNCTION_MAP[id](options)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./generateSplitViewMaxSizeGetter"; | ||
export * from "./getLastMessage"; | ||
export * from "./getAllowedItems"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum DocChange { | ||
Added = "added", | ||
Removed = "removed", | ||
Modified = "modified", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.