-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
80 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,65 @@ | ||
import { useStore } from '@nanostores/solid' | ||
import { For } from 'solid-js' | ||
import { For, createSignal } from 'solid-js' | ||
import { useI18n } from '@/hooks' | ||
import { currentConversationId } from '@/stores/conversation' | ||
import { getMessagesByConversationId } from '@/stores/messages' | ||
import { getMessagesByConversationId, updateMessage } from '@/stores/messages' | ||
import { showSelectMessageModal, showShareModal } from '@/stores/ui' | ||
import { Checkbox } from '../ui/base' | ||
|
||
export default () => { | ||
const { t } = useI18n() | ||
const $currentConversationId = useStore(currentConversationId) | ||
const messages = getMessagesByConversationId($currentConversationId()) | ||
const [checkAll, setCheckAll] = createSignal(messages.every(item => item.isSelected)) | ||
const [selectedMessages, setSelectedMessages] = createSignal(messages) | ||
|
||
console.log(messages, selectedMessages()) | ||
|
||
const handleToggleMessages = (id: string) => { | ||
messages.forEach((item) => { | ||
if (item.id === id) | ||
item.isSelected = !item.isSelected | ||
}) | ||
setSelectedMessages(messages) | ||
} | ||
|
||
const handleSelectAll = () => { | ||
messages.forEach((item) => { | ||
item.isSelected = !checkAll() | ||
}) | ||
setSelectedMessages(messages) | ||
setCheckAll(!checkAll()) | ||
console.log(selectedMessages(), checkAll()) | ||
} | ||
|
||
const handleSaveContext = () => { | ||
messages.forEach((item) => { | ||
updateMessage($currentConversationId(), item.id, { isSelected: item.isSelected }) | ||
}) | ||
showSelectMessageModal.set(false) | ||
showShareModal.set(true) | ||
} | ||
|
||
console.log($currentConversationId(), messages) | ||
return ( | ||
<div class="w-full"> | ||
<div class="fi px-6 py-4 border-base b-b-1"> | ||
<div class="text-base">{t('conversations.share.messages.title')}</div> | ||
</div> | ||
<div class="flex flex-col p-6 h-100 overflow-auto relative"> | ||
<For each={messages}> | ||
{item => ( | ||
<div class="border border-base b-b-0 last:b-b-1 p-4" > | ||
<Checkbox initValue label={`${item.role}: ${item.content}`} /> | ||
</div> | ||
)} | ||
<div class="border border-base b-b-0 last:b-b-1 p-4 hv-base"> | ||
<Checkbox setValue={() => handleSelectAll()} initValue={checkAll()} label={`${t('conversations.share.messages.selectAll')}`} /> | ||
</div> | ||
<For each={selectedMessages()}> | ||
{(item) => { | ||
return ( | ||
<div class="border border-base b-b-0 last:b-b-1 p-4 hv-base"> | ||
<Checkbox setValue={() => handleToggleMessages(item.id)} initValue={item.isSelected} label={`${item.role}: ${item.content}`} /> | ||
</div> | ||
) | ||
}} | ||
</For> | ||
</div> | ||
<div class="fcc px-2 py-2 bg-darker border border-base hv-base hover:border-base-100" >{t('settings.save')}</div> | ||
<div class="fcc px-2 py-2 bg-darker border border-base hv-base hover:border-base-100" onClick={() => handleSaveContext()}>{t('settings.save')}</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters