Skip to content
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

feature: edits required for public page to work on multiple sites #2971

Merged
merged 6 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions clients/search-component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"import": "./dist/vanilla/index.js"
}
},
"version": "0.2.29",
"version": "0.2.30",
"license": "MIT",
"homepage": "https://github.com/devflowinc/trieve/tree/main/clients/search-component",
"scripts": {
Expand All @@ -29,6 +29,7 @@
"lint": "eslint",
"build:clean": "rm -rf dist && yarn type:dts && yarn build",
"build": "run-s build:src build:css type:dts",
"build:watch": "run-p watch:js build:src build:css type:dts",
"build:src": "node ./scripts/build.js",
"type:dts": "tsc --emitDeclarationOnly --declarationMap",
"build:css": "npx postcss src/app.css -o dist/index.css && cp src/styles.d.ts dist/",
Expand Down Expand Up @@ -56,7 +57,7 @@
"react-dom": "^18.3.1",
"tailwind": "^4.0.0",
"tailwindcss": "^3.4.11",
"tailwindcss-scoped-preflight": "^3.4.4",
"tailwindcss-scoped-preflight": "^3.4.10",
"typescript": "^5.6.2",
"typescript-eslint": "^8.3.0"
},
Expand Down
39 changes: 4 additions & 35 deletions clients/search-component/src/TrieveModal/Chat/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,6 @@ import React, {
} from "react";

