mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-30 17:13:15 +00:00
(refactor): separate browser ready builds
This commit is contained in:
22
extensions/react-widget/src/browser.tsx
Normal file
22
extensions/react-widget/src/browser.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
//exports browser ready methods
|
||||
|
||||
import { createRoot } from "react-dom/client";
|
||||
|
||||
import { DocsGPTWidget } from './components/DocsGPTWidget';
|
||||
import { SearchBar } from './components/SearchBar';
|
||||
import React from "react";
|
||||
if (typeof window !== 'undefined') {
|
||||
const renderWidget = (elementId: string, props = {}) => {
|
||||
const root = createRoot(document.getElementById(elementId) as HTMLElement);
|
||||
root.render(<DocsGPTWidget {...props} />);
|
||||
};
|
||||
const renderSearchBar = (elementId: string, props = {}) => {
|
||||
const root = createRoot(document.getElementById(elementId) as HTMLElement);
|
||||
root.render(<SearchBar {...props} />);
|
||||
};
|
||||
(window as any).renderDocsGPTWidget = renderWidget;
|
||||
|
||||
(window as any).renderSearchBar = renderSearchBar;
|
||||
}
|
||||
|
||||
export { DocsGPTWidget, SearchBar };
|
||||
@@ -69,7 +69,6 @@ const SearchResults = styled.div`
|
||||
position: absolute;
|
||||
display: block;
|
||||
background-color: ${props => props.theme.primary.bg};
|
||||
opacity: 90%;
|
||||
border: 1px solid rgba(0, 0, 0, .1);
|
||||
border-radius: 12px;
|
||||
padding: 8px;
|
||||
@@ -287,7 +286,7 @@ export const SearchBar = ({
|
||||
debounceTimeout.current = setTimeout(() => {
|
||||
getSearchResults(input, apiKey, apiHost, abortController.signal)
|
||||
.then((data) => setResults(data))
|
||||
.catch((err) => console.log(err))
|
||||
.catch((err) => !abortController.signal.aborted && console.log(err))
|
||||
.finally(() => setLoading(false));
|
||||
}, 500);
|
||||
|
||||
@@ -340,10 +339,11 @@ export const SearchBar = ({
|
||||
</InfoButton>
|
||||
{!loading ?
|
||||
(results.length > 0 ?
|
||||
results.map((res) => {
|
||||
results.map((res, key) => {
|
||||
const containsSource = res.source !== 'local';
|
||||
return (
|
||||
<ResultWrapper
|
||||
key={key}
|
||||
onClick={() => {
|
||||
if (!containsSource) return;
|
||||
window.open(res.source, '_blank', 'noopener, noreferrer')
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
//exports methods for React
|
||||
export {SearchBar} from "./components/SearchBar"
|
||||
export { DocsGPTWidget } from "./components/DocsGPTWidget";
|
||||
|
||||
@@ -1,25 +1,7 @@
|
||||
|
||||
//development
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { App } from "./App";
|
||||
import { DocsGPTWidget } from './components/DocsGPTWidget';
|
||||
import { SearchBar } from './components/SearchBar';
|
||||
import React from "react";
|
||||
if (typeof window !== 'undefined') {
|
||||
const renderWidget = (elementId: string, props = {}) => {
|
||||
const root = createRoot(document.getElementById(elementId) as HTMLElement);
|
||||
root.render(<DocsGPTWidget {...props} />);
|
||||
};
|
||||
const renderSearchBar = (elementId: string, props = {}) => {
|
||||
const root = createRoot(document.getElementById(elementId) as HTMLElement);
|
||||
root.render(<SearchBar {...props} />);
|
||||
};
|
||||
(window as any).renderDocsGPTWidget = renderWidget;
|
||||
|
||||
(window as any).renderSearchBar = renderSearchBar;
|
||||
}
|
||||
const container = document.getElementById("app") as HTMLElement;
|
||||
const root = createRoot(container)
|
||||
root.render(<App />);
|
||||
|
||||
export { DocsGPTWidget };
|
||||
export { SearchBar }
|
||||
root.render(<App />);
|
||||
Reference in New Issue
Block a user