fix: make chat button click event work fine (#7658)

fix PD-1504
This commit is contained in:
darkskygit
2024-07-31 09:24:53 +00:00
parent 48e17fad02
commit 49529b7e63
7 changed files with 51 additions and 20 deletions

View File

@@ -168,6 +168,16 @@ export class ChatPanelInput extends WithDisposable(LitElement) {
} }
} }
.chat-panel-send svg rect {
fill: var(--affine-primary-color);
}
.chat-panel-send[aria-disabled='true'] {
cursor: not-allowed;
}
.chat-panel-send[aria-disabled='true'] svg rect {
fill: var(--affine-text-disable-color);
}
.close-wrapper { .close-wrapper {
width: 16px; width: 16px;
height: 16px; height: 16px;
@@ -286,18 +296,13 @@ export class ChatPanelInput extends WithDisposable(LitElement) {
const maxHeight = hasImages ? 272 + 2 : 200 + 2; const maxHeight = hasImages ? 272 + 2 : 200 + 2;
return html`<style> return html`<style>
.chat-panel-send svg rect {
fill: ${this.isInputEmpty && hasImages
? 'var(--affine-text-disable-color)'
: 'var(--affine-primary-color)'};
}
.chat-panel-input { .chat-panel-input {
border-color: ${this.focused border-color: ${this.focused
? 'var(--affine-primary-color)' ? 'var(--affine-primary-color)'
: 'var(--affine-border-color)'}; : 'var(--affine-border-color)'};
box-shadow: ${this.focused ? 'var(--affine-active-shadow)' : 'none'}; box-shadow: ${this.focused ? 'var(--affine-active-shadow)' : 'none'};
max-height: ${maxHeight}px !important; max-height: ${maxHeight}px !important;
user-select: none;
} }
</style> </style>
<div class="chat-panel-input"> <div class="chat-panel-input">
@@ -395,7 +400,11 @@ export class ChatPanelInput extends WithDisposable(LitElement) {
> >
${ChatAbortIcon} ${ChatAbortIcon}
</div>` </div>`
: html`<div @click="${this.send}" class="chat-panel-send"> : html`<div
@click="${this.send}"
class="chat-panel-send"
aria-disabled=${this.isInputEmpty}
>
${ChatSendIcon} ${ChatSendIcon}
</div>`} </div>`}
</div> </div>

View File

@@ -91,6 +91,7 @@ export class ChatPanel extends WithDisposable(ShadowlessElement) {
align-items: center; align-items: center;
color: var(--affine-text-secondary-color); color: var(--affine-text-secondary-color);
font-size: 12px; font-size: 12px;
user-select: none;
} }
`; `;

View File

@@ -56,6 +56,7 @@ export class ChatBlockInput extends LitElement {
resize: none; resize: none;
overflow-y: hidden; overflow-y: hidden;
background-color: transparent; background-color: transparent;
user-select: none;
} }
textarea::placeholder { textarea::placeholder {
font-size: 14px; font-size: 14px;
@@ -91,6 +92,17 @@ export class ChatBlockInput extends LitElement {
} }
} }
} }
.chat-panel-send svg rect {
fill: var(--affine-primary-color);
}
.chat-panel-send[aria-disabled='true'] {
cursor: not-allowed;
}
.chat-panel-send[aria-disabled='true'] svg rect {
fill: var(--affine-text-disable-color);
}
.close-wrapper { .close-wrapper {
width: 16px; width: 16px;
height: 16px; height: 16px;
@@ -143,17 +155,13 @@ export class ChatBlockInput extends LitElement {
}); });
return html`<style> return html`<style>
.chat-panel-send svg rect {
fill: ${this._isInputEmpty
? 'var(--affine-text-disable-color)'
: 'var(--affine-primary-color)'};
}
.chat-panel-input { .chat-panel-input {
border-color: ${this._focused border-color: ${this._focused
? 'var(--affine-primary-color)' ? 'var(--affine-primary-color)'
: 'var(--affine-border-color)'}; : 'var(--affine-border-color)'};
box-shadow: ${this._focused ? 'var(--affine-active-shadow)' : 'none'}; box-shadow: ${this._focused ? 'var(--affine-active-shadow)' : 'none'};
max-height: ${maxHeight}px; max-height: ${maxHeight}px;
user-select: none;
} }
</style> </style>
<div class="ai-chat-input"> <div class="ai-chat-input">
@@ -233,7 +241,11 @@ export class ChatBlockInput extends LitElement {
> >
${ChatAbortIcon} ${ChatAbortIcon}
</div>` </div>`
: html`<div @click="${this._send}" class="chat-panel-send"> : html`<div
@click="${this._send}"
class="chat-panel-send"
aria-disabled=${this._isInputEmpty}
>
${ChatSendIcon} ${ChatSendIcon}
</div>`} </div>`}
</div> </div>

