mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-09 17:37:20 -06:00
Backport #40288 * fix #40286 Signed-off-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -12,10 +12,11 @@ type IssueInfo = {
|
||||
|
||||
const issueInfoCache = new Map<string, IssueInfo>();
|
||||
|
||||
async function getIssueInfo(url: string): Promise<IssueInfo> {
|
||||
async function getIssueInfo(url: string): Promise<IssueInfo | null> {
|
||||
if (issueInfoCache.has(url)) return issueInfoCache.get(url)!;
|
||||
const resp = await GET(url);
|
||||
if (!resp.ok) throw new Error(resp.statusText || 'Unknown network error');
|
||||
// fetch already logs network errors in console, we can ignore network errors here
|
||||
if (!resp.ok) return null;
|
||||
const data = await resp.json();
|
||||
issueInfoCache.set(url, data);
|
||||
return data;
|
||||
@@ -26,6 +27,8 @@ async function showRefIssuePopup(link: HTMLAnchorElement, info: IssuePathInfo) {
|
||||
getIssueInfo(`${window.config.appSubUrl}/${info.ownerName}/${info.repoName}/${info.pathType}/${info.indexString}/info`),
|
||||
import('../components/ContextPopup.vue'),
|
||||
]);
|
||||
if (!data) return;
|
||||
|
||||
const el = document.createElement('div');
|
||||
const app = createApp(ContextPopup, {
|
||||
issue: data.convertedIssue,
|
||||
@@ -56,21 +59,24 @@ export function initRefIssueContextPopup() {
|
||||
link.setAttribute('data-ref-issue-popup', '');
|
||||
|
||||
// delay so a mouse passing over the link doesn't fire a fetch
|
||||
let timer: TimeoutId;
|
||||
const cancel = () => {
|
||||
let timer: TimeoutId | undefined;
|
||||
const stopDelayedPopup = () => {
|
||||
if (!timer) return;
|
||||
clearTimeout(timer);
|
||||
timer = undefined;
|
||||
link.removeAttribute('data-ref-issue-popup');
|
||||
link.removeEventListener('mouseleave', cancel);
|
||||
link.removeEventListener('mouseleave', stopDelayedPopup);
|
||||
};
|
||||
timer = setTimeout(async () => {
|
||||
link.removeEventListener('mouseleave', cancel);
|
||||
link.removeEventListener('mouseleave', stopDelayedPopup);
|
||||
try {
|
||||
await showRefIssuePopup(link, issuePathInfo);
|
||||
} catch (err) {
|
||||
console.error('Failed to load issue info:', err);
|
||||
link.removeAttribute('data-ref-issue-popup');
|
||||
console.error('Failed to load issue popup info:', err);
|
||||
} finally {
|
||||
stopDelayedPopup();
|
||||
}
|
||||
}, 300);
|
||||
link.addEventListener('mouseleave', cancel);
|
||||
link.addEventListener('mouseleave', stopDelayedPopup);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user