Skip to content

Commit

Permalink
Quick variations button; allows users to generate 3 more variations i…
Browse files Browse the repository at this point in the history
…mmediately
  • Loading branch information
mrdjohnson committed Jun 24, 2024
1 parent 7b13ba7 commit 6b90a17
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/components/message/MessageGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import { PropsWithChildren } from 'react'
import { observer } from 'mobx-react-lite'

import WindowClose from '~/icons/WindowClose'
import WindowPlus from '~/icons/WindowPlus'
import Delete from '~/icons/Delete'

import { IMessageModel } from '~/models/MessageModel'
import ToolTip from '~/components/Tooltip'

type MessageGroupType = PropsWithChildren<{
message: IMessageModel
onAddMoreVariations: () => void
}>

const MessageGroup = observer(({ message, children }: MessageGroupType) => {
const MessageGroup = observer(({ message, children, onAddMoreVariations }: MessageGroupType) => {
return (
<div className="relative flex w-fit flex-col" key={message.uniqId}>
<div className="sticky top-0 z-20 mr-4 flex w-full flex-row gap-2 bg-base-100 pb-2">
Expand All @@ -36,6 +38,15 @@ const MessageGroup = observer(({ message, children }: MessageGroupType) => {
<span className="sticky top-0 text-sm font-semibold text-base-content/30">
{message.variations.length + 1} Variations
</span>

<ToolTip label="Add 3 more variations" placement="top" delay={400}>
<button
className="text-sm opacity-30 hover:scale-105 hover:opacity-100 ml-auto"
onClick={onAddMoreVariations}
>
<WindowPlus />
</button>
</ToolTip>
</div>

<div className="flex flex-col flex-wrap gap-4 rounded-md border border-base-content/10 p-2 pt-4">
Expand Down
12 changes: 11 additions & 1 deletion src/containers/ChatBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,18 @@ const ChatBox = observer(() => {
const variations: IMessageModel[] = message.variations
const allVariations = [message, ...variations]

const handleAddMoreVariations = () => {
_.times(3, () => {
incomingMessageStore.generateVariation(chat, message)
})
}

return (
<MessageGroup message={message} key={message.uniqId + '_group'}>
<MessageGroup
message={message}
key={message.uniqId + '_group'}
onAddMoreVariations={handleAddMoreVariations}
>
{allVariations.map((variant, index) => renderMessage(message, variant, index))}
</MessageGroup>
)
Expand Down
11 changes: 11 additions & 0 deletions src/icons/WindowPlus.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// customized icon from the plus icon, edited via https://yqnn.github.io/svg-path-editor/

export default function WindowPlus() {
return (
<svg xmlns="http://www.w3.org/2000/svg" className="h-4 w-4" viewBox="0 0 24 24">
<g fill="none" stroke="currentColor" strokeLinecap="round" strokeWidth={1.5}>
<path d="M14 21H4a2 2 0 01-2-2V5a2 2 0 012-2h16a2 2 0 012 2v8M2 7h20M5 5l0 0M8 5l0 0M11 5l0 0M17 19l6 0M20 16V22"></path>
</g>
</svg>
)
}

0 comments on commit 6b90a17

Please sign in to comment.