Skip to content

Commit

Permalink
Able to delete gallery
Browse files Browse the repository at this point in the history
  • Loading branch information
jakzaizzat committed May 2, 2024
1 parent f540546 commit 482c970
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 66 deletions.
73 changes: 73 additions & 0 deletions apps/mobile/src/components/Gallery/DeleteGalleryBottomSheet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { useCallback } from 'react';
import { View } from 'react-native';
import { graphql, useFragment } from 'react-relay';
import useDeleteGallery from 'shared/hooks/useDeleteGallery';

import { Button } from '~/components/Button';
import { Typography } from '~/components/Typography';
import { useBottomSheetModalActions } from '~/contexts/BottomSheetModalContext';
import { DeleteGalleryBottomSheet$key } from '~/generated/DeleteGalleryBottomSheet.graphql';
import { contexts } from '~/shared/analytics/constants';

type Props = {
galleryRef: DeleteGalleryBottomSheet$key;
};

export default function DeleteGalleryBottomSheet({ galleryRef }: Props) {
const gallery = useFragment(
graphql`
fragment DeleteGalleryBottomSheet on Gallery {
dbid
}
`,
galleryRef
);
const deleteGallery = useDeleteGallery();
const { hideBottomSheetModal } = useBottomSheetModalActions();

const handleBack = useCallback(() => {
hideBottomSheetModal();
}, [hideBottomSheetModal]);

const handleDelete = useCallback(() => {
deleteGallery(gallery.dbid);
hideBottomSheetModal();
}, [deleteGallery, gallery, hideBottomSheetModal]);

return (
<View className="flex flex-col space-y-6">
<View className="flex flex-col space-y-4">
<Typography
className="text-lg text-black-900 dark:text-offWhite"
font={{ family: 'ABCDiatype', weight: 'Bold' }}
>
Delete gallery
</Typography>
<Typography
className="text-lg text-black-900 dark:text-offWhite"
font={{ family: 'ABCDiatype', weight: 'Regular' }}
>
Are you sure you want to delete this gallery?
</Typography>
</View>

<View className="space-y-2">
<Button
onPress={handleDelete}
text="DELETE"
eventElementId="Delete Gallery Button"
eventName="Delete Gallery"
eventContext={contexts.UserGallery}
/>
<Button
onPress={handleBack}
variant="secondary"
text="CANCEL"
eventElementId="Cancel Delete Gallery Button"
eventName="Cancel Delete Gallery"
eventContext={contexts.UserGallery}
/>
</View>
</View>
);
}
71 changes: 7 additions & 64 deletions apps/mobile/src/components/ProfileView/GalleryPreviewCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ import { RawNftPreviewAsset } from '~/components/NftPreview/NftPreviewAsset';
import { NftPreviewErrorFallback } from '~/components/NftPreview/NftPreviewErrorFallback';
import { Typography } from '~/components/Typography';
import { useBottomSheetModalActions } from '~/contexts/BottomSheetModalContext';
import { useToastActions } from '~/contexts/ToastContext';
import { GalleryPreviewCardFragment$key } from '~/generated/GalleryPreviewCardFragment.graphql';
import { GalleryPreviewCardQueryFragment$key } from '~/generated/GalleryPreviewCardQueryFragment.graphql';
import { MainTabStackNavigatorProp, RootStackNavigatorProp } from '~/navigation/types';
import { MainTabStackNavigatorProp } from '~/navigation/types';
import { contexts } from '~/shared/analytics/constants';
import { ReportingErrorBoundary } from '~/shared/errors/ReportingErrorBoundary';
import unescape from '~/shared/utils/unescape';

import { BottomSheetRow } from '../BottomSheetRow';
import { GalleryTouchableOpacity } from '../GalleryTouchableOpacity';
import { useSafeAreaPadding } from '../SafeAreaViewWithPadding';
import { GalleryPreviewCardBottomSheet } from './GalleryPreviewCardBottomSheet';

