Skip to content

Commit e32b56b

Browse files
committed
feat: add context copy
1 parent 290b442 commit e32b56b

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = {
88
'@typescript-eslint/no-unused-vars': 'warn',
99
'react/jsx-key': 'off',
1010
'import/namespace': 'off',
11+
'react/jsx-closing-tag-location': 'off',
1112
},
1213
overrides: [
1314
{

src/components/ui/ShareModal.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
1-
import { useI18n } from '@/hooks'
1+
import { useStore } from '@nanostores/solid'
2+
import { For } from 'solid-js'
3+
import { useClipboardCopy, useI18n } from '@/hooks'
4+
import { currentConversationId } from '@/stores/conversation'
5+
import { getMessagesByConversationId } from '@/stores/messages'
26
import { Tabs } from '../ui/base'
37
import type { TabItem } from './base/Tabs'
48

59
export default () => {
610
const { t } = useI18n()
11+
const $currentConversationId = useStore(currentConversationId)
12+
const messages = getMessagesByConversationId($currentConversationId())
13+
14+
console.log($currentConversationId(), messages)
15+
16+
const [copied, copy] = useClipboardCopy(messages.map(item => `${item.role}: ${item.content}`).join('\n'))
717

818
const tabs: TabItem[] = [
919
{
1020
value: 'context',
1121
label: t('conversations.share.tabs.context'),
12-
content: <div class="flex">context</div>,
22+
content: <div class="flex flex-col gap-2">
23+
<div class="emerald-light-button mt-0 cursor-pointer" onClick={() => copy()}>{copied() ? t('copyed') : t('conversations.share.copy')}</div>
24+
<For each={messages}>
25+
{item => (
26+
<div class="flex space-x-2">
27+
<div class="font-bold w-20 text-left">{item.role}:</div>
28+
<div class="text-left flex-1">{item.content}</div>
29+
</div>
30+
)}
31+
</For>
32+
</div>,
1333
},
1434
{
1535
value: 'image',
@@ -22,14 +42,14 @@ export default () => {
2242
<div class="w-full">
2343
<div class="fi justify-between border-base b-b-1 px-6 py-4">
2444
<div class="text-base">{t('conversations.share.link.title')}</div>
25-
<button class="emerald-button mt-0">{t('conversations.share.link.create')}</button>
45+
<button class="button mt-0">{t('conversations.share.link.create')}</button>
2646
</div>
2747
<div class="fcc flex-col space-y-2 p-6">
2848
<div class="border w-full border-base fi justify-between box-border p-4 rounded-md hv-base">
2949
<span class="text-xs">{t('conversations.share.messages.selected')}</span>
3050
<span class="text-xs op-60">2 Messages</span>
3151
</div>
32-
<Tabs tabs={tabs} />
52+
<Tabs tabs={tabs} sticky tabClass="bg-base-100" />
3353
</div>
3454
</div>
3555
)

src/components/ui/base/Tabs.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export interface TabItem {
1212
interface Props {
1313
tabs: TabItem[]
1414
initValue?: string
15+
sticky?: boolean
16+
tabClass?: string
1517
}
1618

1719
export const Tabs = (props: Props) => {
@@ -21,18 +23,18 @@ export const Tabs = (props: Props) => {
2123

2224
return (
2325
<div {...api().rootProps} class="w-full text-sm font-medium text-center">
24-
<div {...api().tablistProps} class="flex flex-wrap -mb-px border-b border-base">
26+
<div {...api().tablistProps} class={`flex flex-wrap -mb-px border-b border-base ${props.sticky && 'sticky top-0 bottom-0'} ${props.tabClass}`}>
2527
<For each={props.tabs}>
2628
{item => (
27-
<button class={`inline-block p-4 border-b-2 border-transparent hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-300 cursor-pointer ${api().value === item.value && '!border-emerald-600 !text-emerald-600'}`} {...api().getTriggerProps({ value: item.value })}>
29+
<button class={`inline-block p-4 border-b-2 border-transparent hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-300 cursor-pointer ${api().value === item.value && '!border-emerald-600 !text-emerald-600'}`} {...api().getTriggerProps({ value: item.value })}>
2830
{item.label}
2931
</button>
3032
)}
3133
</For>
3234
</div>
3335
<For each={props.tabs}>
3436
{item => (
35-
<div class="w-full p-4 text-sm mt-4 border border-base" {...api().getContentProps({ value: item.value })}>
37+
<div class="w-full text-sm mt-4 border border-base p-4" {...api().getContentProps({ value: item.value })}>
3638
{item.content}
3739
</div>
3840
)}

src/locale/lang/en.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const en = {
3838
create: 'Create Link',
3939
},
4040
save: 'Save',
41+
copy: 'Copy Context',
4142
messages: {
4243
title: 'Select Message',
4344
selected: 'Selected Messages',
@@ -51,5 +52,6 @@ export const en = {
5152
send: {
5253
placeholder: 'Enter Something...',
5354
},
55+
copyed: 'Copyed!',
5456
},
5557
} as language

src/locale/lang/zh-cn.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const zhCN = {
3838
create: '创建链接',
3939
},
4040
save: '保存',
41+
copy: '复制上下文',
4142
messages: {
4243
title: '选择消息',
4344
selected: '已选择的消息',
@@ -51,5 +52,6 @@ export const zhCN = {
5152
send: {
5253
placeholder: '输入内容...',
5354
},
55+
copyed: '已拷贝!',
5456
},
5557
} as language

0 commit comments

Comments
 (0)