From b79d068abd6c5d5cc0527ebb7d82471c9feac086 Mon Sep 17 00:00:00 2001 From: bkellam Date: Fri, 6 Sep 2024 17:37:02 -0700 Subject: [PATCH] Add code host logos for gitlab & github --- public/github.svg | 1 + public/gitlab.svg | 1 + src/app/search/searchResults.tsx | 55 ++++++++++++++++++++++++++++++-- 3 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 public/github.svg create mode 100644 public/gitlab.svg diff --git a/public/github.svg b/public/github.svg new file mode 100644 index 00000000..538ec5bf --- /dev/null +++ b/public/github.svg @@ -0,0 +1 @@ +GitHub \ No newline at end of file diff --git a/public/gitlab.svg b/public/gitlab.svg new file mode 100644 index 00000000..e4a29630 --- /dev/null +++ b/public/gitlab.svg @@ -0,0 +1 @@ +GitLab \ No newline at end of file diff --git a/src/app/search/searchResults.tsx b/src/app/search/searchResults.tsx index fd4d22ed..f276b10e 100644 --- a/src/app/search/searchResults.tsx +++ b/src/app/search/searchResults.tsx @@ -5,7 +5,11 @@ import { Separator } from "@/components/ui/separator"; import { ZoektFileMatch } from "@/lib/types"; import { Scrollbar } from "@radix-ui/react-scroll-area"; import { useMemo, useState } from "react"; -import { DoubleArrowDownIcon, DoubleArrowUpIcon } from "@radix-ui/react-icons"; +import { DoubleArrowDownIcon, DoubleArrowUpIcon, FileIcon } from "@radix-ui/react-icons"; +import Image from "next/image"; +import githubLogo from "../../../public/github.svg"; +import gitlabLogo from "../../../public/gitlab.svg"; +import clsx from "clsx"; const MAX_MATCHES_TO_PREVIEW = 5; @@ -63,10 +67,55 @@ const FileMatch = ({ return sortedMatches; }, [match, showAll]); + const { repoIcon, repoName, repoLink } = useMemo(() => { + if (match.Repo.startsWith("github.com")) { + return { + repoName: match.Repo.substring("github.com/".length), + repoLink: `https://${match.Repo}`, + repoIcon: GitHub + } + } + + if (match.Repo.startsWith("gitlab.com")) { + return { + repoName: match.Repo.substring("gitlab.com/".length), + repoLink: `https://${match.Repo}`, + repoIcon: GitLab + } + } + + return { + repoName: match.Repo, + repoLink: undefined, + repoIcon: + } + }, [match]); + return (
-
- {match.Repo} · {match.FileName} +
+ {repoIcon} + { + if (repoLink) { + window.open(repoLink, "_blank"); + } + }} + > + {repoName} + + · {match.FileName}
{matches.map((match, index) => { const fragment = match.Fragments[0];