优化推荐

This commit is contained in:
IndieKKY
2024-03-18 11:39:35 +08:00
parent 7a03d37c61
commit 72c8f9608e
5 changed files with 130 additions and 71 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@@ -22,7 +22,6 @@ import {
FaRegArrowAltCircleDown,
IoWarning,
MdExpand,
RiFileCopy2Line,
RiTranslate
} from 'react-icons/all'
import classNames from 'classnames'
@@ -32,9 +31,9 @@ import {
ASK_ENABLED_DEFAULT,
HEADER_HEIGHT,
PAGE_SETTINGS,
RECOMMEND_HEIGHT,
SEARCH_BAR_HEIGHT,
SUMMARIZE_ALL_THRESHOLD,
SUMMARIZE_TYPES,
TITLE_HEIGHT
} from '../const'
import {FaClipboardList} from 'react-icons/fa'
@@ -42,6 +41,7 @@ import useTranslate from '../hooks/useTranslate'
import {getSummarize} from '../util/biz_util'
import {openUrl} from '@kky002/kky-util'
import Markdown from '../components/Markdown'
import {random} from 'lodash-es'
const Body = () => {
const dispatch = useAppDispatch()
@@ -56,6 +56,7 @@ const Body = () => {
const translateEnable = useAppSelector(state => state.env.envData.translateEnable)
const summarizeEnable = useAppSelector(state => state.env.envData.summarizeEnable)
const {addSummarizeTask, addAskTask} = useTranslate()
const infos = useAppSelector(state => state.env.infos)
const askFold = useAppSelector(state => state.env.askFold)
const askQuestion = useAppSelector(state => state.env.askQuestion)
const askContent = useAppSelector(state => state.env.askContent)
@@ -70,6 +71,10 @@ const Body = () => {
const title = useAppSelector(state => state.env.title)
const fontSize = useAppSelector(state => state.env.envData.fontSize)
const searchText = useAppSelector(state => state.env.searchText)
const recommendIdx = useMemo(() => random(0, 2), [])
const showSearchInput = useMemo(() => {
return (segments != null && segments.length > 0) && (envData.searchEnabled ? envData.searchEnabled : (envData.askEnabled ?? ASK_ENABLED_DEFAULT))
}, [envData.askEnabled, envData.searchEnabled, segments])
const searchPlaceholder = useMemo(() => {
let placeholder = ''
if (envData.searchEnabled) {
@@ -245,7 +250,7 @@ const Body = () => {
</div>
{/* search */}
{(envData.searchEnabled ? envData.searchEnabled : (envData.askEnabled ?? ASK_ENABLED_DEFAULT)) && <div className='px-2 py-1 flex flex-col relative'>
{showSearchInput && <div className='px-2 py-1 flex flex-col relative'>
<input type='text' className='input input-xs bg-base-200' placeholder={searchPlaceholder} value={searchText} onChange={onSearchTextChange}/>
{searchText && <button className='absolute top-1 right-2 btn btn-ghost btn-xs btn-circle text-base-content/75' onClick={onClearSearchText}><AiOutlineCloseCircle/></button>}
</div>}
@@ -262,7 +267,7 @@ const Body = () => {
<div ref={bodyRef} onWheel={onWheel}
className={classNames('flex flex-col gap-1.5 overflow-y-auto select-text scroll-smooth', floatKeyPointsSegIdx != null && 'pb-[100px]')}
style={{
height: `${totalHeight - HEADER_HEIGHT - TITLE_HEIGHT - (envData.searchEnabled ? SEARCH_BAR_HEIGHT : 0)}px`
height: `${totalHeight - HEADER_HEIGHT - TITLE_HEIGHT - RECOMMEND_HEIGHT - (showSearchInput ? SEARCH_BAR_HEIGHT : 0)}px`
}}
>
{/* ask */}
@@ -298,21 +303,24 @@ const Body = () => {
segmentIdx={segmentIdx} bodyRef={bodyRef}/>)}
{/* tip */}
<div className='flex flex-col items-center text-center pt-1 pb-2'>
<div className='font-semibold text-accent'>💡<span className='underline underline-offset-4'></span>💡</div>
<div className='text-sm desc px-2'><span className='text-amber-600 font-semibold'></span><span
className='text-secondary/75 font-semibold'></span>🥳
</div>
{(segments?.length ?? 0) > 0 && <button className='mt-1.5 btn btn-xs btn-info'
onClick={onCopy}>{SUMMARIZE_TYPES[curSummaryType].name}<RiFileCopy2Line/>
</button>}
</div>
<div className='flex flex-col items-center text-center py-2 mx-4 border-t border-t-base-300'>
{/* <div className='flex flex-col items-center text-center pt-1 pb-2'> */}
{/* <div className='font-semibold text-accent'>💡<span className='underline underline-offset-4'>提示</span>💡</div> */}
{/* <div className='text-sm desc px-2'>可以尝试将<span className='text-amber-600 font-semibold'>概览</span>生成的内容粘贴到<span */}
{/* className='text-secondary/75 font-semibold'>视频评论</span>里,发布后看看有什么效果🥳 */}
{/* </div> */}
{/* {(segments?.length ?? 0) > 0 && <button className='mt-1.5 btn btn-xs btn-info' */}
{/* onClick={onCopy}>点击复制生成的{SUMMARIZE_TYPES[curSummaryType].name}<RiFileCopy2Line/> */}
{/* </button>} */}
{/* </div> */}
{((infos == null) || infos.length === 0) && <div className='flex flex-col'>
<div className='flex flex-col items-center text-center py-2 mx-4'>
<div className='font-semibold text-accent flex items-center gap-1'><img src='/bibigpt.png'
alt='BibiGPT'
alt='BibiGPT logo'
className='w-8 h-8'/>BibiGPT
</div>
<div className='text-sm px-2 desc'><span className='text-amber-600 font-semibold text-base'></span><span className='font-semibold'></span></div>
<div className='text-sm px-2 desc'><span className='text-amber-600 font-semibold text-base'></span><span
className='font-semibold'></span>
</div>
<div className='flex gap-2'>
<a title='BibiGPT' href='https://bibigpt.co/r/bilibili'
onClick={(e) => {
@@ -323,7 +331,7 @@ const Body = () => {
</div>
<div className='flex flex-col items-center text-center py-2 mx-4 border-t border-t-base-300'>
<div className='font-semibold text-accent flex items-center gap-1'><img src='/youtube-caption.png'
alt='youtube caption'
alt='youtube caption logo'
className='w-8 h-8'/>YouTube Caption
</div>
<div className='text-sm px-2 desc'><span className='text-amber-600 font-semibold text-base'>YouTube</span>
@@ -334,13 +342,62 @@ const Body = () => {
e.preventDefault()
openUrl('https://chromewebstore.google.com/detail/fiaeclpicddpifeflpmlgmbjgaedladf')
}} className='link text-sm text-accent'>Chrome商店</a>
<a title='Edge商店' href='https://microsoftedge.microsoft.com/addons/detail/galeejdehabppfgooagmkclpppnbccpc'
<a title='Edge商店'
href='https://microsoftedge.microsoft.com/addons/detail/galeejdehabppfgooagmkclpppnbccpc'
onClick={e => {
e.preventDefault()
openUrl('https://microsoftedge.microsoft.com/addons/detail/galeejdehabppfgooagmkclpppnbccpc')
}} className='link text-sm text-accent'>Edge商店</a>
</div>
</div>
<div className='flex flex-col items-center text-center py-2 mx-4 border-t border-t-base-300'>
<div className='font-semibold text-accent flex items-center gap-1'><img src='/immersive-summary.png'
alt='Immersive Summary logo'
className='w-8 h-8'/>Immersive Summary
</div>
<div className='text-sm px-2 desc'></div>
<div className='flex gap-2'>
<a title='Chrome商店' href='https://chromewebstore.google.com/detail/mcijpllinkhflgpkggimnafkbmpiijah'
onClick={(e) => {
e.preventDefault()
openUrl('https://chromewebstore.google.com/detail/mcijpllinkhflgpkggimnafkbmpiijah')
}} className='link text-sm text-accent'>Chrome商店</a>
</div>
</div>
</div>}
</div>
{/* recommend */}
<div className='' style={{
height: `${RECOMMEND_HEIGHT}px`
}}>
{recommendIdx === 0 && <div className='flex items-center gap-1 rounded shadow-sm bg-base-200/10 m-0.5'>
<a className='link link-accent link-hover font-semibold text-sm flex items-center' onClick={(e) => {
e.preventDefault()
openUrl('https://bibigpt.co/r/bilibili')
}}><img src='/bibigpt.png'
alt='BibiGPT logo'
className='w-8 h-8'/> BibiGPT </a>
<span className='text-sm desc'></span>
</div>}
{recommendIdx === 1 && <div className='flex items-center gap-1 rounded shadow-sm bg-base-200/10 m-1'>
<a className='link link-accent link-hover font-semibold text-sm flex items-center' onClick={(e) => {
e.preventDefault()
openUrl('https://chromewebstore.google.com/detail/fiaeclpicddpifeflpmlgmbjgaedladf')
}}><img src='/youtube-caption.png'
alt='youtube caption logo'
className='w-8 h-8'/>YouTube Caption</a>
<span className='text-sm desc'>YouTube版的字幕列表</span>
</div>}
{recommendIdx === 2 && <div className='flex items-center gap-1 rounded shadow-sm bg-base-200/10 m-1'>
<a className='link link-accent link-hover font-semibold text-sm flex items-center' onClick={(e) => {
e.preventDefault()
openUrl('https://chromewebstore.google.com/detail/mcijpllinkhflgpkggimnafkbmpiijah')
}}><img src='/immersive-summary.png'
alt='Immersive Summary logo'
className='w-8 h-8'/>Immersive Summary</a>
<span className='text-sm desc'></span>
</div>}
</div>
</div>
}

View File

@@ -261,27 +261,27 @@ const MoreBtn = (props: Props) => {
(IndieKKY)
</a>
</li>
<li className='hover:bg-accent'>
<a className='flex items-center' onClick={(e) => {
e.preventDefault()
e.stopPropagation()
openUrl('https://bibigpt.co/r/bilibili')
}}>
<img alt='BibiGPT' src='/bibigpt.png' className='w-[20px] h-[20px] bg-white rounded-sm p-0.5'/>
BibiGPT
</a>
</li>
<li className='hover:bg-accent'>
<a className='flex items-center' onClick={(e) => {
e.preventDefault()
e.stopPropagation()
openUrl('https://chromewebstore.google.com/detail/fiaeclpicddpifeflpmlgmbjgaedladf')
}}>
<img alt='youtube subtitle' src='/youtube-caption.png'
className='w-[20px] h-[20px] bg-white rounded-sm p-0.5'/>
Youtube Caption
</a>
</li>
{/* <li className='hover:bg-accent'> */}
{/* <a className='flex items-center' onClick={(e) => { */}
{/* e.preventDefault() */}
{/* e.stopPropagation() */}
{/* openUrl('https://bibigpt.co/r/bilibili') */}
{/* }}> */}
{/* <img alt='BibiGPT' src='/bibigpt.png' className='w-[20px] h-[20px] bg-white rounded-sm p-0.5'/> */}
{/* BibiGPT */}
{/* </a> */}
{/* </li> */}
{/* <li className='hover:bg-accent'> */}
{/* <a className='flex items-center' onClick={(e) => { */}
{/* e.preventDefault() */}
{/* e.stopPropagation() */}
{/* openUrl('https://chromewebstore.google.com/detail/fiaeclpicddpifeflpmlgmbjgaedladf') */}
{/* }}> */}
{/* <img alt='youtube subtitle' src='/youtube-caption.png' */}
{/* className='w-[20px] h-[20px] bg-white rounded-sm p-0.5'/> */}
{/* Youtube Caption */}
{/* </a> */}
{/* </li> */}
<li className='hover:bg-accent'>
<a className='flex items-center' onClick={(e) => {
dispatch(setPage(PAGE_SETTINGS))

View File

@@ -159,6 +159,7 @@ export const TOTAL_HEIGHT_MAX = 800
export const HEADER_HEIGHT = 44
export const TITLE_HEIGHT = 24
export const SEARCH_BAR_HEIGHT = 32
export const RECOMMEND_HEIGHT = 36
export const WORDS_RATE = 0.75
export const WORDS_MIN = 500

View File

@@ -86,6 +86,7 @@ const useSubtitleService = () => {
if (data.data.totalHeight) {
dispatch(setTotalHeight(Math.min(Math.max(data.data.totalHeight, TOTAL_HEIGHT_MIN), TOTAL_HEIGHT_MAX)))
}
console.debug('setSettings', data.data)
}
}
@@ -98,12 +99,12 @@ const useSubtitleService = () => {
// 有数据时自动展开
useEffect(() => {
if ((data != null) && data.body.length > 0) {
if (infos != null) {
eventBus.emit({
type: EVENT_EXPAND
})
}
}, [data, eventBus])
}, [eventBus, infos])
// 当前未展示 & (未折叠 | 自动展开) & 有列表 => 展示第一个
useEffect(() => {
@@ -207,7 +208,7 @@ const useSubtitleService = () => {
}
}
dispatch(setSegments(segments))
}, [data?.body, dispatch, envData.summarizeEnable, envData.words])
}, [data?.body, dispatch, envData.aiType, envData.model, envData.summarizeEnable, envData.words])
// 每秒更新当前视频时间
useInterval(() => {