Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
Fix authentcate issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Datlyfe committed Mar 17, 2022
1 parent f0f6712 commit 80dbe0b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
17 changes: 16 additions & 1 deletion src/ExportButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
State,
} from "@storybook/api";
import {
authenticate,
createStoryRequest,
escapeHtml,
getStorybookToken,
Expand Down Expand Up @@ -79,6 +80,7 @@ const populateSeedObjectBasedOnArgType = (
const argOptions = getArgOptions(arg);
switch (argType) {
case "select":
case "radio":
seedObject[argKey] = choice(...argOptions);
break;
case "boolean":
Expand Down Expand Up @@ -122,7 +124,7 @@ const getVariants = (
const arg = argTypes[key];
const argType = getArgType(arg);

if (["select"].includes(argType)) {
if (["select", "radio"].includes(argType)) {
const options = getArgOptions(arg);
return options.length > 0 ? options[0] : null;
}
Expand Down Expand Up @@ -203,6 +205,9 @@ const createStory = async (
api.on(STORY_RENDERED, handleSBRender);

const [variants, defaultVariant, defaultVariantHash] = getVariants(story);

console.log(variants);

parent.postMessage(
{
action: EXPORT_START,
Expand Down Expand Up @@ -370,10 +375,20 @@ export const ExportButton: React.FC<SProps> = () => {
}) as any;

useEffect(() => {
let mounted = true;
if (!isAuthenticated) {
authenticate(getStorybookToken()).then((isAuthenticated) => {
if (mounted) {
setIsAuthenticated(isAuthenticated);
}
});
}

document.addEventListener(EXPORT_SINGLE_STORY, handleChangeStory);
document.addEventListener(EXPORT_ALL_STORIES, handleExportAllStories);

return () => {
mounted = false;
document.removeEventListener(EXPORT_SINGLE_STORY, handleChangeStory);
document.removeEventListener(EXPORT_ALL_STORIES, handleExportAllStories);
};
Expand Down
7 changes: 1 addition & 6 deletions src/register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import {
EXPORT_PROGRESS,
EXPORT_SINGLE_STORY,
EXPORT_START,
ON_AUTH,
} from "./constants";
import { ExportButton } from "./ExportButton";
import { authenticate, getStorybookToken, injectCustomStyles } from "./utils";
import { injectCustomStyles } from "./utils";
import { get } from "lodash";
import ReactDOM from "react-dom";
import Banner from "./components/banner";
Expand Down Expand Up @@ -83,10 +82,6 @@ addons.register(ADDON_ID, (api) => {
const ev = new CustomEvent(EXPORT_ALL_STORIES, { detail: { stories } });
frame.contentDocument.dispatchEvent(ev);
});

authenticate(getStorybookToken()).then((isAuthenticated) => {
channel.emit(ON_AUTH, isAuthenticated);
});
}

addons.add(ADDON_ID, {
Expand Down

0 comments on commit 80dbe0b

Please sign in to comment.