-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
348 additions
and
3 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export PUBLIC_CROCT_APP_ID=14881fb0-5b23-4a2c-a05d-446654d08189 | ||
export CROCT_API_KEY=afd986ca-49ef-4705-b75c-c9d91bf3d507:ES256 | ||
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgRxge6XkJ3O9ybjTSat6sPTgyxqYjNNmiGg1P5QWhXTehRANCAATkCdeeySEI58Z7GD5mKlVjW9FS8hbMylVvAW1KMWBpghJ5utZQnm857INWVto3a4m+T96fAU1PUIX/tdROZP22 | ||
|
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,72 @@ | ||
--- | ||
// import { Search as ReactSearch } from './Search'; | ||
// import BaseSearch from '@astrojs/starlight/components/Search.astro'; | ||
import '@orama/wc-components/dist/orama-ui/orama-ui.css'; | ||
export type { Props } from '@astrojs/starlight/props'; | ||
console.log('Redering custom search'); | ||
--- | ||
|
||
<div class="orama-search-bar"> | ||
<orama-search-box /> | ||
<orama-search-button colorScheme="dark" /> | ||
</div> | ||
|
||
<script> | ||
import { defineCustomElements } from '@orama/wc-components/loader'; | ||
import { ORAMA_CLOUD_API_KEY, ORAMA_CLOUD_ENDPOINT } from 'astro:env/client'; | ||
|
||
document.querySelectorAll<HTMLOramaSearchBoxElement>('.orama-search-bar orama-search-box').forEach((el) => { | ||
Object.assign(el, { | ||
index: { | ||
endpoint: ORAMA_CLOUD_ENDPOINT, | ||
api_key: ORAMA_CLOUD_API_KEY, | ||
}, | ||
disableChat: true, | ||
sourcesMap: { | ||
title: 'title', | ||
description: 'content', | ||
}, | ||
resultMap: { | ||
title: 'title', | ||
description: 'content', | ||
}, | ||
searchPlaceholder: 'Search something...', | ||
chatPlaceholder: 'What do you dream of doing with Inox Tools?', | ||
suggestions: [ | ||
'What is Inox Tools?', | ||
'How to use Nanostores on the server?', | ||
'How to use Portals in Astro?', | ||
], | ||
} satisfies Partial<HTMLOramaSearchBoxElement>); | ||
}); | ||
|
||
function updateSearchTheme() { | ||
const theme = document.documentElement.dataset.theme || 'dark'; | ||
document.querySelectorAll('.orama-search-bar').forEach((el) => { | ||
const button = el.querySelector('orama-search-button'); | ||
const box = el.querySelector('orama-search-box'); | ||
if (button) button.colorScheme = theme as any; | ||
if (box) box.colorScheme = theme as any; | ||
}); | ||
} | ||
|
||
updateSearchTheme(); | ||
|
||
const observer = new MutationObserver(updateSearchTheme); | ||
observer.observe(document.documentElement, { attributes: true, subtree: false }); | ||
|
||
defineCustomElements(); | ||
|
||
document.querySelectorAll('.orama-search-bar orama-search-button').forEach((el) => { | ||
el.appendChild(document.createTextNode('Search')) | ||
}); | ||
</script> | ||
|
||
<style> | ||
.orama-search-bar { | ||
width: 100%; | ||
max-width: 22rem; | ||
} | ||
</style> |
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,50 @@ | ||
import type { OramaClient } from '@oramacloud/client'; | ||
|
||
export function getOramaUserId(): string | undefined { | ||
if (typeof document === 'undefined' || typeof window === 'undefined') return; | ||
|
||
const cookies = document.cookie.split(';'); | ||
const oid = cookies.find((cookie) => cookie.trim().startsWith('oid=')); | ||
|
||
if (oid) { | ||
return oid.split('=')[1]; | ||
} | ||
|
||
return; | ||
} | ||
|
||
export function userSessionRefresh( | ||
client: OramaClient, | ||
userId: string | undefined, | ||
updateCallback: (userId: string | undefined) => void | ||
) { | ||
const currentUserId = getOramaUserId(); | ||
if (currentUserId !== userId) { | ||
console.warn('User ID changed:', currentUserId); | ||
client.reset(); | ||
updateCallback(currentUserId); | ||
} | ||
} | ||
|
||
declare global { | ||
interface Window { | ||
posthog: any; | ||
} | ||
} | ||
|
||
export function searchSessionTracking(client: OramaClient, userId: string) { | ||
if (!window?.posthog) return; | ||
try { | ||
if (userId) { | ||
// TODO: remove this console.log | ||
console.log('Identifying user with Cookie ID:', userId); | ||
client.identify(userId); | ||
} else { | ||
// TODO: remove this console.log | ||
console.log('Identifying session with PostHog:', window.posthog.get_distinct_id()); | ||
client.alias(window.posthog.get_distinct_id()); | ||
} | ||
} catch (error) { | ||
console.log(`Error setting identity: ${error}`); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
"baseUrl": ".", | ||
"paths": { | ||
"@/*": ["src/*"] | ||
} | ||
}, | ||
"jsx": "react-jsx", | ||
"jsxImportSource": "react" | ||
} | ||
} |
Oops, something went wrong.