Skip to content

Commit

Permalink
Merge pull request #2274 from daostack/cw-2240-inbox-items-avatar-cli…
Browse files Browse the repository at this point in the history
…ckable

Make the inbox items avatars clickable #2240
  • Loading branch information
andreymikhadyuk authored Nov 7, 2023
2 parents 3495fc3 + 1e898bc commit 4a38a0e
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ const DiscussionFeedCard = forwardRef<FeedItemRef, DiscussionFeedCardProps>(
isPreviewMode={isPreviewMode}
isPinned={isPinned}
commonName={commonName}
commonId={commonId}
image={commonImage}
imageAlt={`${commonName}'s image`}
isProject={isProject}
Expand Down
3 changes: 3 additions & 0 deletions src/pages/common/components/FeedCard/FeedCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type FeedCardProps = PropsWithChildren<{
lastMessage?: TextEditorValue;
isPreviewMode?: boolean;
commonName?: string;
commonId?: string;
image?: string;
imageAlt?: string;
isProject?: boolean;
Expand Down Expand Up @@ -70,6 +71,7 @@ export const FeedCard = forwardRef<FeedCardRef, FeedCardProps>((props, ref) => {
lastMessage,
isPreviewMode = true,
commonName,
commonId,
image,
imageAlt,
isProject,
Expand Down Expand Up @@ -194,6 +196,7 @@ export const FeedCard = forwardRef<FeedCardRef, FeedCardProps>((props, ref) => {
lastMessage: !isLoading ? lastMessage : undefined,
menuItems,
commonName,
commonId,
image,
imageAlt,
isProject,
Expand Down
2 changes: 2 additions & 0 deletions src/pages/common/components/FeedItem/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface FeedItemBaseContentProps {
seen?: boolean;
ownerId?: string;
commonName?: string;
commonId?: string;
renderImage?: (className?: string) => ReactNode;
renderLeftContent?: () => ReactNode;
image?: string;
Expand All @@ -42,6 +43,7 @@ export interface FeedItemBaseContentProps {
hasImages?: boolean;
isLoading?: boolean;
shouldHideBottomContent?: boolean;
dmUserId?: string;
hasUnseenMention?: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ const ProposalFeedCard = forwardRef<FeedItemRef, ProposalFeedCardProps>(
seen={feedItemUserMetadata?.seen ?? !isFeedItemUserMetadataFetched}
menuItems={menuItems}
ownerId={item.userId}
commonId={commonId}
hasUnseenMention={
feedItemUserMetadata?.hasUnseenMention ??
!isFeedItemUserMetadataFetched
Expand Down
1 change: 0 additions & 1 deletion src/pages/commonFeed/components/FeedLayout/FeedLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ import {
import { InfiniteScroll, TextEditorValue } from "@/shared/ui-kit";
import {
addQueryParam,
checkIsProject,
deleteQueryParam,
getParamsFromOneOfRoutes,
getUserName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export const ChatChannelItem: FC<ChatChannelFeedLayoutItemProps> = (props) => {
ownerId={userId}
renderImage={renderImage}
isImageRounded
dmUserId={dmUserId}
/>
);
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import React, { FC, MouseEventHandler, useRef, useState } from "react";
import { useHistory } from "react-router-dom";
import classNames from "classnames";
import { useLongPress } from "use-long-press";
import { FeedCardTags, FeedItemBaseContentProps } from "@/pages/common";
import {
FeedCardTags,
FeedItemBaseContentProps,
useFeedItemContext,
} from "@/pages/common";
import { useRoutesContext } from "@/shared/contexts";
import { PredefinedTypes } from "@/shared/models";
import {
ContextMenu,
Expand Down Expand Up @@ -36,11 +42,16 @@ export const FeedItemBaseContent: FC<FeedItemBaseContentProps> = (props) => {
isImageRounded,
isProject,
discussionPredefinedType,
dmUserId,
commonId,
hasUnseenMention,
} = props;
const history = useHistory();
const { getCommonPagePath } = useRoutesContext();
const contextMenuRef = useRef<ContextMenuRef>(null);
const [isLongPressing, setIsLongPressing] = useState(false);
const [isLongPressed, setIsLongPressed] = useState(false);
const { onUserSelect } = useFeedItemContext();
const isContextMenuEnabled = Boolean(menuItems && menuItems.length > 0);
const finalTitle =
discussionPredefinedType === PredefinedTypes.General && commonName
Expand Down Expand Up @@ -98,6 +109,14 @@ export const FeedItemBaseContent: FC<FeedItemBaseContentProps> = (props) => {
}
};

const handleAvatarClick = () => {
if (onUserSelect && dmUserId) {
onUserSelect(dmUserId);
} else if (commonId) {
history.push(getCommonPagePath(commonId));
}
};

return (
<div
className={classNames(styles.container, {
Expand All @@ -109,14 +128,16 @@ export const FeedItemBaseContent: FC<FeedItemBaseContentProps> = (props) => {
onContextMenu={handleContextMenu}
{...getLongPressProps()}
>
{renderImage?.(imageClassName) || (
<CommonAvatar
name={commonName}
src={image}
className={imageClassName}
alt={imageAlt}
/>
)}
<div onClick={handleAvatarClick}>
{renderImage?.(imageClassName) || (
<CommonAvatar
name={commonName}
src={image}
className={imageClassName}
alt={imageAlt}
/>
)}
</div>
<div className={styles.content}>
<div className={styles.topContent}>
<p
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
width: 1.5rem;
height: 1.5rem;
color: inherit;
}
}
2 changes: 1 addition & 1 deletion src/pages/inbox/components/InboxFilterButton/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default as InboxFilterButton } from "./InboxFilterButton";
export { default as InboxFilterButton } from "./InboxFilterButton";
2 changes: 1 addition & 1 deletion src/shared/hooks/useCases/useInboxItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const useInboxItems = (
const refetch = () => {
dispatch(inboxActions.resetInboxItems());
fetch();
}
};

useEffect(() => {
if (!inboxItems.firstDocTimestamp || !userId) {
Expand Down

0 comments on commit 4a38a0e

Please sign in to comment.