Skip to content

Commit

Permalink
Merge pull request #773 from alvesjtiago/algolia-search
Browse files Browse the repository at this point in the history
Algolia search
  • Loading branch information
cpengilly authored Aug 14, 2024
2 parents 5b9c67c + b5cf5d0 commit 30ec1b8
Show file tree
Hide file tree
Showing 16 changed files with 4,441 additions and 4,504 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/algolia.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Algolia Index Update

on:
push:
branches: [main]

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "20.x"

- name: Install pnpm
run: npm install -g pnpm

- name: Install dependencies
run: pnpm install

- name: Create and upload index
env:
ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }}
ALGOLIA_WRITE_API_KEY: ${{ secrets.ALGOLIA_WRITE_API_KEY }}
ALGOLIA_INDEX_NAME: ${{ secrets.ALGOLIA_INDEX_NAME }}
run: pnpm index:docs
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ public/sitemap.xml

# log files
*.log

# .env files
.env

# algolia
.algolia
36 changes: 36 additions & 0 deletions components/ScrollDispatcher/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import AlgoliaContext from "@/utils/contexts/AlgoliaContext";
import React, { ReactNode, useContext, useEffect } from "react";
import * as aa from "search-insights";

export default function ScrollDispatcher({
children,
}: Readonly<{
children: ReactNode;
}>) {
const { queryID, objectID } = useContext(AlgoliaContext);

const onScroll = () => {
const bottom =
Math.ceil(window.innerHeight + window.scrollY) >=
document.documentElement.scrollHeight;

if (bottom && queryID && objectID) {
aa.default("convertedObjectIDsAfterSearch", {
index: "docs",
eventName: "Converted Search",
queryID: queryID,
objectIDs: [objectID],
});
}
};

useEffect(() => {
window.addEventListener("scroll", onScroll);

return () => {
window.removeEventListener("scroll", onScroll);
};
}, [queryID, objectID]);

return <div>{children}</div>;
}
Loading

0 comments on commit 30ec1b8

Please sign in to comment.