Skip to content

Commit

Permalink
fix: swiping not updating values
Browse files Browse the repository at this point in the history
  • Loading branch information
Vali-98 committed Dec 28, 2024
1 parent 9b52036 commit 88bb8f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
18 changes: 9 additions & 9 deletions app/components/ChatMenu/ChatWindow/Swipes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type SwipesProps = {

const Swipes: React.FC<SwipesProps> = ({ 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)
Expand All @@ -29,19 +29,19 @@ const Swipes: React.FC<SwipesProps> = ({ nowGenerating, isGreeting, index }) =>
}
}

const isLastAltGreeting = isGreeting && entry.swipe_id === entry.swipes.length - 1
const isLastAltGreeting = isGreeting && swipeIndex === swipesLength - 1

return (
<View style={styles.swipesItem}>
<TouchableHighlight
style={styles.swipeButton}
onPress={handleSwipeLeft}
disabled={nowGenerating || entry.swipe_id === 0}>
disabled={nowGenerating || swipeIndex === 0}>
<AntDesign
name="left"
size={20}
color={
entry.swipe_id === 0 || nowGenerating
swipeIndex === 0 || nowGenerating
? Style.getColor('primary-text3')
: Style.getColor('primary-text1')
}
Expand All @@ -50,8 +50,8 @@ const Swipes: React.FC<SwipesProps> = ({ nowGenerating, isGreeting, index }) =>

{index !== 0 && (
<TouchableHighlight
onPress={() => 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}>
<AntDesign
Expand All @@ -67,12 +67,12 @@ const Swipes: React.FC<SwipesProps> = ({ nowGenerating, isGreeting, index }) =>
)}

<Text style={styles.swipeText}>
{entry.swipe_id + 1} / {entry.swipes.length}
{swipeIndex + 1} / {swipesLength}
</Text>

{index !== 0 && (
<TouchableHighlight
onPress={() => continueResponse(entry.swipes[entry.swipe_id].id)}
onPress={() => swipeId && continueResponse(swipeId)}
disabled={nowGenerating}
style={styles.swipeButton}>
<AntDesign
Expand All @@ -90,7 +90,7 @@ const Swipes: React.FC<SwipesProps> = ({ nowGenerating, isGreeting, index }) =>
<TouchableHighlight
style={styles.swipeButton}
onPress={() => handleSwipeRight('')}
onLongPress={() => handleSwipeRight(entry?.swipes?.[entry.swipe_id]?.swipe ?? '')}
onLongPress={() => handleSwipeRight(swipeText ?? '')}
disabled={nowGenerating || isLastAltGreeting}>
<AntDesign
name="right"
Expand Down
17 changes: 8 additions & 9 deletions constants/Chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,15 +639,14 @@ export namespace Chats {

export const useSwipeData = (index: number) => {
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 = () => {
Expand Down

0 comments on commit 88bb8f1

Please sign in to comment.