Skip to content

Commit

Permalink
fix more items text for spaces where there is less items than limited
Browse files Browse the repository at this point in the history
  • Loading branch information
andreymikhadyuk committed Apr 4, 2024
1 parent 7fdb4fa commit 5f404f4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const ProjectFeedItem: FC<ProjectFeedItemProps> = (props) => {
const commonId = item.data.id;
const {
data: feedItems,
hasMoreItems,
fetched,
fetchFeedItems,
onFeedItemUpdate,
Expand Down Expand Up @@ -196,13 +197,15 @@ export const ProjectFeedItem: FC<ProjectFeedItemProps> = (props) => {
level={level}
onFeedItemUpdate={onFeedItemUpdate}
/>
<NavLink
className={styles.moreItemsTextContainer}
to={commonPath}
>
More items in {common.name}
<OpenIcon className={styles.moreItemsTextIcon} />
</NavLink>
{hasMoreItems && (
<NavLink
className={styles.moreItemsTextContainer}
to={commonPath}
>
More items in {common.name}
<OpenIcon className={styles.moreItemsTextIcon} />
</NavLink>
)}
</>
)}
</CommonCard>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const ITEMS_LIMIT = 5;
type State = LoadingState<FeedItemFollowLayoutItem[]>;

interface Return extends State {
hasMoreItems: boolean;
fetchFeedItems: () => void;
onFeedItemUpdate: (item: CommonFeed, isRemoved: boolean) => void;
}
Expand All @@ -42,6 +43,7 @@ export const useFeedItems = (
fetched: false,
data: [],
});
const [hasMoreItems, setHasMoreItems] = useState(false);
const feedState = useSelector(selectFeedStateByCommonId(commonId));

const updateCachedFeedState = (
Expand Down Expand Up @@ -94,6 +96,7 @@ export const useFeedItems = (
fetched: true,
data: cachedFeedItems.slice(0, ITEMS_LIMIT),
});
setHasMoreItems(cachedFeedItems.length > ITEMS_LIMIT);
} else {
setState({
loading: true,
Expand All @@ -110,7 +113,7 @@ export const useFeedItems = (
await Promise.all([
CommonFeedService.getCommonFeedItemsByUpdatedAt(commonId, userId, {
commonMember,
limit: ITEMS_LIMIT,
limit: ITEMS_LIMIT + 2,
}),
CommonFeedService.getCommonPinnedFeedItems(commonId),
]);
Expand All @@ -129,19 +132,16 @@ export const useFeedItems = (
}));

if (currentLoadingIdRef.current === loadingId) {
const finalItems = [...convertedPinnedFeedItems, ...convertedFeedItems];

setState({
loading: false,
fetched: true,
data: [...convertedPinnedFeedItems, ...convertedFeedItems].slice(
0,
ITEMS_LIMIT,
),
data: finalItems.slice(0, ITEMS_LIMIT),
});
setHasMoreItems(finalItems.length > ITEMS_LIMIT);

if (
cachedFeedItems.length <
convertedFeedItems.length + convertedPinnedFeedItems.length
) {
if (cachedFeedItems.length < finalItems.length) {
updateCachedFeedState(convertedFeedItems, convertedPinnedFeedItems);
}
}
Expand Down Expand Up @@ -220,6 +220,7 @@ export const useFeedItems = (

return {
...state,
hasMoreItems,
fetchFeedItems,
onFeedItemUpdate: handleFeedItemUpdate,
};
Expand Down

0 comments on commit 5f404f4

Please sign in to comment.