Skip to content

Commit

Permalink
Merge branch 'dev' into CW-2256-unread-filtretation-inbox
Browse files Browse the repository at this point in the history
  • Loading branch information
pvm-code authored Oct 31, 2023
2 parents c648c33 + 1905140 commit 330d1f4
Show file tree
Hide file tree
Showing 26 changed files with 77 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FC } from "react";
import { useTranslation } from "react-i18next";
import landingVideoPosterSrc from "@/shared/assets/images/landing-video-poster.jpg";
import landingVideoPosterSrc from "@/shared/assets/images/landing-video-poster.jpeg";
import landingVideoSrc from "@/shared/assets/videos/landing-video.mp4";
import { useIsBigPhoneView } from "@/shared/hooks/viewport";
import { Button, ButtonVariant } from "@/shared/ui-kit";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const CommonMember: FC<CommonMemberProps> = ({
circlesWithHighestTier[circlesWithHighestTier.length - 1];

governanceCircles.forEach((circle) => {
if (!highestMemberCircle.hierarchy) {
if (!highestMemberCircle?.hierarchy) {
return;
}
if (!circle.hierarchy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ const DiscussionFeedCard = forwardRef<FeedItemRef, DiscussionFeedCardProps>(
}

const circleVisibility = governanceCircles
? getVisibilityString(governanceCircles, discussion?.circleVisibility)
? getVisibilityString(governanceCircles, item?.circleVisibility)
: undefined;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { PredefinedTypes } from "@/shared/models";
import { hasPermission } from "@/shared/utils";
import { FeedItemPinAction, GetAllowedItemsOptions } from "../../FeedItem";

const PINNED_ITEMS_LIMIT = 7;

export function checkIsPinUnpinAllowed(
action: FeedItemPinAction,
options: GetAllowedItemsOptions,
Expand All @@ -17,7 +19,7 @@ export function checkIsPinUnpinAllowed(
}

if (action === FeedItemPinAction.Pin) {
const hasReachedPinLimit = pinnedFeedItems.length >= 3;
const hasReachedPinLimit = pinnedFeedItems.length >= PINNED_ITEMS_LIMIT;

if (isDiscussionPinned || hasReachedPinLimit) {
return false;
Expand Down
2 changes: 2 additions & 0 deletions src/pages/commonFeed/CommonFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ const CommonFeedComponent: FC<CommonFeedProps> = (props) => {
loading: areCommonFeedItemsLoading,
hasMore: hasMoreCommonFeedItems,
fetch: fetchCommonFeedItems,
batchNumber,
} = useCommonFeedItems(commonId, commonFeedItemIdsForNotListening);

const {
Expand Down Expand Up @@ -508,6 +509,7 @@ const CommonFeedComponent: FC<CommonFeedProps> = (props) => {
topFeedItems={topFeedItems}
feedItems={commonFeedItems}
loading={areCommonFeedItemsLoading}
batchNumber={batchNumber}
onFetchNext={fetchMoreCommonFeedItems}
renderFeedItemBaseContent={renderFeedItemBaseContent}
onFeedItemUpdate={handleFeedItemUpdate}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import "../../../../styles/sizes";

.content {
position: relative;
flex: 1;
padding: 0 1.5rem;
display: flex;
Expand All @@ -17,6 +18,11 @@
justify-content: center;
}

.infiniteScrollMarker {
position: absolute;
bottom: 50rem;
}

.emptyText {
margin: 0;
font-weight: 500;
Expand Down
18 changes: 18 additions & 0 deletions src/pages/commonFeed/components/FeedLayout/FeedLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import {
MobileProfile,
SplitView,
} from "./components";
import { BATCHES_AMOUNT_TO_PRELOAD } from "./constants";
import { useUserForProfile } from "./hooks";
import {
checkShouldAutoOpenPreview,
Expand Down Expand Up @@ -114,6 +115,7 @@ interface FeedLayoutProps {
topFeedItems?: FeedLayoutItem[];
loading: boolean;
shouldHideContent?: boolean;
batchNumber?: number;
onFetchNext: (feedItemId?: string) => void;
renderFeedItemBaseContent: (props: FeedItemBaseContentProps) => ReactNode;
renderChatChannelItem?: (props: ChatChannelFeedLayoutItemProps) => ReactNode;
Expand Down Expand Up @@ -153,6 +155,7 @@ const FeedLayout: ForwardRefRenderFunction<FeedLayoutRef, FeedLayoutProps> = (
topFeedItems = [],
loading,
shouldHideContent = false,
batchNumber,
onFetchNext,
renderFeedItemBaseContent,
renderChatChannelItem,
Expand Down Expand Up @@ -603,6 +606,16 @@ const FeedLayout: ForwardRefRenderFunction<FeedLayoutRef, FeedLayoutProps> = (
}
}, [isTabletView, shouldAutoExpandItem, activeFeedItemId]);

useEffect(() => {
if (
batchNumber &&
batchNumber >= 1 &&
batchNumber <= BATCHES_AMOUNT_TO_PRELOAD
) {
onFetchNext();
}
}, [batchNumber]);

useImperativeHandle(
ref,
() => ({
Expand Down Expand Up @@ -640,6 +653,11 @@ const FeedLayout: ForwardRefRenderFunction<FeedLayoutRef, FeedLayoutProps> = (
{topContent}
{isContentEmpty && <p className={styles.emptyText}>{emptyText}</p>}
<InfiniteScroll
markerClassName={
allFeedItems && allFeedItems.length > 7
? styles.infiniteScrollMarker
: ""
}
onFetchNext={onFetchNext}
isLoading={loading}
loaderDelay={LOADER_APPEARANCE_DELAY}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const BATCHES_AMOUNT_TO_PRELOAD = 2;
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import React, { FC } from "react";
import { useHistory } from "react-router";
import { useMenuItems } from "@/pages/common/components/CommonTabPanels/components/FeedTab/components/NewStreamButton";
import { useRoutesContext } from "@/shared/contexts";
import { BoldPlusIcon, PlusIcon } from "@/shared/icons";
import { PlusIcon } from "@/shared/icons";
import { CirclesPermissions, CommonMember, Governance } from "@/shared/models";
import {
ButtonIcon,
ButtonVariant,
DesktopMenu,
MobileMenu,
} from "@/shared/ui-kit";
Expand Down
2 changes: 2 additions & 0 deletions src/pages/inbox/BaseInbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const InboxPage: FC<InboxPageProps> = (props) => {
hasMore: hasMoreInboxItems,
fetch: fetchInboxItems,
refetch: refetchInboxItems,
batchNumber,
} = useInboxItems(feedItemIdsForNotListening, {
unread: isActiveUnreadInboxItemsQueryParam,
});
Expand Down Expand Up @@ -265,6 +266,7 @@ const InboxPage: FC<InboxPageProps> = (props) => {
feedItems={inboxItems}
loading={areInboxItemsLoading || !user}
shouldHideContent={!user}
batchNumber={batchNumber}
onFetchNext={fetchMoreInboxItems}
renderFeedItemBaseContent={renderFeedItemBaseContent}
renderChatChannelItem={renderChatChannelItem}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
@import "../../../../../../constants";
@import "../../../../../../styles/sizes";

.buttonIcon {
background-color: transparent;

&:hover {
background-color: $light-gray-1;
}
}

.icon {
width: 0.625rem;
height: 0.625rem;
width: 1rem;
height: 1rem;
color: $c-gray-800;

@include tablet {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
import React, { FC } from "react";
import { BoldPlusIcon, PlusIcon } from "@/shared/icons";
import { ButtonIcon, ButtonVariant } from "@/shared/ui-kit";
import classnames from "classnames";
import { PlusIcon } from "@/shared/icons";
import { ButtonIcon } from "@/shared/ui-kit";
import styles from "./PlusButton.module.scss";

interface PlusButtonProps {
className?: string;
isMobileVersion?: boolean;
onClick?: () => void;
}

const PlusButton: FC<PlusButtonProps> = (props) => {
const { className, isMobileVersion, onClick } = props;
const { className, onClick } = props;

return (
<ButtonIcon
className={className}
variant={
isMobileVersion ? ButtonVariant.Transparent : ButtonVariant.PrimaryGray
}
className={classnames(styles.buttonIcon, className)}
onClick={onClick}
>
{isMobileVersion ? (
<PlusIcon className={styles.icon} />
) : (
<BoldPlusIcon className={styles.icon} />
)}
<PlusIcon className={styles.icon} />
</ButtonIcon>
);
};
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/shared/assets/images/landing-video-poster.jpg
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
text-align: center;
font-size: $xxsmall-2;
color: $c-gray-60;
direction: ltr;
}

.messageName {
Expand Down
3 changes: 2 additions & 1 deletion src/shared/components/Chat/ChatMessage/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ export default function ChatMessage({
<div
className={classNames(styles.messageContent, {
[styles.messageContentCurrentUser]: !isNotCurrentUserMessage,
[styles.messageContentRtl]: isRtlText(discussionMessage.text),
[styles.messageContentRtl]:
!isSystemMessage && isRtlText(discussionMessage.text),
})}
>
{filePreview && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
CommonCreatedSystemMessage,
CommonEditedSystemMessage,
CommonFeedItemCreatedSystemMessage,
CommonFeedType,
CommonMemberAddedSystemMessage,
SystemMessageCommonType,
User,
Expand Down Expand Up @@ -73,8 +72,8 @@ const getCommonCreatedSystemMessageText = async (

if (isThisCommonCreated) {
return [
`This ${getCommonTypeText(systemMessageData.commonType)} was created by `,
userEl,
` created this ${getCommonTypeText(systemMessageData.commonType)}`,
];
}

Expand All @@ -91,7 +90,7 @@ const getCommonCreatedSystemMessageText = async (
""
);

return [userEl, " created the space", commonEl].filter(Boolean);
return ["The ", commonEl, " space was created by ", userEl].filter(Boolean);
};

const getCommonEditedSystemMessageText = async (
Expand All @@ -102,14 +101,15 @@ const getCommonEditedSystemMessageText = async (
const userEl = renderUserMention(user, data);

return [
userEl,
` edited this ${getCommonTypeText(systemMessageData.commonType)}’s `,
`This ${getCommonTypeText(systemMessageData.commonType)}’s `,
renderLink(
(data.getCommonPageAboutTabPath || getCommonPageAboutTabPath)(
systemMessageData.commonId,
),
"info",
),
" was edited by ",
userEl,
];
};

Expand Down Expand Up @@ -156,15 +156,7 @@ const getFeedItemCreatedSystemMessageText = async (
""
);

return [
userEl,
` created the ${
systemMessageData.feedItemType === CommonFeedType.Discussion
? "discussion"
: "proposal"
}`,
titleEl,
].filter(Boolean);
return [titleEl, " was created by ", userEl].filter(Boolean);
};

export const getTextFromSystemMessage = async (
Expand Down
3 changes: 2 additions & 1 deletion src/shared/hooks/useCases/useCommonFeedItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { useDispatch, useSelector } from "react-redux";
import { CommonFeedService } from "@/services";
import { commonActions, FeedItems, selectFeedItems } from "@/store/states";

interface Return extends Pick<FeedItems, "data" | "loading" | "hasMore"> {
interface Return
extends Pick<FeedItems, "data" | "loading" | "hasMore" | "batchNumber"> {
fetch: (feedItemId?: string) => void;
}

Expand Down
3 changes: 2 additions & 1 deletion src/shared/hooks/useCases/useInboxItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import { FeedLayoutItemWithFollowData } from "@/shared/interfaces";
import { FeedItemFollow, FeedItemFollowWithMetadata } from "@/shared/models";
import { inboxActions, InboxItems, selectInboxItems } from "@/store/states";

interface Return extends Pick<InboxItems, "data" | "loading" | "hasMore"> {
interface Return
extends Pick<InboxItems, "data" | "loading" | "hasMore" | "batchNumber"> {
fetch: () => void;
refetch: () => void;
}
Expand Down
6 changes: 4 additions & 2 deletions src/shared/ui-kit/InfiniteScroll/InfiniteScroll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import styles from "./InfiniteScroll.module.scss";
interface InfiniteScrollProps {
isLoading: boolean;
loaderDelay?: number;
markerClassName?: string;
onFetchNext: () => void;
}

const InfiniteScroll: FC<InfiniteScrollProps> = (props) => {
const { isLoading, loaderDelay, onFetchNext, children } = props;
const { isLoading, loaderDelay, markerClassName, onFetchNext, children } =
props;
const [isInnerLoading, setIsInnerLoading] = useState(isLoading);
const markerRef = useRef<HTMLDivElement>(null);
const isMarkerOnScreen = useIntersectionObserver(markerRef.current);
Expand Down Expand Up @@ -39,7 +41,7 @@ const InfiniteScroll: FC<InfiniteScrollProps> = (props) => {
return (
<>
{children}
<div ref={markerRef} />
<div className={markerClassName} ref={markerRef} />
{isLoading && (
<div className={styles.loaderWrapper}>
<Loader delay={loaderDelay} />
Expand Down
2 changes: 1 addition & 1 deletion src/store/states/common/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const getFeedItems = createAsyncAction(
feedItemId?: string;
limit?: number;
},
Omit<FeedItems, "loading">,
Omit<FeedItems, "loading" | "batchNumber">,
Error,
string
>();
Expand Down
2 changes: 2 additions & 0 deletions src/store/states/common/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const initialFeedItems: FeedItems = {
hasMore: false,
firstDocTimestamp: null,
lastDocTimestamp: null,
batchNumber: 0,
};

const initialPinnedFeedItems: PinnedFeedItems = {
Expand Down Expand Up @@ -428,6 +429,7 @@ export const reducer = createReducer<CommonState, Action>(initialState)
data:
payloadData && (nextState.feedItems.data || []).concat(payloadData),
loading: false,
batchNumber: nextState.feedItems.batchNumber + 1,
};
}),
)
Expand Down
1 change: 1 addition & 0 deletions src/store/states/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface FeedItems {
hasMore: boolean;
firstDocTimestamp: Timestamp | null;
lastDocTimestamp: Timestamp | null;
batchNumber: number;
}

export interface PinnedFeedItems {
Expand Down
2 changes: 1 addition & 1 deletion src/store/states/inbox/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const getInboxItems = createAsyncAction(
limit?: number;
unread?: boolean;
},
Omit<InboxItems, "loading">,
Omit<InboxItems, "loading" | "batchNumber">,
Error,
string
>();
Expand Down
Loading

0 comments on commit 330d1f4

Please sign in to comment.