mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-14 20:55:53 +08:00
fix: text generation too long hide the operation btn (#271)
This commit is contained in:
parent
f572b55237
commit
f2f19484b8
@ -1,39 +1,39 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import React, { FC, useEffect, useState, useRef } from 'react'
|
import type { FC } from 'react'
|
||||||
|
import React, { useEffect, useRef, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
|
|
||||||
import cn from 'classnames'
|
import cn from 'classnames'
|
||||||
import { useBoolean, useClickAway } from 'ahooks'
|
import { useBoolean, useClickAway } from 'ahooks'
|
||||||
|
import { XMarkIcon } from '@heroicons/react/24/outline'
|
||||||
|
import TabHeader from '../../base/tab-header'
|
||||||
|
import Button from '../../base/button'
|
||||||
|
import s from './style.module.css'
|
||||||
|
import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
|
||||||
import ConfigScence from '@/app/components/share/text-generation/config-scence'
|
import ConfigScence from '@/app/components/share/text-generation/config-scence'
|
||||||
import NoData from '@/app/components/share/text-generation/no-data'
|
import NoData from '@/app/components/share/text-generation/no-data'
|
||||||
// import History from '@/app/components/share/text-generation/history'
|
// import History from '@/app/components/share/text-generation/history'
|
||||||
import { fetchAppInfo, fetchAppParams, sendCompletionMessage, updateFeedback, saveMessage, fetchSavedMessage as doFetchSavedMessage, removeMessage } from '@/service/share'
|
import { fetchSavedMessage as doFetchSavedMessage, fetchAppInfo, fetchAppParams, removeMessage, saveMessage, sendCompletionMessage, updateFeedback } from '@/service/share'
|
||||||
import type { SiteInfo } from '@/models/share'
|
import type { SiteInfo } from '@/models/share'
|
||||||
import type { PromptConfig, MoreLikeThisConfig, SavedMessage } from '@/models/debug'
|
import type { MoreLikeThisConfig, PromptConfig, SavedMessage } from '@/models/debug'
|
||||||
import Toast from '@/app/components/base/toast'
|
import Toast from '@/app/components/base/toast'
|
||||||
import AppIcon from '@/app/components/base/app-icon'
|
import AppIcon from '@/app/components/base/app-icon'
|
||||||
import { Feedbacktype } from '@/app/components/app/chat'
|
import type { Feedbacktype } from '@/app/components/app/chat'
|
||||||
import { changeLanguage } from '@/i18n/i18next-config'
|
import { changeLanguage } from '@/i18n/i18next-config'
|
||||||
import Loading from '@/app/components/base/loading'
|
import Loading from '@/app/components/base/loading'
|
||||||
import { userInputsFormToPromptVariables } from '@/utils/model-config'
|
import { userInputsFormToPromptVariables } from '@/utils/model-config'
|
||||||
import TextGenerationRes from '@/app/components/app/text-generate/item'
|
import TextGenerationRes from '@/app/components/app/text-generate/item'
|
||||||
import SavedItems from '@/app/components/app/text-generate/saved-items'
|
import SavedItems from '@/app/components/app/text-generate/saved-items'
|
||||||
import TabHeader from '../../base/tab-header'
|
import type { InstalledApp } from '@/models/explore'
|
||||||
import { XMarkIcon } from '@heroicons/react/24/outline'
|
|
||||||
import s from './style.module.css'
|
|
||||||
import Button from '../../base/button'
|
|
||||||
import { App } from '@/types/app'
|
|
||||||
import { InstalledApp } from '@/models/explore'
|
|
||||||
import { appDefaultIconBackground } from '@/config'
|
import { appDefaultIconBackground } from '@/config'
|
||||||
|
|
||||||
export type IMainProps = {
|
export type IMainProps = {
|
||||||
isInstalledApp?: boolean,
|
isInstalledApp?: boolean
|
||||||
installedAppInfo? : InstalledApp
|
installedAppInfo?: InstalledApp
|
||||||
}
|
}
|
||||||
|
|
||||||
const TextGeneration: FC<IMainProps> = ({
|
const TextGeneration: FC<IMainProps> = ({
|
||||||
isInstalledApp = false,
|
isInstalledApp = false,
|
||||||
installedAppInfo
|
installedAppInfo,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const media = useBreakpoints()
|
const media = useBreakpoints()
|
||||||
@ -56,7 +56,7 @@ const TextGeneration: FC<IMainProps> = ({
|
|||||||
|
|
||||||
const [messageId, setMessageId] = useState<string | null>(null)
|
const [messageId, setMessageId] = useState<string | null>(null)
|
||||||
const [feedback, setFeedback] = useState<Feedbacktype>({
|
const [feedback, setFeedback] = useState<Feedbacktype>({
|
||||||
rating: null
|
rating: null,
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleFeedback = async (feedback: Feedbacktype) => {
|
const handleFeedback = async (feedback: Feedbacktype) => {
|
||||||
@ -93,21 +93,20 @@ const TextGeneration: FC<IMainProps> = ({
|
|||||||
|
|
||||||
const checkCanSend = () => {
|
const checkCanSend = () => {
|
||||||
const prompt_variables = promptConfig?.prompt_variables
|
const prompt_variables = promptConfig?.prompt_variables
|
||||||
if (!prompt_variables || prompt_variables?.length === 0) {
|
if (!prompt_variables || prompt_variables?.length === 0)
|
||||||
return true
|
return true
|
||||||
}
|
|
||||||
let hasEmptyInput = false
|
let hasEmptyInput = false
|
||||||
const requiredVars = prompt_variables?.filter(({ key, name, required }) => {
|
const requiredVars = prompt_variables?.filter(({ key, name, required }) => {
|
||||||
const res = (!key || !key.trim()) || (!name || !name.trim()) || (required || required === undefined || required === null)
|
const res = (!key || !key.trim()) || (!name || !name.trim()) || (required || required === undefined || required === null)
|
||||||
return res
|
return res
|
||||||
}) || [] // compatible with old version
|
}) || [] // compatible with old version
|
||||||
requiredVars.forEach(({ key }) => {
|
requiredVars.forEach(({ key }) => {
|
||||||
if (hasEmptyInput) {
|
if (hasEmptyInput)
|
||||||
return
|
return
|
||||||
}
|
|
||||||
if (!inputs[key]) {
|
if (!inputs[key])
|
||||||
hasEmptyInput = true
|
hasEmptyInput = true
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (hasEmptyInput) {
|
if (hasEmptyInput) {
|
||||||
@ -138,16 +137,17 @@ const TextGeneration: FC<IMainProps> = ({
|
|||||||
|
|
||||||
setMessageId(null)
|
setMessageId(null)
|
||||||
setFeedback({
|
setFeedback({
|
||||||
rating: null
|
rating: null,
|
||||||
})
|
})
|
||||||
setCompletionRes('')
|
setCompletionRes('')
|
||||||
|
|
||||||
const res: string[] = []
|
const res: string[] = []
|
||||||
let tempMessageId = ''
|
let tempMessageId = ''
|
||||||
|
|
||||||
if (!isPC) {
|
if (!isPC)
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||||
showResSidebar()
|
showResSidebar()
|
||||||
}
|
|
||||||
setResponsingTrue()
|
setResponsingTrue()
|
||||||
sendCompletionMessage(data, {
|
sendCompletionMessage(data, {
|
||||||
onData: (data: string, _isFirstMessage: boolean, { messageId }: any) => {
|
onData: (data: string, _isFirstMessage: boolean, { messageId }: any) => {
|
||||||
@ -161,20 +161,22 @@ const TextGeneration: FC<IMainProps> = ({
|
|||||||
},
|
},
|
||||||
onError() {
|
onError() {
|
||||||
setResponsingFalse()
|
setResponsingFalse()
|
||||||
}
|
},
|
||||||
}, isInstalledApp, installedAppInfo?.id)
|
}, isInstalledApp, installedAppInfo?.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchInitData = () => {
|
const fetchInitData = () => {
|
||||||
return Promise.all([isInstalledApp ? {
|
return Promise.all([isInstalledApp
|
||||||
app_id: installedAppInfo?.id,
|
? {
|
||||||
site: {
|
app_id: installedAppInfo?.id,
|
||||||
title: installedAppInfo?.app.name,
|
site: {
|
||||||
prompt_public: false,
|
title: installedAppInfo?.app.name,
|
||||||
copyright: ''
|
prompt_public: false,
|
||||||
},
|
copyright: '',
|
||||||
plan: 'basic',
|
},
|
||||||
}: fetchAppInfo(), fetchAppParams(isInstalledApp, installedAppInfo?.id)])
|
plan: 'basic',
|
||||||
|
}
|
||||||
|
: fetchAppInfo(), fetchAppParams(isInstalledApp, installedAppInfo?.id)])
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -195,7 +197,7 @@ const TextGeneration: FC<IMainProps> = ({
|
|||||||
})()
|
})()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// Can Use metadata(https://beta.nextjs.org/docs/api-reference/metadata) to set title. But it only works in server side client.
|
// Can Use metadata(https://beta.nextjs.org/docs/api-reference/metadata) to set title. But it only works in server side client.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (siteInfo?.title)
|
if (siteInfo?.title)
|
||||||
document.title = `${siteInfo.title} - Powered by Dify`
|
document.title = `${siteInfo.title} - Powered by Dify`
|
||||||
@ -204,7 +206,7 @@ const TextGeneration: FC<IMainProps> = ({
|
|||||||
const [isShowResSidebar, { setTrue: showResSidebar, setFalse: hideResSidebar }] = useBoolean(false)
|
const [isShowResSidebar, { setTrue: showResSidebar, setFalse: hideResSidebar }] = useBoolean(false)
|
||||||
const resRef = useRef<HTMLDivElement>(null)
|
const resRef = useRef<HTMLDivElement>(null)
|
||||||
useClickAway(() => {
|
useClickAway(() => {
|
||||||
hideResSidebar();
|
hideResSidebar()
|
||||||
}, resRef)
|
}, resRef)
|
||||||
|
|
||||||
const renderRes = (
|
const renderRes = (
|
||||||
@ -212,10 +214,10 @@ const TextGeneration: FC<IMainProps> = ({
|
|||||||
ref={resRef}
|
ref={resRef}
|
||||||
className={
|
className={
|
||||||
cn(
|
cn(
|
||||||
"flex flex-col h-full shrink-0",
|
'flex flex-col h-full shrink-0',
|
||||||
isPC ? 'px-10 py-8' : 'bg-gray-50',
|
isPC ? 'px-10 py-8' : 'bg-gray-50',
|
||||||
isTablet && 'p-6', isMoble && 'p-4')
|
isTablet && 'p-6', isMoble && 'p-4')
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<>
|
<>
|
||||||
<div className='shrink-0 flex items-center justify-between'>
|
<div className='shrink-0 flex items-center justify-between'>
|
||||||
@ -233,32 +235,34 @@ const TextGeneration: FC<IMainProps> = ({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='grow'>
|
<div className='grow overflow-y-auto'>
|
||||||
{(isResponsing && !completionRes) ? (
|
{(isResponsing && !completionRes)
|
||||||
<div className='flex h-full w-full justify-center items-center'>
|
? (
|
||||||
<Loading type='area' />
|
<div className='flex h-full w-full justify-center items-center'>
|
||||||
</div>) : (
|
<Loading type='area' />
|
||||||
<>
|
</div>)
|
||||||
{isNoData
|
: (
|
||||||
? <NoData />
|
<>
|
||||||
: (
|
{isNoData
|
||||||
<TextGenerationRes
|
? <NoData />
|
||||||
className='mt-3'
|
: (
|
||||||
content={completionRes}
|
<TextGenerationRes
|
||||||
messageId={messageId}
|
className='mt-3'
|
||||||
isInWebApp
|
content={completionRes}
|
||||||
moreLikeThis={moreLikeThisConifg?.enabled}
|
messageId={messageId}
|
||||||
onFeedback={handleFeedback}
|
isInWebApp
|
||||||
feedback={feedback}
|
moreLikeThis={moreLikeThisConifg?.enabled}
|
||||||
onSave={handleSaveMessage}
|
onFeedback={handleFeedback}
|
||||||
isMobile={isMoble}
|
feedback={feedback}
|
||||||
isInstalledApp={isInstalledApp}
|
onSave={handleSaveMessage}
|
||||||
installedAppId={installedAppInfo?.id}
|
isMobile={isMoble}
|
||||||
/>
|
isInstalledApp={isInstalledApp}
|
||||||
)
|
installedAppId={installedAppInfo?.id}
|
||||||
}
|
/>
|
||||||
</>
|
)
|
||||||
)}
|
}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
</div>
|
</div>
|
||||||
@ -267,19 +271,18 @@ const TextGeneration: FC<IMainProps> = ({
|
|||||||
if (!appId || !siteInfo || !promptConfig)
|
if (!appId || !siteInfo || !promptConfig)
|
||||||
return <Loading type='app' />
|
return <Loading type='app' />
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={cn(
|
<div className={cn(
|
||||||
isPC && 'flex',
|
isPC && 'flex',
|
||||||
isInstalledApp ? s.installedApp : 'h-screen',
|
isInstalledApp ? s.installedApp : 'h-screen',
|
||||||
'bg-gray-50'
|
'bg-gray-50',
|
||||||
)}>
|
)}>
|
||||||
{/* Left */}
|
{/* Left */}
|
||||||
<div className={cn(
|
<div className={cn(
|
||||||
isPC ? 'w-[600px] max-w-[50%] p-8' : 'p-4',
|
isPC ? 'w-[600px] max-w-[50%] p-8' : 'p-4',
|
||||||
isInstalledApp && 'rounded-l-2xl',
|
isInstalledApp && 'rounded-l-2xl',
|
||||||
"shrink-0 relative flex flex-col pb-10 h-full border-r border-gray-100 bg-white"
|
'shrink-0 relative flex flex-col pb-10 h-full border-r border-gray-100 bg-white',
|
||||||
)}>
|
)}>
|
||||||
<div className='mb-6'>
|
<div className='mb-6'>
|
||||||
<div className='flex justify-between items-center'>
|
<div className='flex justify-between items-center'>
|
||||||
@ -307,12 +310,16 @@ const TextGeneration: FC<IMainProps> = ({
|
|||||||
items={[
|
items={[
|
||||||
{ id: 'create', name: t('share.generation.tabs.create') },
|
{ id: 'create', name: t('share.generation.tabs.create') },
|
||||||
{
|
{
|
||||||
id: 'saved', name: t('share.generation.tabs.saved'), extra: savedMessages.length > 0 ? (
|
id: 'saved',
|
||||||
<div className='ml-1 flext items-center h-5 px-1.5 rounded-md border border-gray-200 text-gray-500 text-xs font-medium'>
|
name: t('share.generation.tabs.saved'),
|
||||||
{savedMessages.length}
|
extra: savedMessages.length > 0
|
||||||
</div>
|
? (
|
||||||
) : null
|
<div className='ml-1 flext items-center h-5 px-1.5 rounded-md border border-gray-200 text-gray-500 text-xs font-medium'>
|
||||||
}
|
{savedMessages.length}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
},
|
||||||
]}
|
]}
|
||||||
value={currTab}
|
value={currTab}
|
||||||
onChange={setCurrTab}
|
onChange={setCurrTab}
|
||||||
@ -340,12 +347,11 @@ const TextGeneration: FC<IMainProps> = ({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{/* copyright */}
|
{/* copyright */}
|
||||||
<div className={cn(
|
<div className={cn(
|
||||||
isInstalledApp ? 'left-[248px]' : 'left-8',
|
isInstalledApp ? 'left-[248px]' : 'left-8',
|
||||||
'fixed bottom-4 flex space-x-2 text-gray-400 font-normal text-xs'
|
'fixed bottom-4 flex space-x-2 text-gray-400 font-normal text-xs',
|
||||||
)}>
|
)}>
|
||||||
<div className="">© {siteInfo.copyright || siteInfo.title} {(new Date()).getFullYear()}</div>
|
<div className="">© {siteInfo.copyright || siteInfo.title} {(new Date()).getFullYear()}</div>
|
||||||
{siteInfo.privacy_policy && (
|
{siteInfo.privacy_policy && (
|
||||||
<>
|
<>
|
||||||
@ -373,7 +379,7 @@ const TextGeneration: FC<IMainProps> = ({
|
|||||||
<div
|
<div
|
||||||
className={cn('fixed z-50 inset-0', isTablet ? 'pl-[128px]' : 'pl-6')}
|
className={cn('fixed z-50 inset-0', isTablet ? 'pl-[128px]' : 'pl-6')}
|
||||||
style={{
|
style={{
|
||||||
background: 'rgba(35, 56, 118, 0.2)'
|
background: 'rgba(35, 56, 118, 0.2)',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{renderRes}
|
{renderRes}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user