Skip to content

Commit

Permalink
Add code host logos for gitlab & github
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan-kellam committed Sep 7, 2024
1 parent 9c7db75 commit b79d068
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
1 change: 1 addition & 0 deletions public/github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/gitlab.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 52 additions & 3 deletions src/app/search/searchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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: <Image
src={githubLogo}
alt="GitHub"
className="w-4 h-4 dark:invert"
/>
}
}

if (match.Repo.startsWith("gitlab.com")) {
return {
repoName: match.Repo.substring("gitlab.com/".length),
repoLink: `https://${match.Repo}`,
repoIcon: <Image
src={gitlabLogo}
alt="GitLab"
className="w-4 h-4 dark:invert"
/>
}
}

return {
repoName: match.Repo,
repoLink: undefined,
repoIcon: <FileIcon className="w-4 h-4" />
}
}, [match]);

return (
<div>
<div className="bg-cyan-200 dark:bg-cyan-900 primary-foreground px-2">
<span>{match.Repo} · {match.FileName}</span>
<div className="bg-cyan-200 dark:bg-cyan-900 primary-foreground px-2 flex flex-row gap-2 items-center">
{repoIcon}
<span
className={clsx("font-medium", {
"cursor-pointer hover:underline": repoLink,
})}
onClick={() => {
if (repoLink) {
window.open(repoLink, "_blank");
}
}}
>
{repoName}
</span>
<span>· {match.FileName}</span>
</div>
{matches.map((match, index) => {
const fragment = match.Fragments[0];
Expand Down

0 comments on commit b79d068

Please sign in to comment.