Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the inbox items avatars clickable #2240 #2274

Merged
merged 4 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move click handler outside of this component to the parents which use it and pass the callback as onImageClick prop. So the component at least will not know about the dm user and such kind of things which are not related to the component itself.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andreymikhadyuk I'm not sure I understood what's the issue with that. Currently the handleAvatarClick is only being used there, and data like dmUserId is necessary for this. So if it's being used only here, why should we define the function outside and pass it by props...

{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
Loading