mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-10-10 19:32:02 +00:00
fix lint errors
This commit is contained in:
parent
8d30b52fc1
commit
922cd52f1b
5 changed files with 40 additions and 45 deletions
|
@ -1,10 +1,9 @@
|
||||||
import {matchEmoji, matchMention, matchIssue} from '../../utils/match.js';
|
import {matchEmoji, matchMention, matchIssue} from '../../utils/match.js';
|
||||||
import {emojiString} from '../emoji.js';
|
import {emojiString} from '../emoji.js';
|
||||||
import {getIssueIcon, getIssueColor,isIssueSuggestionsLoaded, fetchIssueSuggestions} from '../issue.js'
|
import {getIssueIcon, getIssueColor, isIssueSuggestionsLoaded, fetchIssueSuggestions} from '../issue.js';
|
||||||
import {svg} from '../../svg.js'
|
import {svg} from '../../svg.js';
|
||||||
import {createElementFromHTML} from '../../utils/dom.js';
|
import {createElementFromHTML} from '../../utils/dom.js';
|
||||||
import { GET } from '../../modules/fetch.js';
|
import {parseIssueHref} from '../../utils.js';
|
||||||
import {parseIssueHref} from '../../utils.js'
|
|
||||||
|
|
||||||
async function issueSuggestions(text) {
|
async function issueSuggestions(text) {
|
||||||
const key = '#';
|
const key = '#';
|
||||||
|
@ -19,7 +18,7 @@ async function issueSuggestions(text) {
|
||||||
const li = document.createElement('li');
|
const li = document.createElement('li');
|
||||||
li.setAttribute('role', 'option');
|
li.setAttribute('role', 'option');
|
||||||
li.setAttribute('data-value', `${key}${issue.number}`);
|
li.setAttribute('data-value', `${key}${issue.number}`);
|
||||||
li.classList.add('tw-flex', 'tw-gap-2')
|
li.classList.add('tw-flex', 'tw-gap-2');
|
||||||
|
|
||||||
const icon = svg(getIssueIcon(issue), 16, ['text', getIssueColor(issue)].join(' '));
|
const icon = svg(getIssueIcon(issue), 16, ['text', getIssueColor(issue)].join(' '));
|
||||||
li.append(createElementFromHTML(icon));
|
li.append(createElementFromHTML(icon));
|
||||||
|
@ -41,8 +40,6 @@ async function issueSuggestions(text) {
|
||||||
export function initTextExpander(expander) {
|
export function initTextExpander(expander) {
|
||||||
if (!expander) return;
|
if (!expander) return;
|
||||||
|
|
||||||
const textarea = expander.querySelector('textarea');
|
|
||||||
|
|
||||||
expander?.addEventListener('text-expander-change', ({detail: {key, provide, text}}) => {
|
expander?.addEventListener('text-expander-change', ({detail: {key, provide, text}}) => {
|
||||||
if (key === ':') {
|
if (key === ':') {
|
||||||
const matches = matchEmoji(text);
|
const matches = matchEmoji(text);
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
import { GET } from '../modules/fetch.js';
|
import {GET} from '../modules/fetch.js';
|
||||||
import {parseIssueHref, parseRepoOwnerPathInfo} from '../utils.js'
|
import {parseIssueHref, parseRepoOwnerPathInfo} from '../utils.js';
|
||||||
|
|
||||||
export function getIssueIcon(issue) {
|
export function getIssueIcon(issue) {
|
||||||
if (issue.pull_request) {
|
if (issue.pull_request) {
|
||||||
if (issue.state === 'open') {
|
if (issue.state === 'open') {
|
||||||
if (issue.pull_request.draft === true) {
|
if (issue.pull_request.draft === true) {
|
||||||
return 'octicon-git-pull-request-draft'; // WIP PR
|
return 'octicon-git-pull-request-draft'; // WIP PR
|
||||||
}
|
|
||||||
return 'octicon-git-pull-request'; // Open PR
|
|
||||||
} else if (issue.pull_request.merged === true) {
|
|
||||||
return 'octicon-git-merge'; // Merged PR
|
|
||||||
}
|
}
|
||||||
return 'octicon-git-pull-request'; // Closed PR
|
return 'octicon-git-pull-request'; // Open PR
|
||||||
} else if (issue.state === 'open') {
|
} else if (issue.pull_request.merged === true) {
|
||||||
return 'octicon-issue-opened'; // Open Issue
|
return 'octicon-git-merge'; // Merged PR
|
||||||
}
|
}
|
||||||
return 'octicon-issue-closed'; // Closed Issue
|
return 'octicon-git-pull-request'; // Closed PR
|
||||||
|
} else if (issue.state === 'open') {
|
||||||
|
return 'octicon-issue-opened'; // Open Issue
|
||||||
}
|
}
|
||||||
|
return 'octicon-issue-closed'; // Closed Issue
|
||||||
|
}
|
||||||
|
|
||||||
export function getIssueColor(issue) {
|
export function getIssueColor(issue) {
|
||||||
if (issue.pull_request) {
|
if (issue.pull_request) {
|
||||||
if (issue.pull_request.draft === true) {
|
if (issue.pull_request.draft === true) {
|
||||||
|
@ -33,7 +33,7 @@ export function getIssueColor(issue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isIssueSuggestionsLoaded() {
|
export function isIssueSuggestionsLoaded() {
|
||||||
return !!window.config.issueValues
|
return Boolean(window.config.issueValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchIssueSuggestions() {
|
export async function fetchIssueSuggestions() {
|
||||||
|
@ -51,4 +51,4 @@ export async function fetchIssueSuggestions() {
|
||||||
const res = await GET(`${window.config.appSubUrl}/${issuePathInfo.ownerName}/${issuePathInfo.repoName}/issues/suggestions`);
|
const res = await GET(`${window.config.appSubUrl}/${issuePathInfo.ownerName}/${issuePathInfo.repoName}/issues/suggestions`);
|
||||||
const issues = await res.json();
|
const issues = await res.json();
|
||||||
window.config.issueValues = issues;
|
window.config.issueValues = issues;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
import emojis from '../../../assets/emoji.json';
|
import emojis from '../../../assets/emoji.json';
|
||||||
import {GET} from '../modules/fetch.js';
|
|
||||||
|
|
||||||
|
|
||||||
const maxMatches = 6;
|
const maxMatches = 6;
|
||||||
|
|
||||||
|
@ -46,12 +44,12 @@ export function matchMention(queryText) {
|
||||||
|
|
||||||
export function matchIssue(queryText, currentIssue = null) {
|
export function matchIssue(queryText, currentIssue = null) {
|
||||||
const issues = (window.config.issueValues ?? []).filter(
|
const issues = (window.config.issueValues ?? []).filter(
|
||||||
issue => issue.number !== currentIssue
|
(issue) => issue.number !== currentIssue,
|
||||||
);
|
);
|
||||||
const query = queryText.toLowerCase().trim();
|
const query = queryText.toLowerCase().trim();
|
||||||
|
|
||||||
if (!query) {
|
if (!query) {
|
||||||
return [...issues]
|
return Array.from(issues)
|
||||||
.sort((a, b) => b.number - a.number)
|
.sort((a, b) => b.number - a.number)
|
||||||
.slice(0, maxMatches);
|
.slice(0, maxMatches);
|
||||||
}
|
}
|
||||||
|
@ -61,8 +59,8 @@ export function matchIssue(queryText, currentIssue = null) {
|
||||||
|
|
||||||
if (isDigital) {
|
if (isDigital) {
|
||||||
// Find issues/prs with number starting with the query (prefix), sorted by number ascending
|
// Find issues/prs with number starting with the query (prefix), sorted by number ascending
|
||||||
const prefixMatches = issues.filter(issue =>
|
const prefixMatches = issues.filter((issue) =>
|
||||||
String(issue.number).startsWith(query)
|
String(issue.number).startsWith(query),
|
||||||
).sort((a, b) => a.number - b.number);
|
).sort((a, b) => a.number - b.number);
|
||||||
|
|
||||||
results.push(...prefixMatches);
|
results.push(...prefixMatches);
|
||||||
|
@ -71,8 +69,8 @@ export function matchIssue(queryText, currentIssue = null) {
|
||||||
if (!isDigital || results.length < maxMatches) {
|
if (!isDigital || results.length < maxMatches) {
|
||||||
// Fallback: find by title match, sorted by number descending
|
// Fallback: find by title match, sorted by number descending
|
||||||
const titleMatches = issues
|
const titleMatches = issues
|
||||||
.filter(issue =>
|
.filter((issue) =>
|
||||||
issue.title.toLowerCase().includes(query)
|
issue.title.toLowerCase().includes(query),
|
||||||
)
|
)
|
||||||
.sort((a, b) => b.number - a.number);
|
.sort((a, b) => b.number - a.number);
|
||||||
|
|
||||||
|
|
|
@ -65,5 +65,5 @@ test('matchIssue', () => {
|
||||||
window.config.issueValues[2],
|
window.config.issueValues[2],
|
||||||
window.config.issueValues[7],
|
window.config.issueValues[7],
|
||||||
window.config.issueValues[9],
|
window.config.issueValues[9],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,15 +16,15 @@ window.config = {
|
||||||
{key: 'org7 User 7', value: 'org7', name: 'org7', fullname: 'User 7', avatar: 'https://avatar7.com'},
|
{key: 'org7 User 7', value: 'org7', name: 'org7', fullname: 'User 7', avatar: 'https://avatar7.com'},
|
||||||
],
|
],
|
||||||
issueValues: [
|
issueValues: [
|
||||||
{number: 10, title:'Issue'},
|
{number: 10, title: 'Issue'},
|
||||||
{number: 9, title:'Foo issue'},
|
{number: 9, title: 'Foo issue'},
|
||||||
{number: 8, title:'Foo issue'},
|
{number: 8, title: 'Foo issue'},
|
||||||
{number: 7, title:'Merged PR'},
|
{number: 7, title: 'Merged PR'},
|
||||||
{number: 6, title:'Closed PR'},
|
{number: 6, title: 'Closed PR'},
|
||||||
{number: 5, title:'PR'},
|
{number: 5, title: 'PR'},
|
||||||
{number: 4, title:'WIP: PR'},
|
{number: 4, title: 'WIP: PR'},
|
||||||
{number: 3, title:'Closed issue'},
|
{number: 3, title: 'Closed issue'},
|
||||||
{number: 2, title:'PR'},
|
{number: 2, title: 'PR'},
|
||||||
{number: 1, title:'Issue'},
|
{number: 1, title: 'Issue'},
|
||||||
]
|
],
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue