Skip to content

Commit

Permalink
feat: load style from cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
VojtechVidra committed Jan 21, 2024
1 parent ebbf0d0 commit c51a51d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/vanilla-js/cloud/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
window.FlowsJS?.init({
projectId: "rbnd-test",
projectId: "993b3bc3-ebce-4a3e-ba8e-44ca62e3fc9e",
customApiUrl: "http://localhost:3005",
userId: "rbnd-test-user",
flows: [
Expand Down
3 changes: 3 additions & 0 deletions src/cloud/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { hash } from "../utils";
import { log } from "../log";
import { validateFlowsOptions, validateCloudFlowsOptions } from "../validation";
import { api } from "./api";
import { loadStyle } from "./style";

export * from "../index";

Expand All @@ -23,6 +24,8 @@ export const init = async (options: FlowsCloudOptions): Promise<void> => {

const apiUrl = options.customApiUrl ?? "https://api.flows-cloud.com";

loadStyle({ apiUrl, projectId: options.projectId });

const flows = await api(apiUrl)
.getFlows({
projectId: options.projectId,
Expand Down
9 changes: 9 additions & 0 deletions src/cloud/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const loadStyle = ({ apiUrl, projectId }: { apiUrl: string; projectId: string }): void => {
const styleEl =
(document.querySelector("#flows-cloud-styles") as HTMLLinkElement | undefined) ??
document.createElement("link");
styleEl.id = "flows-cloud-styles";
styleEl.rel = "stylesheet";
styleEl.href = `${apiUrl}/sdk/css?projectId=${projectId}`;
document.head.appendChild(styleEl);
};

0 comments on commit c51a51d

Please sign in to comment.