type GalleryPreviewCardProps = {
isFeatured: boolean;
Expand All @@ -41,6 +39,7 @@ export function GalleryPreviewCard({ galleryRef, isFeatured, queryRef }: Gallery
tokenPreviews {
medium
}
...GalleryPreviewCardBottomSheetFragment
}
`,
galleryRef
Expand Down Expand Up @@ -69,10 +68,10 @@ export function GalleryPreviewCard({ galleryRef, isFeatured, queryRef }: Gallery
const handleOptionPress = useCallback(() => {
showBottomSheetModal({
content: (
<GalleryPreviewCardBottomSheet galleryId={gallery.dbid} onClose={hideBottomSheetModal} />
<GalleryPreviewCardBottomSheet galleryRef={gallery} onClose={hideBottomSheetModal} />
),
});
}, [gallery.dbid, hideBottomSheetModal, showBottomSheetModal]);
}, [gallery, hideBottomSheetModal, showBottomSheetModal]);

return (
<GalleryTouchableOpacity
Expand Down Expand Up @@ -118,6 +117,8 @@ export function GalleryPreviewCard({ galleryRef, isFeatured, queryRef }: Gallery
eventElementId={null}
eventName={null}
eventContext={null}
className="rounded-full p-1"
activeOpacity={0.5}
>
<OptionIcon />
</GalleryTouchableOpacity>
Expand Down Expand Up @@ -160,61 +161,3 @@ function TokenCell({
</View>
);
}

type GalleryPreviewCardBottomSheetProps = {
galleryId: string;
onClose: () => void;
};

function GalleryPreviewCardBottomSheet({ galleryId, onClose }: GalleryPreviewCardBottomSheetProps) {
const { bottom } = useSafeAreaPadding();
const { pushToast } = useToastActions();
const navigation = useNavigation<RootStackNavigatorProp>();

const handleInProgress = useCallback(() => {
pushToast({
message: 'Feature in progress',
});
}, [pushToast]);

const handleEditGallery = useCallback(() => {
navigation.navigate('GalleryEditor', {
galleryId,
stagedTokens: [],
});
onClose();
}, [galleryId, navigation, onClose]);

return (
<View style={{ paddingBottom: bottom }} className=" flex flex-col space-y-6">
<View className="flex flex-col space-y-2">
<BottomSheetRow
text="Edit Gallery"
onPress={handleEditGallery}
eventContext={contexts.UserGallery}
/>
<BottomSheetRow
text="Feature on Profile"
onPress={handleInProgress}
eventContext={contexts.UserGallery}
/>
<BottomSheetRow
text="Hide Gallery"
onPress={handleInProgress}
eventContext={contexts.UserGallery}
/>
<BottomSheetRow
text="Share Gallery"
onPress={handleInProgress}
eventContext={contexts.UserGallery}
/>
<BottomSheetRow
text="Delete Gallery"
onPress={handleInProgress}
isConfirmationRow
eventContext={contexts.UserGallery}
/>
</View>
</View>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { useNavigation } from '@react-navigation/native';
import { useCallback } from 'react';
import { View } from 'react-native';
import { graphql, useFragment } from 'react-relay';
import { contexts } from 'shared/analytics/constants';

import { useBottomSheetModalActions } from '~/contexts/BottomSheetModalContext';
import { useToastActions } from '~/contexts/ToastContext';
import { GalleryPreviewCardBottomSheetFragment$key } from '~/generated/GalleryPreviewCardBottomSheetFragment.graphql';
import { RootStackNavigatorProp } from '~/navigation/types';

import { BottomSheetRow } from '../BottomSheetRow';
import DeleteGalleryBottomSheet from '../Gallery/DeleteGalleryBottomSheet';
import { useSafeAreaPadding } from '../SafeAreaViewWithPadding';

type Props = {
galleryRef: GalleryPreviewCardBottomSheetFragment$key;
onClose: () => void;
};

export function GalleryPreviewCardBottomSheet({ galleryRef, onClose }: Props) {
const gallery = useFragment(
graphql`
fragment GalleryPreviewCardBottomSheetFragment on Gallery {
dbid
...DeleteGalleryBottomSheet
}
`,
galleryRef
);

const galleryId = gallery.dbid;

const { bottom } = useSafeAreaPadding();
const { pushToast } = useToastActions();

const { showBottomSheetModal } = useBottomSheetModalActions();
const navigation = useNavigation<RootStackNavigatorProp>();

const handleInProgress = useCallback(() => {
pushToast({
message: 'Feature in progress',
});
}, [pushToast]);

const handleEditGallery = useCallback(() => {
navigation.navigate('GalleryEditor', {
galleryId,
stagedTokens: [],
});
onClose();
}, [galleryId, navigation, onClose]);

const handleDeleteGallery = useCallback(() => {
showBottomSheetModal({
content: <DeleteGalleryBottomSheet galleryRef={gallery} />,
});
}, [gallery, showBottomSheetModal]);

return (
<View style={{ paddingBottom: bottom }} className=" flex flex-col space-y-6">
<View className="flex flex-col space-y-2">
<BottomSheetRow
text="Edit Gallery"
onPress={handleEditGallery}
eventContext={contexts.UserGallery}
/>
<BottomSheetRow
text="Feature on Profile"
onPress={handleInProgress}
eventContext={contexts.UserGallery}
/>
<BottomSheetRow
text="Hide Gallery"
onPress={handleInProgress}
eventContext={contexts.UserGallery}
/>
<BottomSheetRow
text="Share Gallery"
onPress={handleInProgress}
eventContext={contexts.UserGallery}
/>
<BottomSheetRow
text="Delete Gallery"
onPress={handleDeleteGallery}
isConfirmationRow
eventContext={contexts.UserGallery}
/>
</View>
</View>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { contexts } from '~/shared/analytics/constants';
import { Button } from '../core/Button/Button';
import { HStack } from '../core/Spacer/Stack';
import { BaseM } from '../core/Text/Text';
import useDeleteGallery from './useDeleteGallery';
import useDeleteGallery from '~/shared/hooks/useDeleteGallery';

type Props = {
galleryId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useCallback } from 'react';
import { graphql } from 'relay-runtime';

import { useDeleteGalleryMutation } from '~/generated/useDeleteGalleryMutation.graphql';
import { usePromisifiedMutation } from '~/shared/relay/usePromisifiedMutation';
import { usePromisifiedMutation } from '../relay/usePromisifiedMutation';

export default function useDeleteGallery() {
const [deleteGallery] = usePromisifiedMutation<useDeleteGalleryMutation>(graphql`
Expand Down

0 comments on commit 482c970

Please sign in to comment.