-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skrev om chatbot til å være klientsiderendret for at den skal kulle reagere på endringer av params.
- Loading branch information
Showing
18 changed files
with
469 additions
and
260 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
// @NOTE: can maybe use HTML rewriter here to append scripts based on cookies? | ||
export const loadedScripts = new Set<string>(); | ||
export const loadedScripts = new Map<string, Promise<void>>(); | ||
|
||
export const loadExternalScript = (uri: string, async = true) => { | ||
return new Promise<void>((resolve) => { | ||
if (loadedScripts.has(uri)) { | ||
return resolve(); | ||
} | ||
|
||
loadedScripts.add(uri); | ||
const script = document.createElement("script"); | ||
if (async) { | ||
script.async = true; | ||
} | ||
script.src = uri; | ||
export const loadExternalScript = ( | ||
uri: string, | ||
async = true, | ||
): Promise<void> => { | ||
const existing = loadedScripts.get(uri); | ||
if (existing) { | ||
return existing; | ||
} | ||
const script = document.createElement("script"); | ||
if (async) { | ||
script.async = true; | ||
} | ||
script.src = uri; | ||
const promise = new Promise<void>((resolve) => { | ||
script.onload = () => { | ||
resolve(); | ||
}; | ||
document.body.appendChild(script); | ||
}); | ||
loadedScripts.set(uri, promise); | ||
document.body.appendChild(script); | ||
return promise; | ||
}; |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { Meta, StoryObj } from "@storybook/html"; | ||
import "./chatbot"; | ||
|
||
const meta: Meta = { | ||
title: "chatbot", | ||
tags: ["autodocs"], | ||
render: () => { | ||
const wrapper = document.createElement("div"); | ||
wrapper.innerHTML = "<d-chatbot></d-chatbot>"; | ||
|
||
window.__DECORATOR_DATA__ = { | ||
params: { chatbot: true, chatbotVisible: true }, | ||
features: { ["dekoratoren.chatbotscript"]: true }, | ||
env: { ENV: "production" }, | ||
} as any; | ||
|
||
return wrapper; | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj; | ||
|
||
export const Default: Story = {}; |
Oops, something went wrong.