Page MenuHomePhabricator

D3419.id10393.diff
No OneTemporary

D3419.id10393.diff

diff --git a/lib/hooks/toggle-unread-status.js b/lib/hooks/toggle-unread-status.js
--- a/lib/hooks/toggle-unread-status.js
+++ b/lib/hooks/toggle-unread-status.js
@@ -16,7 +16,7 @@
function useToggleUnreadStatus(
threadInfo: ThreadInfo,
mostRecentNonLocalMessage: ?string,
- afterAction: () => void,
+ afterAction: ?() => void,
): () => void {
const dispatchActionPromise = useDispatchActionPromise();
const boundSetThreadUnreadStatus: (
@@ -40,7 +40,9 @@
unread: !unread,
},
);
- afterAction();
+ if (afterAction) {
+ afterAction();
+ }
}, [
threadInfo,
mostRecentNonLocalMessage,
diff --git a/native/chat/swipeable-thread.react.js b/native/chat/swipeable-thread.react.js
--- a/native/chat/swipeable-thread.react.js
+++ b/native/chat/swipeable-thread.react.js
@@ -4,23 +4,11 @@
import * as React from 'react';
import MaterialIcon from 'react-native-vector-icons/MaterialCommunityIcons';
-import {
- setThreadUnreadStatus,
- setThreadUnreadStatusActionTypes,
-} from 'lib/actions/activity-actions';
-import type {
- SetThreadUnreadStatusPayload,
- SetThreadUnreadStatusRequest,
-} from 'lib/types/activity-types';
+import useToggleUnreadStatus from 'lib/hooks/toggle-unread-status';
import type { ThreadInfo } from 'lib/types/thread-types';
-import {
- useDispatchActionPromise,
- useServerCall,
-} from 'lib/utils/action-utils';
import Swipeable from '../components/swipeable';
import { useColors } from '../themes/colors';
-
type Props = {
+threadInfo: ThreadInfo,
+mostRecentNonLocalMessage: ?string,
@@ -54,33 +42,21 @@
const colors = useColors();
const { mostRecentNonLocalMessage, iconSize } = props;
- const updateUnreadStatus: (
- request: SetThreadUnreadStatusRequest,
- ) => Promise<SetThreadUnreadStatusPayload> = useServerCall(
- setThreadUnreadStatus,
+
+ let swipeableClose = React.useCallback(() => {
+ if (swipeable.current) {
+ swipeableClose = swipeable.current.close();
+ }
+ }, []);
+
+ const toggleUnreadStatus = useToggleUnreadStatus(
+ threadInfo,
+ mostRecentNonLocalMessage,
+ swipeableClose,
);
- const dispatchActionPromise = useDispatchActionPromise();
+
const swipeableActions = React.useMemo(() => {
const isUnread = threadInfo.currentUser.unread;
- const toggleUnreadStatus = () => {
- const request = {
- unread: !isUnread,
- threadID: threadInfo.id,
- latestMessage: mostRecentNonLocalMessage,
- };
- dispatchActionPromise(
- setThreadUnreadStatusActionTypes,
- updateUnreadStatus(request),
- undefined,
- {
- threadID: threadInfo.id,
- unread: !isUnread,
- },
- );
- if (swipeable.current) {
- swipeable.current.close();
- }
- };
return [
{
key: 'action1',
@@ -96,12 +72,11 @@
},
];
}, [
- colors,
- threadInfo,
- mostRecentNonLocalMessage,
+ threadInfo.currentUser.unread,
+ toggleUnreadStatus,
+ colors.vibrantRedButton,
+ colors.vibrantGreenButton,
iconSize,
- updateUnreadStatus,
- dispatchActionPromise,
]);
return (

File Metadata

Mime Type
text/plain
Expires
Thu, Nov 28, 1:06 PM (21 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2594062
Default Alt Text
D3419.id10393.diff (3 KB)

Event Timeline