From 8df67b8992c3eb44dc409d4cedef26fd8f2d4878 Mon Sep 17 00:00:00 2001 From: Amanda Bullington <35536439+albullington@users.noreply.github.com> Date: Wed, 25 Oct 2023 16:21:54 -0700 Subject: [PATCH] Add comment sheet for deleting comments; closes #792 (#835) --- ios/Podfile.lock | 2 +- .../ObsDetails/ActivityTab/ActivityHeader.js | 16 ++++++++++++++-- .../ActivityTab/ActivityHeaderContainer.js | 11 +---------- src/i18n/l10n/en.ftl | 2 ++ src/i18n/l10n/en.ftl.json | 1 + src/i18n/strings.ftl | 2 ++ src/realmModels/Comment.js | 7 ------- 7 files changed, 21 insertions(+), 20 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 2aa0d3503..685dece47 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -776,4 +776,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 77ed9526d4011b245ce5afa1ea331dea4c67d753 -COCOAPODS: 1.12.1 +COCOAPODS: 1.13.0 diff --git a/src/components/ObsDetails/ActivityTab/ActivityHeader.js b/src/components/ObsDetails/ActivityTab/ActivityHeader.js index cd9f8abc2..a77fbc445 100644 --- a/src/components/ObsDetails/ActivityTab/ActivityHeader.js +++ b/src/components/ObsDetails/ActivityTab/ActivityHeader.js @@ -2,7 +2,7 @@ import classnames from "classnames"; import FlagItemModal from "components/ObsDetails/FlagItemModal"; import { - Body4, INatIcon, InlineUser, TextInputSheet + Body4, INatIcon, InlineUser, TextInputSheet, WarningSheet } from "components/SharedComponents"; import KebabMenu from "components/SharedComponents/KebabMenu"; import { @@ -36,6 +36,7 @@ const ActivityHeader = ( { const [kebabMenuVisible, setKebabMenuVisible] = useState( false ); const [flagModalVisible, setFlagModalVisible] = useState( false ); const [showEditCommentSheet, setShowEditCommentSheet] = useState( false ); + const [showDeleteCommentSheet, setShowDeleteCommentSheet] = useState( false ); const { user } = item; const itemType = item.category @@ -145,7 +146,7 @@ const ActivityHeader = ( { /> { - deleteComment( item.uuid ); + setShowDeleteCommentSheet( true ); setKebabMenuVisible( false ); }} title={t( "Delete-comment" )} @@ -194,6 +195,17 @@ const ActivityHeader = ( { confirm={textInput => updateCommentBody( textInput )} /> )} + {( currentUser && showDeleteCommentSheet ) && ( + setShowDeleteCommentSheet( false )} + headerText={t( "DELETE-COMMENT" )} + snapPoints={[148]} + confirm={deleteComment} + buttonText={t( "DELETE" )} + handleSecondButtonPress={( ) => setShowDeleteCommentSheet( false )} + secondButtonText={t( "CANCEL" )} + /> + )} ); diff --git a/src/components/ObsDetails/ActivityTab/ActivityHeaderContainer.js b/src/components/ObsDetails/ActivityTab/ActivityHeaderContainer.js index 006306dd8..7e6577cfc 100644 --- a/src/components/ObsDetails/ActivityTab/ActivityHeaderContainer.js +++ b/src/components/ObsDetails/ActivityTab/ActivityHeaderContainer.js @@ -4,16 +4,12 @@ import { useQueryClient } from "@tanstack/react-query"; import { deleteComments, updateComment } from "api/comments"; import { updateIdentification } from "api/identifications"; import { isCurrentUser } from "components/LoginSignUp/AuthenticationService"; -import { RealmContext } from "providers/contexts"; import type { Node } from "react"; import React, { useEffect, useState } from "react"; -import Comment from "realmModels/Comment"; import useAuthenticatedMutation from "sharedHooks/useAuthenticatedMutation"; import ActivityHeader from "./ActivityHeader"; -const { useRealm } = RealmContext; - type Props = { item: Object, refetchRemoteObservation?: Function, @@ -28,7 +24,6 @@ const ActivityHeaderContainer = ( { }:Props ): Node => { const [currentUser, setCurrentUser] = useState( false ); const [flagged, setFlagged] = useState( false ); - const realm = useRealm( ); const queryClient = useQueryClient( ); const { user } = item; @@ -63,11 +58,7 @@ const ActivityHeaderContainer = ( { } ); - const deleteUserComment = () => { - Comment.deleteComment( item.uuid, realm ); - // then delete remotely - deleteCommentMutation.mutate( item.uuid ); - }; + const deleteUserComment = ( ) => deleteCommentMutation.mutate( item.uuid ); const updateCommentMutation = useAuthenticatedMutation( ( uuid, optsWithAuth ) => updateComment( uuid, optsWithAuth ), diff --git a/src/i18n/l10n/en.ftl b/src/i18n/l10n/en.ftl index 39db3e824..fe10120b5 100644 --- a/src/i18n/l10n/en.ftl +++ b/src/i18n/l10n/en.ftl @@ -234,6 +234,8 @@ DELETE = DELETE DELETE-ALL = DELETE ALL +DELETE-COMMENT = DELETE COMMENT? + Delete-comment = Delete comment DELETE-OBSERVATION = DELETE OBSERVATION? diff --git a/src/i18n/l10n/en.ftl.json b/src/i18n/l10n/en.ftl.json index 3409208d9..ab6831aeb 100644 --- a/src/i18n/l10n/en.ftl.json +++ b/src/i18n/l10n/en.ftl.json @@ -130,6 +130,7 @@ "Default-Search-Place": "Default Search Place", "DELETE": "DELETE", "DELETE-ALL": "DELETE ALL", + "DELETE-COMMENT": "DELETE COMMENT?", "Delete-comment": "Delete comment", "DELETE-OBSERVATION": "DELETE OBSERVATION?", "Delete-observation": "Delete observation", diff --git a/src/i18n/strings.ftl b/src/i18n/strings.ftl index 39db3e824..fe10120b5 100644 --- a/src/i18n/strings.ftl +++ b/src/i18n/strings.ftl @@ -234,6 +234,8 @@ DELETE = DELETE DELETE-ALL = DELETE ALL +DELETE-COMMENT = DELETE COMMENT? + Delete-comment = Delete comment DELETE-OBSERVATION = DELETE OBSERVATION? diff --git a/src/realmModels/Comment.js b/src/realmModels/Comment.js index 6b4268189..2fe0d52ae 100644 --- a/src/realmModels/Comment.js +++ b/src/realmModels/Comment.js @@ -20,13 +20,6 @@ class Comment extends Realm.Object { }; } - static async deleteComment( id, realm ) { - realm?.write( ( ) => { - const commentToDelete = realm.objects( "Comment" ).filtered( `uuid == "${id}"` )[0]; - realm.delete( commentToDelete ); - } ); - } - static schema = { name: "Comment", properties: {