-
Notifications
You must be signed in to change notification settings - Fork 165
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
Migrate FAQ page into the Typesense backend #401
Draft
ekamuktia
wants to merge
25
commits into
kawalcovid19:main
Choose a base branch
from
ekamuktia:feature/typesense-faq
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 15 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
9ef8171
init faq typesense
ekamuktia 67b7b95
Merge remote-tracking branch 'origin/main' into feature/typesense-faq
ekamuktia 94b56ec
Merge branch 'main' into feature/typesense-faq
ekamuktia 0f12a6a
change FaqData to Faq
ekamuktia a817d3d
Merge branch 'feature/typesense-faq' of https://github.com/ekamuktia/…
ekamuktia a81eacc
filter to modal
ekamuktia 5894fbf
change router to window
ekamuktia 9283a2e
filter params type
ekamuktia b32bd9c
remove modal
ekamuktia cb2a1da
Merge branch 'main' into feature/typesense-faq
ekamuktia 81034e4
change to usetouter
ekamuktia c7c61b2
Merge branch 'feature/typesense-faq' of https://github.com/ekamuktia/…
ekamuktia fb896f7
usefiltermodal as config, console log for debug
ekamuktia 25a7800
usefiltermodal as optional
ekamuktia 7dda93a
usefiltermodal false
ekamuktia f5a0a0f
Merge remote-tracking branch 'origin/main' into feature/typesense-faq
ekamuktia ebf6efb
Merge branch 'main' of https://github.com/ekamuktia/wargabantuwarga.c…
ekamuktia aaac2f1
fix: refinement list select option value
ekamuktia 6f35e72
fix: remove console log
ekamuktia de04d15
Merge branch 'main' of https://github.com/ekamuktia/wargabantuwarga.c…
ekamuktia 96cb318
Merge branch 'main' into feature/typesense-faq
ekamuktia 2ab64b7
Merge branch 'main' into feature/typesense-faq
ekamuktia 69aebe7
Merge branch 'main' of https://github.com/ekamuktia/wargabantuwarga.c…
ekamuktia 6a761e2
Merge branch 'feature/typesense-faq' of https://github.com/ekamuktia/…
ekamuktia c719fb6
Merge branch 'main' into feature/typesense-faq
mazipan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,31 @@ | ||
declare module "typesense-instantsearch-adapter" { | ||
type SearchClient = object; | ||
|
||
export interface TypesenseNode { | ||
host: string; | ||
port: string; | ||
protocol: string; | ||
} | ||
|
||
export interface TypesenseSearchParameters { | ||
queryBy: string; | ||
sortBy?: string; | ||
highlightFullFields?: string; | ||
} | ||
|
||
export interface TypesenseServer { | ||
apiKey: string; | ||
nodes: TypesenseNode[]; | ||
} | ||
|
||
export interface TypesenseInstantsearchAdapterOptions { | ||
server?: TypesenseServer; | ||
additionalSearchParameters: TypesenseSearchParameters; | ||
} | ||
|
||
export default class TypesenseInstantsearchAdapter { | ||
readonly searchClient: SearchClient; | ||
|
||
constructor(options: TypesenseInstantsearchAdapterOptions); | ||
} | ||
} |
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,82 @@ | ||
import { Faq } from "~/lib/faqs"; | ||
|
||
import htmr from "htmr"; | ||
|
||
type FaqListProps = { | ||
data: Faq[]; | ||
}; | ||
|
||
function groupBy<T, U>(data: T[], key: U) { | ||
return data.reduce((acc: any, currentValue: any) => { | ||
const groupKey = currentValue[key]; | ||
if (!acc[groupKey]) { | ||
acc[groupKey] = []; | ||
} | ||
acc[groupKey].push(currentValue); | ||
return acc; | ||
}, {}); | ||
} | ||
|
||
export function FAQList(props: FaqListProps) { | ||
const listFaqs = groupBy(props.data, "kategori_pertanyaan"); | ||
return ( | ||
<div className="space-y-4"> | ||
{Object.keys(listFaqs as Record<string, unknown>).map( | ||
(category: string) => ( | ||
<div | ||
key={category} | ||
className="p-4 bg-white shadow overflow-hidden rounded-md" | ||
> | ||
<div className="relative"> | ||
<div | ||
aria-hidden="true" | ||
className="absolute inset-0 flex items-center" | ||
> | ||
<div className="w-full border-t border-gray-300" /> | ||
</div> | ||
<div className="relative flex flex-row items-center justify-start"> | ||
<span className="pr-3 bg-white text-lg font-medium text-gray-900"> | ||
{category} | ||
</span> | ||
</div> | ||
</div> | ||
<dl className="divide-y divide-gray-200"> | ||
{listFaqs[category].map((question: Faq) => ( | ||
<div | ||
key={question.pertanyaan} | ||
className="pt-6 pb-8 md:grid md:grid-cols-12 md:gap-8" | ||
> | ||
<dt className="text-base font-semibold text-gray-900 md:col-span-5"> | ||
{question.pertanyaan} | ||
</dt> | ||
<dd className="mt-2 md:mt-0 md:col-span-7"> | ||
<p className="text-base text-gray-500"> | ||
{htmr( | ||
question.jawaban.replace(/(?:\r\n|\r|\n)/g, "<br>"), | ||
)} | ||
</p> | ||
<small> | ||
Sumber:{" "} | ||
{question.link ? ( | ||
<a | ||
className="underline text-blue-800" | ||
href={question.link} | ||
rel="noreferrer" | ||
target="_blank" | ||
> | ||
{question.sumber} | ||
</a> | ||
) : ( | ||
question.sumber | ||
)} | ||
</small> | ||
</dd> | ||
</div> | ||
))} | ||
</dl> | ||
</div> | ||
), | ||
)} | ||
</div> | ||
); | ||
} |
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,19 @@ | ||
import { FAQList } from "~/components/faq-list"; | ||
import { Faq } from "~/lib/faqs"; | ||
|
||
import { StateResultsProvided } from "react-instantsearch-core"; | ||
import { connectStateResults } from "react-instantsearch-dom"; | ||
|
||
function Hits(stateResults: StateResultsProvided) { | ||
const { searchResults } = stateResults; | ||
let results: Faq[]; | ||
|
||
try { | ||
results = searchResults.hits as unknown as Faq[]; | ||
} catch (e) { | ||
results = []; | ||
} | ||
return <FAQList data={results} />; | ||
} | ||
|
||
export default connectStateResults(Hits); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented code should not be pushed.