优化提示

This commit is contained in:
IndieKKY
2024-10-06 14:07:57 +08:00
parent 86746dc2a3
commit 6e9132d657
3 changed files with 85 additions and 48 deletions

View File

@@ -0,0 +1,27 @@
import React from 'react';
import { useAppSelector } from '../hooks/redux';
import { openOptionsPage } from '../utils/chromeUtils';
const ApiKeyReminder: React.FC = () => {
const apiKey = useAppSelector(state => state.env.envData.apiKey);
const geminiApiKey = useAppSelector(state => state.env.envData.geminiApiKey);
const aiType = useAppSelector(state => state.env.envData.aiType);
if ((aiType === 'gemini' && geminiApiKey) || (aiType !== 'gemini' && apiKey)) {
return null;
}
return (
<div className="flex items-center justify-between p-2 bg-yellow-100 text-yellow-800 text-sm rounded-md">
<span>API密钥以使用总结及翻译功能</span>
<button
className="px-2 py-1 bg-yellow-200 hover:bg-yellow-300 rounded text-xs font-medium transition-colors"
onClick={openOptionsPage}
>
</button>
</div>
);
};
export default ApiKeyReminder;

View File

@@ -38,6 +38,7 @@ import useKeyService from '../hooks/useKeyService'
import Ask from './Ask'
import { v4 } from 'uuid'
import RateExtension from '../components/RateExtension'
import ApiKeyReminder from './ApiKeyReminder'
const Body = () => {
const dispatch = useAppDispatch()
@@ -291,6 +292,8 @@ const Body = () => {
<li>(使)</li>
</ul>
<ApiKeyReminder />
{/* <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 */}

7
src/utils/chromeUtils.ts Normal file
View File

@@ -0,0 +1,7 @@
export const openOptionsPage = () => {
if (chrome.runtime.openOptionsPage) {
chrome.runtime.openOptionsPage();
} else {
window.open(chrome.runtime.getURL('options.html'));
}
};