-
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 #2164 from daostack/CW-2048-add-actions-menu-to-dms
Add action menu for dms with mark as read\unread functionality #2048
- Loading branch information
Showing
10 changed files
with
89 additions
and
7 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
4 changes: 4 additions & 0 deletions
4
src/pages/inbox/components/ChatChannelItem/constants/chatChannelMenuItems.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,4 @@ | ||
export enum ChatChannelMenuItem { | ||
MarkUnread = "markUnread", | ||
MarkRead = "markRead", | ||
} |
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 "./chatChannelMenuItems"; |
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 * from "./useChatChannelSubscription"; | ||
export * from "./useMenuItems"; |
42 changes: 42 additions & 0 deletions
42
src/pages/inbox/components/ChatChannelItem/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,42 @@ | ||
import React from "react"; | ||
import { ChatService } from "@/services"; | ||
import { Message3Icon } from "@/shared/icons"; | ||
import { ContextMenuItem as Item } from "@/shared/interfaces"; | ||
import { ChatChannelMenuItem } from "../constants"; | ||
import { getAllowedItems, Options as GetAllowedItemsOptions } from "../utils"; | ||
|
||
export const useMenuItems = (options: GetAllowedItemsOptions): Item[] => { | ||
const { chatChannelUserStatus } = options; | ||
const items: Item[] = [ | ||
{ | ||
id: ChatChannelMenuItem.MarkUnread, | ||
text: "Mark as unread", | ||
onClick: async () => { | ||
if (!chatChannelUserStatus) { | ||
return; | ||
} | ||
|
||
await ChatService.markChatChannelAsUnseen( | ||
chatChannelUserStatus.chatChannelId, | ||
); | ||
}, | ||
icon: <Message3Icon />, | ||
}, | ||
{ | ||
id: ChatChannelMenuItem.MarkRead, | ||
text: "Mark as read", | ||
onClick: async () => { | ||
if (!chatChannelUserStatus) { | ||
return; | ||
} | ||
|
||
await ChatService.markChatChannelAsSeen( | ||
chatChannelUserStatus.chatChannelId, | ||
); | ||
}, | ||
icon: <Message3Icon />, | ||
}, | ||
]; | ||
|
||
return getAllowedItems(items, options); | ||
}; |
20 changes: 20 additions & 0 deletions
20
src/pages/inbox/components/ChatChannelItem/utils/getAllowedItems.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,20 @@ | ||
import { ContextMenuItem as Item } from "@/shared/interfaces"; | ||
import { ChatChannelUserStatus } from "@/shared/models"; | ||
import { ChatChannelMenuItem } from "../constants"; | ||
|
||
export interface Options { | ||
chatChannelUserStatus: ChatChannelUserStatus | null; | ||
} | ||
|
||
const MENU_ITEM_TO_CHECK_FUNCTION_MAP: Record< | ||
ChatChannelMenuItem, | ||
(options: Options) => boolean | ||
> = { | ||
[ChatChannelMenuItem.MarkUnread]: ({ chatChannelUserStatus }) => | ||
Boolean(chatChannelUserStatus?.seen), | ||
[ChatChannelMenuItem.MarkRead]: ({ chatChannelUserStatus }) => | ||
Boolean(chatChannelUserStatus && !chatChannelUserStatus.seen), | ||
}; | ||
|
||
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 +1,2 @@ | ||
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