Compare commits
No commits in common. "b0ee3a69f1f33d1a70a197f1a80a1b5246f3e261" and "b136e841f59a12a2508b9a51f2be504aeec9c020" have entirely different histories.
b0ee3a69f1
...
b136e841f5
|
@ -14,24 +14,14 @@ export async function GET(request: NextRequest) {
|
||||||
console.log(search)
|
console.log(search)
|
||||||
const cleanedSearch = search.replace(/[^a-zA-Z\s]/g, "").toLowerCase()
|
const cleanedSearch = search.replace(/[^a-zA-Z\s]/g, "").toLowerCase()
|
||||||
const searchWords = cleanedSearch.split(/\s+/)
|
const searchWords = cleanedSearch.split(/\s+/)
|
||||||
const filteredData = cardData.filter((card) => {
|
const filteredData = cardData.filter((card) =>
|
||||||
let captionArray = card.caption?.toLowerCase().split(/[^a-z]/)
|
searchWords.some((word) =>
|
||||||
if (!captionArray) {
|
card.caption
|
||||||
return false
|
?.toLowerCase()
|
||||||
}
|
.split(/[^a-z]/)
|
||||||
const words = searchWords.filter((word) => captionArray.includes(word))
|
.includes(word)
|
||||||
if (words.length) {
|
)
|
||||||
card.rank = 999999
|
)
|
||||||
for (const word of words) {
|
|
||||||
const index = captionArray.indexOf(word)
|
|
||||||
if (index && index < card.rank) {
|
|
||||||
card.rank = index
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
filteredData.sort((a, b) => a.rank! - b.rank!)
|
|
||||||
return Response.json(filteredData)
|
return Response.json(filteredData)
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ export default function Home() {
|
||||||
)}
|
)}
|
||||||
<form
|
<form
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
style={{ width: "100%", maxWidth: "700px", paddingBottom: "16px" }}
|
style={{ width: "100%", maxWidth: "700px" }}
|
||||||
>
|
>
|
||||||
<Input
|
<Input
|
||||||
placeholder="Type something..."
|
placeholder="Type something..."
|
||||||
|
@ -89,7 +89,6 @@ export default function Home() {
|
||||||
loadMore={loadMore}
|
loadMore={loadMore}
|
||||||
hasMore={cardsDisplayed.length < cards.length}
|
hasMore={cardsDisplayed.length < cards.length}
|
||||||
loader={<CircularProgress />}
|
loader={<CircularProgress />}
|
||||||
style={{ width: "100%" }}
|
|
||||||
>
|
>
|
||||||
<Grid container spacing={2} sx={{ flexGrow: 1 }} key="cardGrid">
|
<Grid container spacing={2} sx={{ flexGrow: 1 }} key="cardGrid">
|
||||||
{cardsDisplayed.map((card) => (
|
{cardsDisplayed.map((card) => (
|
||||||
|
|
|
@ -5,6 +5,5 @@ export type CardType = {
|
||||||
oracleId: string
|
oracleId: string
|
||||||
caption: string
|
caption: string
|
||||||
url?: string
|
url?: string
|
||||||
rank?: number
|
|
||||||
mediumImageUrl: string
|
mediumImageUrl: string
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue