Skip to content

Commit

Permalink
feat: added hold swipe right to clone swipe
Browse files Browse the repository at this point in the history
  • Loading branch information
Vali-98 committed Oct 4, 2024
1 parent 099fbc8 commit b0d0c51
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 9 additions & 4 deletions app/components/ChatMenu/ChatWindow/Swipes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ const Swipes: React.FC<SwipesProps> = ({ nowGenerating, isGreeting, index }) =>
swipeChat(index, -1)
}

const handleSwipeRight = async () => {
const handleSwipeRight = async (message: string) => {
const atLimit = await swipeChat(index, 1)
if (atLimit && !isGreeting) {
const id = await addSwipe(index)
if (id) generateResponse(id)
const id = await addSwipe(index, message)
if (!id) return
if (message) continueResponse(id)
else generateResponse(id)
}
}

Expand Down Expand Up @@ -98,7 +100,10 @@ const Swipes: React.FC<SwipesProps> = ({ nowGenerating, isGreeting, index }) =>

<TouchableHighlight
style={styles.swipeButton}
onPress={handleSwipeRight}
onPress={() => handleSwipeRight('')}
onLongPress={() =>
handleSwipeRight(message?.swipes?.[message.swipe_id]?.swipe ?? '')
}
disabled={nowGenerating || isLastAltGreeting}>
<AntDesign
name="right"
Expand Down
6 changes: 3 additions & 3 deletions app/constants/Chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface ChatState {
deleteEntry: (index: number) => Promise<void>
reset: () => void
swipe: (index: number, direction: number) => Promise<boolean>
addSwipe: (index: number) => Promise<number | void>
addSwipe: (index: number, message?: string) => Promise<number | void>
getTokenCount: (index: number) => number
setBuffer: (data: string) => void
insertBuffer: (data: string) => void
Expand Down Expand Up @@ -240,12 +240,12 @@ export namespace Chats {
return false
},

addSwipe: async (index: number) => {
addSwipe: async (index: number, message: string = '') => {
const messages = get().data?.messages
if (!messages) return
const entryId = messages[index].id

const swipe = await db.mutate.createSwipe(entryId, '')
const swipe = await db.mutate.createSwipe(entryId, message)
if (swipe) messages[index].swipes.push(swipe)
await db.mutate.updateEntrySwipeId(entryId, messages[index].swipes.length - 1)
messages[index].swipe_id = messages[index].swipes.length - 1
Expand Down

0 comments on commit b0d0c51

Please sign in to comment.