Skip to content

Commit

Permalink
add missing haptics for post menu(#511 (#603)
Browse files Browse the repository at this point in the history
Co-authored-by: Gavin Kasdorf <[email protected]>
  • Loading branch information
flx-sta and gkasdorf authored Jul 12, 2023
1 parent 44e2989 commit f51c78b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
9 changes: 3 additions & 6 deletions src/components/screens/Post/components/PostOptionsButton.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from "react";
import { useTheme } from "native-base";
import { useActionSheet } from "@expo/react-native-action-sheet";
import { IconDots } from "tabler-icons-react-native";
import { Alert } from "react-native";
import { useAppDispatch } from "../../../../../store";
import { lemmyAuthToken, lemmyInstance } from "../../../../LemmyInstance";
import { showToast } from "../../../../slices/toast/toastSlice";
import HeaderIconButton from "../../../common/Buttons/HeaderIconButton";
import { useAppActionSheet } from "../../../../hooks/app/useAppActionSheet";
import { handleLemmyError } from "../../../../helpers/LemmyErrorHelper";

interface IProps {
Expand All @@ -15,22 +15,19 @@ interface IProps {

function CommentSortButton({ postId }: IProps) {
const theme = useTheme();
const { showActionSheetWithOptions } = useActionSheet();
const { showAppActionSheetWithOptions } = useAppActionSheet();
const dispatch = useAppDispatch();

const onPress = () => {
const options = ["Report Post", "Cancel"];
const cancelButtonIndex = options.indexOf("Cancel");

showActionSheetWithOptions(
showAppActionSheetWithOptions(
{
options,
cancelButtonIndex,
userInterfaceStyle: theme.config.initialColorMode,
},
(index) => {
if (index === cancelButtonIndex) return;

if (index === 0) onReportPress().then();
}
);
Expand Down
27 changes: 27 additions & 0 deletions src/hooks/app/useAppActionSheet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useActionSheet } from "@expo/react-native-action-sheet";
import { ActionSheetProps } from "@expo/react-native-action-sheet/lib/typescript/types";
import { useTheme } from "native-base";
import { onGenericHapticFeedback } from "../../helpers/HapticFeedbackHelpers";

export const useAppActionSheet = () => {
const theme = useTheme();

const { showActionSheetWithOptions } = useActionSheet();

const showAppActionSheetWithOptions: ActionSheetProps["showActionSheetWithOptions"] =
(options, callback) => {
const defaultOptions = {
userInterfaceStyle: theme.config.initialColorMode,
};

showActionSheetWithOptions({ ...defaultOptions, ...options }, (index) => {
onGenericHapticFeedback();
if (index === options.cancelButtonIndex) return;
callback(index);
});
};

return {
showAppActionSheetWithOptions,
};
};
13 changes: 3 additions & 10 deletions src/hooks/post/useComment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { useActionSheet } from "@expo/react-native-action-sheet";
import { useTheme } from "native-base";
import React, { SetStateAction } from "react";
import Clipboard from "@react-native-community/clipboard";
import { CommentReplyView } from "lemmy-js-client";
Expand All @@ -20,6 +18,7 @@ import { writeToLog } from "../../helpers/LogHelper";
import { ILemmyVote } from "../../types/lemmy/ILemmyVote";
import { showToast } from "../../slices/toast/toastSlice";
import { setResponseTo } from "../../slices/comments/newCommentSlice";
import { useAppActionSheet } from "../app/useAppActionSheet";
import { handleLemmyError } from "../../helpers/LemmyErrorHelper";

interface UseComment {
Expand All @@ -45,8 +44,7 @@ const useComment = ({

const dispatch = useAppDispatch();

const { showActionSheetWithOptions } = useActionSheet();
const theme = useTheme();
const { showAppActionSheetWithOptions } = useAppActionSheet();

const onCommentPress = () => {
onGenericHapticFeedback();
Expand Down Expand Up @@ -108,19 +106,14 @@ const useComment = ({
const optionsArr = Object.values(options);
const cancelButtonIndex = optionsArr.indexOf(options.Cancel);

showActionSheetWithOptions(
showAppActionSheetWithOptions(
{
options: optionsArr,
cancelButtonIndex,
userInterfaceStyle: theme.config.initialColorMode,
},
async (index: number) => {
onGenericHapticFeedback();

const option = optionsArr[index];

if (index === cancelButtonIndex) return;

if (option === options["Copy Text"]) {
Clipboard.setString(comment.comment.comment.content);
}
Expand Down

0 comments on commit f51c78b

Please sign in to comment.