Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
40 lines
1.6 KiB
TypeScript
40 lines
1.6 KiB
TypeScript
import {fomanticQuery} from '../modules/fomantic/base.ts';
|
|
import {html, htmlRaw} from '../utils/html.ts';
|
|
import {svg} from '../svg.ts';
|
|
|
|
type RepoItem = {full_name: string; html_url: string; private: boolean; fork: boolean};
|
|
type RepoSearchResponse = {data: Array<{repository: RepoItem}>};
|
|
|
|
function repoIcon(repo: RepoItem): string {
|
|
if (repo.private) return svg('octicon-lock', 16);
|
|
if (repo.fork) return svg('octicon-repo-forked', 16);
|
|
return svg('octicon-repo', 16);
|
|
}
|
|
|
|
// quick repo switcher: the caret next to the repo name opens a remote-search dropdown
|
|
// listing the owner's repositories, and navigates to the selected one
|
|
export function initRepoSwitcher(el: HTMLElement) {
|
|
const currentFullName = el.getAttribute('data-current-full-name');
|
|
const $dropdown = fomanticQuery(el);
|
|
$dropdown.dropdown({
|
|
showOnFocus: false, // don't auto popup the dropdown menu, avoid interrupting users keyboard navigation on the page
|
|
apiSettings: {
|
|
url: el.getAttribute('data-query-url')!,
|
|
onResponse: (response: RepoSearchResponse) => ({results: response.data.map(({repository: repo}) => {
|
|
const svgCheck = repo.full_name === currentFullName ? svg('octicon-check', 16) : '';
|
|
const svgRepoIcon = repoIcon(repo);
|
|
return {
|
|
type: 'html',
|
|
html: html`
|
|
<a class="item" href="${repo.html_url}">
|
|
<span class="tw-w-[16px]">${htmlRaw(svgCheck)}</span>
|
|
<span>${htmlRaw(svgRepoIcon)}</span>
|
|
<span class="gt-ellipsis">${repo.full_name.split('/')[1]}</span>
|
|
</a>
|
|
`,
|
|
};
|
|
})}),
|
|
},
|
|
});
|
|
}
|