-
Notifications
You must be signed in to change notification settings - Fork 278
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
38 changed files
with
499 additions
and
230 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
124 changes: 124 additions & 0 deletions
124
src/components/InjectSDK/components/IntegrationWithPlatform.tsx
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,124 @@ | ||
import { ReactComponent as WebSvg } from '@/assets/image/web-h5.svg'; | ||
import { ReactComponent as MiniprogramSvg } from '@/assets/image/miniprogram.svg'; | ||
import { ReactNode, useMemo, type ComponentType } from 'react'; | ||
import { Trans, useTranslation } from 'react-i18next'; | ||
import { Link } from 'react-router-dom'; | ||
import type { Lang } from 'shiki'; | ||
import { CodeBlock } from '@/components/CodeBlock'; | ||
|
||
export type PlatformName = 'web' | 'miniprogram'; | ||
|
||
export const PLATFORMS: { name: PlatformName; icon: ComponentType }[] = [ | ||
{ | ||
name: 'web', | ||
icon: WebSvg, | ||
}, | ||
{ | ||
name: 'miniprogram', | ||
icon: MiniprogramSvg, | ||
}, | ||
]; | ||
|
||
interface Props { | ||
platform: PlatformName; | ||
onCloseModal: () => void; | ||
} | ||
|
||
export const IntegrationWithPlatform = ({ platform, onCloseModal }: Props) => { | ||
const { t } = useTranslation(); | ||
const deployPath = (location.host + location.pathname).replace(/\/+$/, ''); | ||
const steps = useMemo(() => { | ||
const stepsWithPlatform = { | ||
web: [ | ||
{ | ||
title: t('inject.web.load-sdk'), | ||
code: `<script crossorigin="anonymous" src="${location.protocol}//${deployPath}/page-spy/index.min.js"></script>`, | ||
}, | ||
{ | ||
title: ( | ||
<Trans i18nKey="inject.web.init-sdk"> | ||
<span>slot-0</span> | ||
<a | ||
href="https://github.com/HuolalaTech/page-spy?tab=readme-ov-file#web" | ||
target="_blank" | ||
> | ||
slot-1 | ||
</a> | ||
</Trans> | ||
), | ||
code: `<script> | ||
window.$pageSpy = new PageSpy(); | ||
</script>`, | ||
}, | ||
], | ||
miniprogram: [ | ||
{ | ||
title: t('inject.miniprogram.install-sdk'), | ||
code: `yarn add @huolala-tech/page-spy@latest`, | ||
lang: 'bash', | ||
}, | ||
{ | ||
title: t('inject.miniprogram.request-host'), | ||
code: `https://${window.location.host}\nwss://${window.location.host}`, | ||
}, | ||
{ | ||
title: ( | ||
<Trans i18nKey="inject.miniprogram.init-sdk"> | ||
<span>slot-0</span> | ||
<a | ||
href="https://github.com/HuolalaTech/page-spy?tab=readme-ov-file#mini-program" | ||
target="_blank" | ||
> | ||
slot-1 | ||
</a> | ||
</Trans> | ||
), | ||
code: `// @huolala-tech/page-spy v1.5.x or upper version. \nimport PageSpy from '@huolala-tech/page-spy/miniprogram';\n\nnew PageSpy({ | ||
api: '${deployPath}', | ||
})`, | ||
lang: 'js', | ||
}, | ||
{ | ||
title: t('inject.miniprogram.init-sdk-native'), | ||
code: `import PageSpy from './your/path/page-spy.js';\n\nnew PageSpy({ | ||
api: '${deployPath}', | ||
})`, | ||
lang: 'js', | ||
}, | ||
], | ||
}; | ||
return [ | ||
...stepsWithPlatform[platform], | ||
{ | ||
title: ( | ||
<span> | ||
{t('inject.end')}{' '} | ||
<Trans i18nKey="inject.start-debug"> | ||
Start debugging by clicking the | ||
<Link to="/room-list" onClickCapture={onCloseModal}> | ||
Connections | ||
</Link>{' '} | ||
menu at the top! | ||
</Trans> | ||
</span> | ||
), | ||
code: '', | ||
}, | ||
] as { title: ReactNode; code: string; lang?: Lang }[]; | ||
}, [onCloseModal, platform, t]); | ||
|
||
return ( | ||
<div className="platform-integratio"> | ||
{steps.map(({ title, code, lang = 'html' }, index) => { | ||
return ( | ||
<div className="inject-steps" key={index}> | ||
<p className="inject-steps__title"> | ||
{index + 1}. {title} | ||
</p> | ||
<CodeBlock code={code} lang={lang} /> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.