Skip to content

Commit

Permalink
Refactor Play component to append file content
Browse files Browse the repository at this point in the history
based on language
  • Loading branch information
1aron committed Dec 19, 2023
1 parent 614a6c8 commit 2086409
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions website/app/[locale]/play/Play.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,26 +162,28 @@ export default function Play(props: any) {
let bodyInnerHTML = ''

const appendFile = (eachFile: PlayShareFile) => {
if (!eachFile) {
eachFile = template?.files.find(({ title }: any) => title === eachFile.title) as PlayShareFile
}
const content = eachFile.content
if (!content) {
return
}
const eachTemplateFile: any = template?.files.find(({ title }: any) => title === eachFile.title)
switch (eachTemplateFile?.language) {
switch (eachFile.language) {
case 'html':
bodyInnerHTML += content
return
case 'javascript':
// eslint-disable-next-line no-case-declarations
let eachScriptHTML = getScriptHTML({ ...eachTemplateFile, text: content })
let eachScriptHTML = getScriptHTML({ ...eachFile, text: content })
if (eachFile.name === 'master.css.js') {
eachScriptHTML = eachScriptHTML
.replace(/(export default|export const config =)/, 'window.masterCSSConfig =')
}
headInnerHTML += eachScriptHTML
break
case 'css':
headInnerHTML += getStyleHTML({ ...eachTemplateFile, text: content })
headInnerHTML += getStyleHTML({ ...eachFile, text: content })
break
}
}
Expand Down Expand Up @@ -218,7 +220,7 @@ export default function Play(props: any) {
</head>
<body>${bodyInnerHTML}</body>
</html>`
}, [shareItem?.dependencies?.scripts, shareItem?.dependencies?.styles, shareItem.files, shareItem?.links, template?.files])
}, [shareItem, template?.files])

const tabFile: { id: string, language: string, content: string, readOnly: boolean, name: string, title: string } = useMemo(() => {
switch (tab) {
Expand Down

0 comments on commit 2086409

Please sign in to comment.