Skip to content

Commit 5e5b79e

Browse files
committed
Debug highlight match
1 parent 8d34a6d commit 5e5b79e

File tree

1 file changed

+33
-13
lines changed
  • src/app/(sok)/_components/searchResult

1 file changed

+33
-13
lines changed

src/app/(sok)/_components/searchResult/Debug.jsx

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useSearchParams } from "next/navigation";
44
import { QueryNames } from "@/app/(sok)/_utils/QueryNames";
55
import { mediumDisplayName } from "@/app/_common/utils/utils";
66

7-
function GroupItem({ children, color = "surface-neutral-subtle", tag }) {
7+
function GroupItem({ children, color = "surface-neutral-subtle", tag, match }) {
88
return (
99
<Box
1010
background={color}
@@ -19,8 +19,14 @@ function GroupItem({ children, color = "surface-neutral-subtle", tag }) {
1919
{children}
2020
</BodyShort>
2121
{tag && (
22-
<Box paddingBlock="05" paddingInline="1" background="surface-neutral-subtle">
23-
<BodyShort size="small" textColor="subtle" className="monospace">
22+
<Box
23+
borderColor="border-subtle"
24+
borderWidth="0 0 0 1"
25+
paddingBlock="05"
26+
paddingInline="1"
27+
background={match ? "surface-success-subtle" : "surface-neutral-subtle"}
28+
>
29+
<BodyShort size="small" textColor="subtle">
2430
{tag}
2531
</BodyShort>
2632
</Box>
@@ -30,8 +36,18 @@ function GroupItem({ children, color = "surface-neutral-subtle", tag }) {
3036
);
3137
}
3238

39+
function isMatch(list, string) {
40+
return list.some((it) =>
41+
string
42+
.toLowerCase()
43+
.split(/[ ,;-]/)
44+
.some((word) => word === it.toLowerCase()),
45+
);
46+
}
47+
3348
function Debug({ ad }) {
3449
const searchParams = useSearchParams();
50+
const searchString = searchParams.getAll("q");
3551
const janzzOccupations = ad.categoryList?.filter((it) => it.categoryType === "JANZZ") || [];
3652
const otherOccupationCategories = ad.categoryList?.filter((it) => it.categoryType !== "JANZZ") || [];
3753
const janzzSynonyms =
@@ -46,28 +62,32 @@ function Debug({ ad }) {
4662
<VStack gap="4">
4763
<HStack gap="2">
4864
{searchParams.has(QueryNames.SEARCH_STRING) && (
49-
<GroupItem color={ad.score >= 2 ? "surface-warning-subtle" : "surface-danger-subtle"}>
65+
<GroupItem color={ad.score >= 2 ? "surface-success-subtle" : "surface-danger-subtle"}>
5066
{ad.score?.toFixed(1)}
5167
</GroupItem>
5268
)}
5369

5470
{ad.medium && <GroupItem color="surface-info-subtle">{mediumDisplayName(ad.medium)}</GroupItem>}
55-
71+
</HStack>
72+
<HStack gap="2" align="center">
5673
{janzzOccupations.map((category) => (
57-
<GroupItem color="surface-success-subtle" key={category.id}>
74+
<GroupItem tag="janzz" key={category.id} match={isMatch(searchString, category.name)}>
5875
{category.name}
5976
</GroupItem>
6077
))}
61-
</HStack>
62-
<HStack gap="2" align="center">
78+
6379
{janzzSynonyms.map((tag) => (
64-
<GroupItem key={tag.label} tag="janzz">
80+
<GroupItem key={tag.label} tag="janzz" match={isMatch(searchString, tag.label)}>
6581
{tag.label}
6682
</GroupItem>
6783
))}
6884

6985
{otherOccupationCategories.map((category) => (
70-
<GroupItem key={category.id} tag={category.categoryType?.toLowerCase()}>
86+
<GroupItem
87+
key={category.id}
88+
tag={category.categoryType?.toLowerCase()}
89+
match={isMatch(searchString, category.name)}
90+
>
7191
{category.name}
7292
</GroupItem>
7393
))}
@@ -76,8 +96,8 @@ function Debug({ ad }) {
7696
{ad.properties?.searchtagsai && Array.isArray(ad.properties.searchtagsai) && (
7797
<HStack gap="2" align="center">
7898
{ad.properties.searchtagsai.map((searchTagAi) => (
79-
<GroupItem key={searchTagAi} tag="ai">
80-
{searchTagAi}
99+
<GroupItem key={searchTagAi} tag="ai" match={isMatch(searchString, searchTagAi)}>
100+
{searchTagAi}{" "}
81101
</GroupItem>
82102
))}
83103
</HStack>
@@ -88,7 +108,7 @@ function Debug({ ad }) {
88108
{ad.properties.keywords.split(/[,;]/).map((keyword) => {
89109
if (keyword === "null") return null;
90110
return (
91-
<GroupItem key={keyword} tag="kwrd">
111+
<GroupItem key={keyword} tag="kword" match={isMatch(searchString, keyword)}>
92112
{keyword}
93113
</GroupItem>
94114
);

0 commit comments

Comments
 (0)