Skip to content

Commit

Permalink
Replace lodash/intersection with one-liner
Browse files Browse the repository at this point in the history
  • Loading branch information
DinerIsmail committed Sep 15, 2024
1 parent 50c2734 commit 0955479
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions app/[subdomain]/Web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useCallback, useEffect, useState, useMemo } from 'react'
import dynamic from 'next/dynamic'
import { Box } from '@chakra-ui/react'
import { useDebounce } from 'use-debounce'
import intersection from 'lodash/intersection'
import useLocalStorage from 'use-local-storage'
import {
useQueryParams,
Expand All @@ -15,7 +14,11 @@ import Header from '@components/header'
import useIsMobile from '@hooks/application/useIsMobile'
import MainList from '@components/main-list'
import AlertBanner from '@components/alert-banner'
import { removeNonAlphaNumeric, sortStringsFunc } from '@helpers/utils'
import {
removeNonAlphaNumeric,
sortStringsFunc,
intersection,
} from '@helpers/utils'
import useCategoriesPublic from '@hooks/categories/useCategoriesPublic'
import useTagsPublic from '@hooks/tags/useTagsPublic'
import { Category } from '@prisma/client'
Expand Down Expand Up @@ -151,7 +154,7 @@ export default function Web({
if (query.tags.length > 0) {
results = results.filter((item) => {
const itemTags = item.tags.map((c) => c.label)
return intersection(query.tags, itemTags).length > 0
return intersection([query.tags, itemTags]).length > 0
})
}

Expand Down
4 changes: 4 additions & 0 deletions helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ export function exclude(data, keys) {
Object.entries(data).filter(([key]) => !keys.includes(key)),
)
}

export function intersection(arrays) {
return arrays.reduce((a, b) => a.filter((c) => b.includes(c)))
}

0 comments on commit 0955479

Please sign in to comment.