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

Mobile add breadcrumb to expanded cards info #2295 #2330

Merged
merged 13 commits into from
Nov 30, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useChatContext } from "@/pages/common/components/ChatComponent";
import { Modal } from "@/shared/components";
import { useIsTabletView } from "@/shared/hooks/viewport";
import { ModalType, FeedLayoutItemChangeData } from "@/shared/interfaces";
import { Breadcrumbs } from "@/shared/layouts/MultipleSpacesLayout/components/Header/components";
import { Circles, CommonFeed } from "@/shared/models";
import styles from "./FeedItemPreviewModal.module.scss";

Expand Down Expand Up @@ -72,6 +73,7 @@ const FeedItemPreviewModal: FC<FeedItemPreviewModalProps> = (props) => {
>
{selectedFeedItem && (
<>
<Breadcrumbs itemsWithMenus={false} />
{title && <h3 className={styles.itemTitle}>{title}</h3>}
<FeedItem
commonId={commonId}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { FC } from "react";
import { useSelector } from "react-redux";
import { InboxItemType } from "@/shared/constants";
import { useIsTabletView } from "@/shared/hooks/viewport";
import { selectMultipleSpacesLayoutBreadcrumbs } from "@/store/states";
import { ChatChannelBreadcrumbs, FeedItemBreadcrumbs } from "./components";

Expand All @@ -11,15 +12,18 @@ interface BreadcrumbsProps {
const Breadcrumbs: FC<BreadcrumbsProps> = (props) => {
const { itemsWithMenus = true } = props;
const breadcrumbs = useSelector(selectMultipleSpacesLayoutBreadcrumbs);
const isMobileView = useIsTabletView();

if (breadcrumbs?.type === InboxItemType.ChatChannel) {
return <ChatChannelBreadcrumbs breadcrumbs={breadcrumbs} />;
}
if (breadcrumbs?.type === InboxItemType.FeedItemFollow) {
const truncate = isMobileView && breadcrumbs.items.length >= 3;
return (
<FeedItemBreadcrumbs
breadcrumbs={breadcrumbs}
itemsWithMenus={itemsWithMenus}
truncate={truncate}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ButtonIcon, UserAvatar } from "@/shared/components";
import { RightArrowThinIcon } from "@/shared/icons";
import { ContextMenuRef } from "@/shared/ui-kit";
import { ProjectsStateItem } from "@/store/states";
import { truncateBreadcrumbName } from "../../utils";
import { BreadcrumbsMenu } from "../BreadcrumbsMenu";
import styles from "./ActiveBreadcrumbsItem.module.scss";

Expand All @@ -13,6 +14,7 @@ export interface ActiveBreadcrumbsItemProps {
commonIdToAddProject?: string | null;
withMenu?: boolean;
isLoading?: boolean;
truncate?: boolean;
}

const ActiveBreadcrumbsItem: FC<ActiveBreadcrumbsItemProps> = (props) => {
Expand All @@ -23,6 +25,7 @@ const ActiveBreadcrumbsItem: FC<ActiveBreadcrumbsItemProps> = (props) => {
commonIdToAddProject,
withMenu = true,
isLoading = false,
truncate = false,
} = props;
const itemsButtonRef = useRef<HTMLButtonElement>(null);
const contextMenuRef = useRef<ContextMenuRef>(null);
Expand All @@ -44,7 +47,9 @@ const ActiveBreadcrumbsItem: FC<ActiveBreadcrumbsItemProps> = (props) => {
userName={name}
/>
)}
<span className={styles.name}>{name}</span>
<span className={styles.name}>
{truncate ? truncateBreadcrumbName(name) : name}
</span>
{(items.length > 0 || commonIdToAddProject) && withMenu && (
<ButtonIcon
ref={itemsButtonRef}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import "../../../../../../../../../constants";
@import "../../../../../../../../../styles/sizes";

.button {
--breadcrumbs-color: #{$c-gray-40};
Expand Down Expand Up @@ -27,3 +28,13 @@
--breadcrumbs-bg-color: #{$c-gray-20};
}
}

@include tablet {
.li {
&:first-child {
.button {
padding-left: 0;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useHistory } from "react-router";
import { useRoutesContext } from "@/shared/contexts";
import { ContextMenuRef } from "@/shared/ui-kit";
import { ProjectsStateItem } from "@/store/states";
import { truncateBreadcrumbName } from "../../utils";
import { BreadcrumbsMenu } from "../BreadcrumbsMenu";
import styles from "./BreadcrumbsItem.module.scss";

Expand All @@ -13,6 +14,7 @@ export interface BreadcrumbsItemProps {
onCommonCreate?: () => void;
withMenu?: boolean;
isLoading?: boolean;
truncate?: boolean;
onClick?: () => void;
}

Expand All @@ -24,6 +26,7 @@ const BreadcrumbsItem: FC<BreadcrumbsItemProps> = (props) => {
onCommonCreate,
withMenu = true,
isLoading = false,
truncate = false,
onClick,
} = props;
const history = useHistory();
Expand All @@ -44,9 +47,9 @@ const BreadcrumbsItem: FC<BreadcrumbsItemProps> = (props) => {
};

return (
<li ref={containerRef}>
<li ref={containerRef} className={styles.li}>
<button className={styles.button} onClick={handleButtonClick}>
{activeItem.name}
{truncate ? truncateBreadcrumbName(activeItem.name) : activeItem.name}
</button>
{withMenu && (
<BreadcrumbsMenu
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { FC } from "react";
import { useIsTabletView } from "@/shared/hooks/viewport";
import { MultipleSpacesLayoutChatChannelBreadcrumbs } from "@/store/states";
import { ActiveBreadcrumbsItem } from "../ActiveBreadcrumbsItem";
import feedItemBreadcrumbsStyles from "../FeedItemBreadcrumbs/FeedItemBreadcrumbs.module.scss";
Expand All @@ -9,12 +10,14 @@ interface ChatChannelBreadcrumbsProps {

const ChatChannelBreadcrumbs: FC<ChatChannelBreadcrumbsProps> = (props) => {
const { breadcrumbs } = props;
const isMobileView = useIsTabletView();

return (
<ul className={feedItemBreadcrumbsStyles.container}>
<ActiveBreadcrumbsItem
name={breadcrumbs.activeItem.name}
image={breadcrumbs.activeItem.image}
truncate={isMobileView}
/>
</ul>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import "../../../../../../../../../constants";
@import "../../../../../../../../../styles/sizes";

.container {
margin: 0;
Expand All @@ -10,3 +11,9 @@
overflow-x: auto;
overflow-y: hidden;
}

@include tablet {
roienatan marked this conversation as resolved.
Show resolved Hide resolved
.container {
overflow: hidden;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { FC, useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import { CommonEvent, CommonEventEmitter } from "@/events";
import { CommonService } from "@/services";
import { useIsTabletView } from "@/shared/hooks/viewport";
import {
commonLayoutActions,
MultipleSpacesLayoutFeedItemBreadcrumbs,
Expand All @@ -16,13 +17,18 @@ import styles from "./FeedItemBreadcrumbs.module.scss";
interface FeedItemBreadcrumbsProps {
breadcrumbs: MultipleSpacesLayoutFeedItemBreadcrumbs;
itemsWithMenus: boolean;
truncate: boolean;
}

const FeedItemBreadcrumbs: FC<FeedItemBreadcrumbsProps> = (props) => {
const { breadcrumbs, itemsWithMenus } = props;
const { breadcrumbs, itemsWithMenus, truncate } = props;
const dispatch = useDispatch();
const currentLayoutCommonId = useSelector(selectCommonLayoutCommonId);
const goToCreateCommon = useGoToCreateCommon();
const isMobileView = useIsTabletView();
const breadcrumbsItems = truncate
? [breadcrumbs.items[0], breadcrumbs.items[breadcrumbs.items.length - 1]]
: breadcrumbs.items;

const handleItemClick = (item: ProjectsStateItem) => {
if (
Expand Down Expand Up @@ -60,13 +66,20 @@ const FeedItemBreadcrumbs: FC<FeedItemBreadcrumbsProps> = (props) => {
return (
<ul className={styles.container}>
{!breadcrumbs.areItemsLoading &&
breadcrumbs.items.map((item, index) => (
breadcrumbsItems.map((item, index) => (
<React.Fragment key={item.commonId}>
{index > 0 && <Separator />}
{truncate && index === 1 && (
<>
...
<Separator />
</>
)}
<FeedBreadcrumbsItem
activeItem={item}
onCommonCreate={index === 0 ? goToCreateCommon : undefined}
withMenu={itemsWithMenus}
truncate={isMobileView}
onClick={() => handleItemClick(item)}
/>
</React.Fragment>
Expand All @@ -76,12 +89,15 @@ const FeedItemBreadcrumbs: FC<FeedItemBreadcrumbsProps> = (props) => {
{!breadcrumbs.areItemsLoading && breadcrumbs.items.length > 0 && (
<Separator />
)}
<ActiveFeedBreadcrumbsItem
activeItemId={breadcrumbs.activeCommonId}
name={breadcrumbs.activeItem.name}
image={breadcrumbs.activeItem.image}
withMenu={itemsWithMenus}
/>
{!isMobileView && (
<ActiveFeedBreadcrumbsItem
activeItemId={breadcrumbs.activeCommonId}
name={breadcrumbs.activeItem.name}
image={breadcrumbs.activeItem.image}
withMenu={itemsWithMenus}
truncate={isMobileView}
/>
)}
</>
)}
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import {
} from "../../../ActiveBreadcrumbsItem";

interface ActiveFeedBreadcrumbsItemProps
extends Pick<ActiveBreadcrumbsItemProps, "name" | "image" | "withMenu"> {
extends Pick<
ActiveBreadcrumbsItemProps,
"name" | "image" | "withMenu" | "truncate"
> {
activeItemId: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {

type FeedBreadcrumbsItemProps = Pick<
BreadcrumbsItemProps,
"activeItem" | "onCommonCreate" | "withMenu" | "onClick"
"activeItem" | "onCommonCreate" | "withMenu" | "onClick" | "truncate"
>;

const getItemsByParentId = (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { truncate } from "lodash";

const OMISSION = "...";
const MOBILE_MAXIMUM_ITEM_LENGTH = 10 + OMISSION.length;

export const truncateBreadcrumbName = (itemName: string) => {
return truncate(itemName, {
length: MOBILE_MAXIMUM_ITEM_LENGTH,
omission: OMISSION,
});
};
Loading