From 88bb8f14eb4b139bc7bf10029f424f24b88372af Mon Sep 17 00:00:00 2001 From: Vali98 Date: Sat, 28 Dec 2024 23:13:26 +0800 Subject: [PATCH] fix: swiping not updating values --- app/components/ChatMenu/ChatWindow/Swipes.tsx | 18 +++++++++--------- constants/Chat.ts | 17 ++++++++--------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/app/components/ChatMenu/ChatWindow/Swipes.tsx b/app/components/ChatMenu/ChatWindow/Swipes.tsx index 4a2a3b5..a0e59b8 100644 --- a/app/components/ChatMenu/ChatWindow/Swipes.tsx +++ b/app/components/ChatMenu/ChatWindow/Swipes.tsx @@ -13,7 +13,7 @@ type SwipesProps = { const Swipes: React.FC = ({ nowGenerating, isGreeting, index }) => { const { swipeChat, addSwipe } = Chats.useSwipes() - const entry = Chats.useEntryData(index) + const { swipeText, swipeId, swipeIndex, swipesLength } = Chats.useSwipeData(index) const handleSwipeLeft = () => { swipeChat(index, -1) @@ -29,19 +29,19 @@ const Swipes: React.FC = ({ nowGenerating, isGreeting, index }) => } } - const isLastAltGreeting = isGreeting && entry.swipe_id === entry.swipes.length - 1 + const isLastAltGreeting = isGreeting && swipeIndex === swipesLength - 1 return ( + disabled={nowGenerating || swipeIndex === 0}> = ({ nowGenerating, isGreeting, index }) => {index !== 0 && ( regenerateResponse(entry.swipes[entry.swipe_id].id)} - onLongPress={() => regenerateResponse(entry.swipes[entry.swipe_id].id, false)} + onPress={() => swipeId && regenerateResponse(swipeId)} + onLongPress={() => swipeId && regenerateResponse(swipeId, false)} disabled={nowGenerating} style={styles.swipeButton}> = ({ nowGenerating, isGreeting, index }) => )} - {entry.swipe_id + 1} / {entry.swipes.length} + {swipeIndex + 1} / {swipesLength} {index !== 0 && ( continueResponse(entry.swipes[entry.swipe_id].id)} + onPress={() => swipeId && continueResponse(swipeId)} disabled={nowGenerating} style={styles.swipeButton}> = ({ nowGenerating, isGreeting, index }) => handleSwipeRight('')} - onLongPress={() => handleSwipeRight(entry?.swipes?.[entry.swipe_id]?.swipe ?? '')} + onLongPress={() => handleSwipeRight(swipeText ?? '')} disabled={nowGenerating || isLastAltGreeting}> { const message = useEntryData(index) - const swipe_index = message.swipe_id - const { swipe, swipeText, swipeId } = useChatState( - useShallow((state) => ({ - swipe: state?.data?.messages?.[index].swipes[swipe_index], - swipeText: state?.data?.messages?.[index].swipes[swipe_index].swipe ?? '', - swipeId: state?.data?.messages?.[index].swipes[swipe_index].id, - })) - ) - return { swipeId, swipe, swipeText } + const swipeIndex = message.swipe_id + const swipesLength = message.swipes.length + const { swipe, swipeText, swipeId } = useChatState((state) => ({ + swipe: state?.data?.messages?.[index].swipes[swipeIndex], + swipeText: state?.data?.messages?.[index].swipes[swipeIndex].swipe ?? '', + swipeId: state?.data?.messages?.[index].swipes[swipeIndex].id, + })) + return { swipeId, swipe, swipeText, swipeIndex, swipesLength } } export const useChat = () => {