const styles = {
root: {
width: "100%",
overflow: "hidden",
},
scroll: {
display: "flex",
overflowX: "hidden",
scrollSnapType: "x mandatory",
scrollBehavior: "smooth",
width: "100%",
listStyle: "none",
padding: 0,
margin: 0,
},
item: {
flex: "0 0 auto",
padding: "1rem",
scrollSnapAlign: "start",
boxSizing: "border-box",
},
itemSnapPoint: {
scrollSnapAlign: "start",
},
controls: {
display: "flex",
justifyContent: "center",
alignItems: "center",
marginTop: "5px",
},
nextPrevButton: {
fontSize: "16px",
cursor: "pointer",
Expand Down Expand Up @@ -109,15 +80,13 @@ export const Carousel = ({ children }: { children: React.ReactNode }) => {
const goToPage = (pageIndex: number) => setCurrentPage(pageIndex);

return (
<div style={styles.root}>
<ul style={styles.scroll} ref={scrollRef}>
<div className="carousel-root">
<ul className="carousel-scroll" ref={scrollRef}>
{allProductsCarousel.map((child, index) => (
<li
className="carousel-item"
className={child ? "carousel-item carousel-item-visibile" : "carousel-item carousel-item-hidden"}
style={{
...styles.item,
width: `calc(100% / ${itemsPerPage})`,
visibility: child ? "visible" : "hidden",
}}
key={index}
>
Expand All @@ -126,7 +95,7 @@ export const Carousel = ({ children }: { children: React.ReactNode }) => {
))}
</ul>
{numPages > 1 && (
<div style={styles.controls}>
<div className="carousel-controls">
<button
style={{
...styles.nextPrevButton,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const SearchMode = () => {
}, [results]);

return (
<Suspense fallback={<div className="hidden"> </div>}>
<Suspense fallback={<div className="suspense-fallback"> </div>}>
<div
className={`close-modal-button search ${props.type}`}
onClick={() => setOpen(false)}
Expand Down
6 changes: 3 additions & 3 deletions clients/search-component/src/TrieveModal/Tags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const Tags = () => {
<kbd className="commands-key">
<EnterKeyIcon />
</kbd>
<span className="label">to select</span>
<span>to select</span>
</li>
<li key="arrow-key-commands">
<kbd className="commands-key">
Expand All @@ -38,13 +38,13 @@ export const Tags = () => {
<kbd className="commands-key">
<ArrowUpIcon />
</kbd>
<span className="label">to navigate</span>
<span>to navigate</span>
</li>
<li key="esc-key-command">
<kbd className="commands-key">
<EscKeyIcon />
</kbd>
<span className="label">to close</span>
<span>to close</span>
</li>
</ul>
))
Expand Down
44 changes: 43 additions & 1 deletion clients/search-component/src/TrieveModal/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

body {
#trieve-search-modal-overlay {
@apply bg-black/60 w-screen fixed inset-0 h-screen animate-overlayShow backdrop-blur-sm z-[998];
@apply bg-black/60 w-screen fixed inset-0 h-screen animate-overlayShow backdrop-blur-sm;
}

.close-icon {
Expand All @@ -33,6 +33,10 @@ body {
@apply pl-2 flex gap-2 w-full overflow-x-auto;
}

.suspense-fallback {
@apply hidden;
}

::-webkit-scrollbar {
width: 6px;
height: 6px;
Expand Down Expand Up @@ -309,6 +313,44 @@ body {
.additional-image-links {
@apply gap-2 mt-4 mb-4 flex flex-row;

.carousel-root {
width: 100%;
overflow: hidden;
}

.carousel-scroll {
display: flex;
overflow-x: hidden;
scroll-snap-type: x-mandatory;
scroll-behavior: smooth;
width: 100%;
list-style: none;
padding: 0;
margin: 0;
}

.carousel-item {
flex: 0 0 auto;
padding: 1rem;
scroll-snap-align: start;
box-sizing: border-box;
}

.carousel-item-hidden {
visibility: hidden;
}

.carousel-item-visibile {
visibility: visible;
}

.carousel-controls {
display: flex;
justify-content: center;
align-items: center;
margin-top: 5px;
}

a {
@apply hover:bg-zinc-200 text-zinc-700 hover:text-zinc-950 rounded px-2 text-xs py-1 line-clamp-2 overflow-ellipsis grid-rows-2 w-fit;
}
Expand Down
18 changes: 13 additions & 5 deletions clients/search-component/src/TrieveModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ import { FloatingActionButton } from "./FloatingActionButton";

const Modal = () => {
useKeyboardNavigation();
setClickTriggers();
const { mode, open, setOpen, setMode, props } = useModalState();
const { askQuestion, chatWithGroup } = useChatState();

useEffect(() => {
setClickTriggers(
setOpen,
setMode,
props
);
}, []);

useEffect(() => {
const onViewportResize = () => {
const viewportHeight = window.visualViewport?.height;
Expand Down Expand Up @@ -105,7 +112,7 @@ const Modal = () => {
document.documentElement.style.setProperty(
"--tv-prop-brand-font-family",
props.brandFontFamily ??
`Maven Pro, ui-sans-serif, system-ui, sans-serif,
`Maven Pro, ui-sans-serif, system-ui, sans-serif,
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"`
);
}, [props.brandColor, props.brandFontFamily]);
Expand All @@ -127,12 +134,13 @@ const Modal = () => {
setOpen(false);
}}
id="trieve-search-modal-overlay"
style={{ zIndex: props.zIndex ?? 1000 }}
></div>
<div
id="trieve-search-modal"
className={`${mode === "chat" ? "chat-modal-mobile " : ""} ${
props.theme === "dark" ? "dark " : ""
} ${props.type}`.trim()}
className={`${mode === "chat" ? "chat-modal-mobile " : ""} ${props.theme === "dark" ? "dark " : ""
} ${props.type}`.trim()}
style={{ zIndex: props.zIndex ? props.zIndex + 1 : 1001 }}
>
{props.allowSwitchingModes && <ModeSwitch />}
<div
Expand Down
3 changes: 3 additions & 0 deletions clients/search-component/src/utils/hooks/modal-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ export type ModalProps = {
buttonTriggers?: {
selector: string;
mode: SearchModes;
removeListeners?: boolean;
}[];
zIndex?: number;
showFloatingButton?: boolean;
floatingButtonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right";
};
Expand Down Expand Up @@ -110,6 +112,7 @@ const defaultProps = {
openLinksInNewTab: false,
currencyPosition: "before" as currencyPosition,
responsive: false,
zIndex: 1000,
debounceMs: 0,
show: true,
position: "bottom-right" as
Expand Down
29 changes: 25 additions & 4 deletions clients/search-component/src/utils/hooks/setClickTriggers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
import { startTransition } from "react";
import { useModalState } from "./modal-context";
import { ModalProps, SearchModes } from "./modal-context";

export const setClickTriggers = () => {
const { setOpen, setMode, props } = useModalState();
export const setClickTriggers = (
setOpen: (open: boolean) => void,
setMode: React.Dispatch<React.SetStateAction<SearchModes>>,
props: ModalProps
) => {
const removeAllClickListeners = (selector: string): Element | null => {
const element: Element | null = document.querySelector(selector);
if (!element) return null;
// Vue click attributes
element.removeAttribute("@click.prevent");
element.removeAttribute("@click");
// @ts-expect-error Property 'href' does not exist on type 'Element'. [2339]
element.href = "#";

const newElement = element.cloneNode(true);
element?.parentNode?.replaceChild(newElement, element);
return newElement as unknown as Element;
}

props.buttonTriggers?.forEach((trigger) => {
const element = document.querySelector(trigger.selector);
let element: Element | null = document.querySelector(trigger.selector);
if (trigger.removeListeners ?? true) {
element = removeAllClickListeners(trigger.selector);
console.log("Removed click listeners from", trigger.selector);
}

if (element) {
element.addEventListener("click", () => {
startTransition(() => {
Expand Down
1 change: 1 addition & 0 deletions clients/search-component/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default {
"#trieve-search-component",
"#trieve-search-modal",
"#trieve-search-modal-overlay",
"#open-trieve-modal"
],
{
rootStyles: true,
Expand Down
9 changes: 9 additions & 0 deletions clients/ts-sdk/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -6977,6 +6977,10 @@
"mode": {
"type": "string"
},
"removeTriggers": {
"type": "boolean",
"nullable": true
},
"selector": {
"type": "string"
}
Expand Down Expand Up @@ -12447,6 +12451,11 @@
"useGroupSearch": {
"type": "boolean",
"nullable": true
},
"zIndex": {
"type": "integer",
"format": "int32",
"nullable": true
}
}
},
Expand Down
2 changes: 2 additions & 0 deletions clients/ts-sdk/src/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export type BulkDeleteChunkPayload = {

export type ButtonTrigger = {
mode: string;
removeTriggers?: (boolean) | null;
selector: string;
};

Expand Down Expand Up @@ -2080,6 +2081,7 @@ export type PublicPageParameters = {
theme?: ((PublicPageTheme) | null);
type?: (string) | null;
useGroupSearch?: (boolean) | null;
zIndex?: (number) | null;
};

export type PublicPageSearchOptions = {
Expand Down
Loading