@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user