Skip to content

Commit

Permalink
fix(web): echo terminal not working in docs modal (novuhq#5875)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsoderberg authored Jun 30, 2024
1 parent e7360d6 commit c7c9266
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,8 @@
"liquidjs",
"tailwindcss",
"focusable",
"textareas"
"textareas",
"echoterminal"
],
"flagWords": [],
"patterns": [
Expand Down
9 changes: 8 additions & 1 deletion apps/web/src/components/docs/Docs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { PropsWithChildren, ReactNode, useEffect, useMemo } from 'react';
import { DOCS_URL, MINTLIFY_IMAGE_URL } from './docs.const';
import { Highlight } from './Highlight';
import { DocsQueryResults } from './useLoadDocs';
import { useEchoTerminalScript } from '../../hooks/useEchoTerminalScript';

const Text = styled('p', text);
const LiText = styled('span', text);
Expand Down Expand Up @@ -38,9 +39,15 @@ export const Docs = ({ code = '', description = '', title = '', isLoading, child
return null;
}

return getMDXComponent(code);
return getMDXComponent(code, {
echoterminal: {
EchoTerminal: () => <nv-echo-terminal></nv-echo-terminal>,
},
});
}, [code]);

useEchoTerminalScript();

// Workaround for img tags that is not parsed correctly by mdx-bundler
useEffect(() => {
if (Component === null || isLoading) {
Expand Down
12 changes: 12 additions & 0 deletions apps/web/src/echo-terminal.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { DOMAttributes } from 'react';

type CustomElement<T> = Partial<T & DOMAttributes<T> & { children: any }>;

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace JSX {
interface IntrinsicElements {
['nv-echo-terminal']: CustomElement<any>;
}
}
}
12 changes: 12 additions & 0 deletions apps/web/src/hooks/useEchoTerminalScript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useEffect } from 'react';

export const useEchoTerminalScript = () => {
useEffect(() => {
if (!document.getElementById('echo-terminal-loader')) {
const script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/gh/novuhq/docs/echo-terminal.min.js';
script.id = 'echo-terminal-loader';
document.body.appendChild(script);
}
}, []);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,9 @@ import { AdditionInformationLink } from '../AdditionInformationLink';
import { CodeSnippet } from '../CodeSnippet';
import { text, title } from '@novu/novui/recipes';
import { IconCellTower, IconCloudQueue, IconCode, IconHealthAndSafety } from '@novu/design-system';
import { DOMAttributes, useEffect } from 'react';
import { useEffect } from 'react';
import { useMantineTheme } from '@mantine/core';

type CustomElement<T> = Partial<T & DOMAttributes<T> & { children: any }>;

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace JSX {
interface IntrinsicElements {
['nv-echo-terminal']: CustomElement<any>;
}
}
}
import { useEchoTerminalScript } from '../../../../hooks/useEchoTerminalScript';

const link = 'https://docs.novu.co/framework/quickstart';

Expand All @@ -40,14 +30,7 @@ export const EchoTab = ({ className }: { className?: string }) => {
segment.track(`Additional Info Link - [Get Started]`, { href: link, tab: OnboardingUseCasesTabsEnum.ECHO });
};

useEffect(() => {
if (!document.getElementById('echo-terminal-loader')) {
const script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/gh/novuhq/docs/echo-terminal.min.js';
script.id = 'echo-terminal-loader';
document.body.appendChild(script);
}
}, []);
useEchoTerminalScript();

useEffect(() => {
const tabs = document.getElementsByClassName('nv-terminal-tab');
Expand Down

0 comments on commit c7c9266

Please sign in to comment.