Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed logic for the ellipsis #1106

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/components/pages/search/DevHubHits/DevHubSearchResultCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,9 @@ import classNames from "classnames";
import { Snippet } from "react-instantsearch";

import type { DevHubSearchResultCardProps, HitBreadcrumb } from "./types";
import type { Hit } from "../types";

const DevHubSearchResultCard: FC<DevHubSearchResultCardProps> = ({ hit }) => {
// need to manually add an ellipsis cause Typesense doesn`t support this in the config
const updateHitSnippet = (hit: Hit<any>) => {
if (hit._snippetResult.content.matchedWords?.length) {
hit._snippetResult.content.value = `... ${hit._snippetResult.content.value} ...`;
}
return hit;
};

const updatedHit = updateHitSnippet(hit);
const isEllipsis = !!hit._snippetResult?.content?.matchedWords?.length;

return (
<div className="max-w-[956px]">
Expand Down Expand Up @@ -47,9 +38,12 @@ const DevHubSearchResultCard: FC<DevHubSearchResultCardProps> = ({ hit }) => {
</h5>
<p className="text-heading-5 h-[40px] text-ellipsis overflow-hidden text-search-primary">
<Snippet
hit={updatedHit}
hit={hit}
attribute="content"
className="overflow-hidden text-ellipsis box"
className={classNames("overflow-hidden text-ellipsis box", {
"after:ml-1 after:content-['...'] before:mr-1 before:content-['...']":
isEllipsis,
})}
style={{
WebkitBoxOrient: "vertical",
MozBoxOrient: "vertical",
Expand Down