View File

@@ -69,5 +69,6 @@ export const PeekViewStyles = css`
align-items: center; align-items: center;
color: var(--affine-text-secondary-color); color: var(--affine-text-secondary-color);
font-size: var(--affine-font-xs); font-size: var(--affine-font-xs);
user-select: none;
} }
`; `;

View File

@@ -5,6 +5,7 @@ import {
useLiveData, useLiveData,
useService, useService,
} from '@toeverything/infra'; } from '@toeverything/infra';
import clsx from 'clsx';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { ToolContainer } from '../../workspace'; import { ToolContainer } from '../../workspace';
@@ -14,6 +15,7 @@ import {
aiIslandBtn, aiIslandBtn,
aiIslandWrapper, aiIslandWrapper,
gradient, gradient,
toolStyle,
} from './styles.css'; } from './styles.css';
const RIGHT_SIDEBAR_AI_HAS_EVER_OPENED_KEY = const RIGHT_SIDEBAR_AI_HAS_EVER_OPENED_KEY =
@@ -49,7 +51,7 @@ export const AIIsland = () => {
}, [activeTab, haveChatTab, sidebarOpen]); }, [activeTab, haveChatTab, sidebarOpen]);
return ( return (
<ToolContainer> <ToolContainer className={clsx(toolStyle, { hide })}>
<div <div
className={aiIslandWrapper} className={aiIslandWrapper}
data-hide={hide} data-hide={hide}

View File

@@ -1,6 +1,14 @@
import { cssVar } from '@toeverything/theme'; import { cssVar } from '@toeverything/theme';
import { createVar, keyframes, style } from '@vanilla-extract/css'; import { createVar, keyframes, style } from '@vanilla-extract/css';
export const toolStyle = style({
selectors: {
'&.hide': {
pointerEvents: 'none',
},
},
});
export const aiIslandWrapper = style({ export const aiIslandWrapper = style({
width: 44, width: 44,
height: 44, height: 44,

View File

@@ -71,7 +71,9 @@ export const MainContainer = forwardRef<
MainContainer.displayName = 'MainContainer'; MainContainer.displayName = 'MainContainer';
export const ToolContainer = (props: PropsWithChildren): ReactElement => { export const ToolContainer = (
props: PropsWithChildren<{ className?: string }>
): ReactElement => {
const docId = useLiveData( const docId = useLiveData(
useService(GlobalContextService).globalContext.docId.$ useService(GlobalContextService).globalContext.docId.$
); );
@@ -79,11 +81,7 @@ export const ToolContainer = (props: PropsWithChildren): ReactElement => {
const doc = useLiveData(docId ? docRecordList.doc$(docId) : undefined); const doc = useLiveData(docId ? docRecordList.doc$(docId) : undefined);
const inTrash = useLiveData(doc?.meta$)?.trash; const inTrash = useLiveData(doc?.meta$)?.trash;
return ( return (
<div <div className={clsx(toolStyle, { trash: inTrash }, props.className)}>
className={clsx(toolStyle, {
trash: inTrash,
})}
>
{props.children} {props.children}
</div> </div>
); );