Skip to content

Commit

Permalink
Add share to swipe options
Browse files Browse the repository at this point in the history
  • Loading branch information
rsammelson committed Jul 28, 2023
1 parent 1d44991 commit 706d7e8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
42 changes: 34 additions & 8 deletions src/features/shared/sliding/BaseSlidingVote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
eyeOffOutline,
eyeOutline,
mailUnread,
shareOutline,
} from "ionicons/icons";
import React, { useCallback, useContext, useMemo } from "react";
import SlidingItem, { ActionList, SlidingItemAction } from "./SlidingItem";
Expand All @@ -27,11 +28,16 @@ import {
import { voteError } from "../../../helpers/toastMessages";
import { saveComment, voteOnComment } from "../../comment/commentSlice";
import { PageContext } from "../../auth/PageContext";
import { SwipeAction, SwipeActions } from "../../../services/db";
import {
OSwipeActionAll,
SwipeAction,
SwipeActions,
} from "../../../services/db";
import useCollapseRootComment from "../../comment/useCollapseRootComment";
import { getInboxItemId, markRead } from "../../inbox/inboxSlice";
import { CommentsContext } from "../../comment/CommentsContext";
import styled from "@emotion/styled";
import { Share } from "../../post/shared/Share";

const StyledItemContainer = styled.div`
--ion-item-border-color: transparent;
Expand Down Expand Up @@ -196,6 +202,9 @@ function BaseSlidingVoteInternal({
: undefined;
}, [presentLoginIfNeeded, isHidden, onHide]);

const shareAction: React.MutableRefObject<(() => void) | null> =
React.useRef(null);

const collapseRootComment = useCollapseRootComment(
!isPost ? item : undefined,
rootIndex
Expand Down Expand Up @@ -266,6 +275,11 @@ function BaseSlidingVoteInternal({
},
save: saveAction,
hide: hideAction,
share: {
icon: shareOutline,
trigger: () => shareAction.current?.(),
bgColor: "secondary",
},
collapse: collapseAction,
mark_unread: markUnreadAction,
};
Expand Down Expand Up @@ -295,13 +309,25 @@ function BaseSlidingVoteInternal({
[disableRightSwipes, allActions, actions]
);

const shareUsed = useMemo(
() =>
actions.start === OSwipeActionAll.Share ||
actions.farStart === OSwipeActionAll.Share ||
actions.end === OSwipeActionAll.Share ||
actions.farEnd === OSwipeActionAll.Share,
[actions]
);

return (
<SlidingItem
startActions={startActions}
endActions={endActions}
className={className}
>
{children}
</SlidingItem>
<>
<SlidingItem
startActions={startActions}
endActions={endActions}
className={className}
>
{children}
</SlidingItem>
{shareUsed && isPost && <Share share={shareAction} post={item} />}
</>
);
}
1 change: 1 addition & 0 deletions src/services/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const OSwipeActionBase = {
export const OSwipeActionPost = {
...OSwipeActionBase,
Hide: "hide",
Share: "share",
} as const;

export const OSwipeActionComment = {
Expand Down

0 comments on commit 706d7e8

Please sign in to comment.