* fix lookup word

* prevent navigate to oauth url
This commit is contained in:
an-lee
2024-02-02 01:35:25 +08:00
committed by GitHub
parent abde169ead
commit 799e8b3ea6
3 changed files with 21 additions and 22 deletions

View File

@@ -196,7 +196,12 @@ main.init = () => {
});
logger.debug("will-navigate", detail.url);
if (!navigatable) {
if (
!navigatable ||
detail.url.startsWith(
`${process.env.WEB_API_URL || WEB_API_URL}/oauth`
)
) {
logger.debug("prevent navigation", detail.url);
detail.preventDefault();
}

View File

@@ -14,14 +14,14 @@ export const LookupResult = (props: {
}) => {
const { word, context, sourceId, sourceType, onResult } = props;
const [result, setResult] = useState<LookupType>();
const [loading, setLoading] = useState<boolean>(true);
const [loading, setLoading] = useState<boolean>(false);
if (!word) return null;
const { lookupWord } = useAiCommand();
const processLookup = async () => {
if (!word) return;
if (!loading) return;
if (loading) return;
setLoading(true);
lookupWord({
@@ -31,8 +31,10 @@ export const LookupResult = (props: {
sourceType,
})
.then((lookup) => {
setResult(lookup);
onResult && onResult(lookup.meaning);
if (lookup?.meaning) {
setResult(lookup);
onResult && onResult(lookup.meaning);
}
})
.finally(() => {
setLoading(false);

View File

@@ -36,7 +36,7 @@ export const useAiCommand = () => {
return lookup;
}
lookupCommand(
const res = await lookupCommand(
{
word,
context,
@@ -47,23 +47,15 @@ export const useAiCommand = () => {
modelName: currentEngine.model,
baseUrl: currentEngine.baseUrl,
}
)
.then((res) => {
if (res.context_translation?.trim()) {
webApi
.updateLookup(lookup.id, {
meaning: res,
sourceId,
sourceType,
})
.then((lookup) => {
return lookup;
});
}
})
.catch((err) => {
toast.error(`${t("lookupFailed")}: ${err.message}`);
);
if (res.context_translation?.trim()) {
return webApi.updateLookup(lookup.id, {
meaning: res,
sourceId,
sourceType,
});
}
};
const extractStory = async (story: StoryType) => {