-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement orama search functionality for active members and sta…
…ff pages
- Loading branch information
1 parent
1d57d5a
commit 6dfe23f
Showing
12 changed files
with
8,180 additions
and
8,039 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { createContext, useCallback, useEffect, useMemo, useState } from "react" | ||
import { create, insertMultiple, search } from "@orama/orama" | ||
|
||
export const OramaContext = createContext(null) | ||
|
||
export const OramaProvider = ({ children, schema, initialData }) => { | ||
const [db, setDb] = useState(null) | ||
|
||
useEffect(() => { | ||
const init = async () => { | ||
const database = await create({ | ||
schema, | ||
}); | ||
|
||
setDb(database); | ||
|
||
await insertMultiple(database, initialData); | ||
}; | ||
|
||
init() | ||
}, [schema, initialData]) | ||
|
||
const searchDatabase = useCallback( | ||
async(term) => { | ||
if (!db) return null | ||
|
||
if (term) { | ||
const searchResult = await search(db, term) | ||
|
||
const documents = searchResult.hits.map( | ||
(result) => result.document, | ||
) | ||
|
||
return documents | ||
} else { | ||
const allDocuments = Object.values(db?.data?.docs?.docs) | ||
|
||
return allDocuments | ||
} | ||
}, | ||
[db], | ||
) | ||
|
||
const value = useMemo(() => ({ searchDatabase }), [searchDatabase]) | ||
|
||
return ( | ||
<OramaContext.Provider value={value}> | ||
{children} | ||
</OramaContext.Provider> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const activemembersSchema = { | ||
name: "string", | ||
avatar: { | ||
blurDataURL: "string", | ||
blurHeight: "number", | ||
blurWidth: "number", | ||
height: "number", | ||
src: "string", | ||
width: "number", | ||
}, | ||
github: "string", | ||
twitter: "string", | ||
blogUrl: "string", | ||
linkedin: "string", | ||
} | ||
|
||
export default activemembersSchema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const staffmembersSchema = { | ||
name: "string", | ||
avatar: { | ||
blurDataURL: "string", | ||
blurHeight: "number", | ||
blurWidth: "number", | ||
height: "number", | ||
src: "string", | ||
width: "number", | ||
}, | ||
github: "string", | ||
description: "string", | ||
twitter: "string", | ||
blogUrl: "string", | ||
linkedin: "string", | ||
} | ||
|
||
export default staffmembersSchema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
import Layout from "components/Layout" | ||
import ActiveMembers from "components/ActiveMembers" | ||
import { OramaProvider } from "context/OramaProvider" | ||
import activeMembers from "data/activemembers" | ||
import activemembersSchema from "context/schemas/activemembersSchema" | ||
|
||
export default function Home() { | ||
return ( | ||
<Layout className="flex flex-col justify-start mt-[7rem]"> | ||
<ActiveMembers /> | ||
</Layout> | ||
<OramaProvider schema={activemembersSchema} initialData={activeMembers}> | ||
<Layout className="flex flex-col justify-start mt-[7rem]"> | ||
<ActiveMembers /> | ||
</Layout> | ||
</OramaProvider> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
import Layout from "components/Layout" | ||
import Staff from "components/Staff" | ||
import { OramaProvider } from "context/OramaProvider" | ||
import staffmembersSchema from "context/schemas/staffmembersSchema" | ||
import staff from "data/staff" | ||
|
||
export default function Home() { | ||
return ( | ||
<Layout className="flex flex-col justify-start mt-[7rem]"> | ||
<Staff /> | ||
</Layout> | ||
<OramaProvider schema={staffmembersSchema} initialData={staff}> | ||
<Layout className="flex flex-col justify-start mt-[7rem]"> | ||
<Staff /> | ||
</Layout> | ||
</OramaProvider> | ||
) | ||
} |
Oops, something went wrong.