Skip to content

Commit

Permalink
fix: loading issue
Browse files Browse the repository at this point in the history
  • Loading branch information
DanWebb committed Jan 26, 2024
1 parent a183870 commit 9fc6dca
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@etchteam/storybook-addon-marker",
"version": "3.0.0",
"version": "3.0.1",
"description": "Add a Marker.io feedback button to the storybook UI",
"main": "dist/manager.js",
"files": [
Expand Down
1 change: 0 additions & 1 deletion preview.js

This file was deleted.

20 changes: 8 additions & 12 deletions src/FeedbackButton.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import markerSDK from '@marker.io/browser';
import { Button } from '@storybook/components';
import { useGlobals, useParameter } from '@storybook/manager-api';
import React, { useCallback, useEffect } from 'react';
import { useParameter } from '@storybook/manager-api';
import React, { useCallback, useEffect, useState } from 'react';

import { WIDGET_KEY, TOOL_ID } from './constants';
import { TOOL_ID } from './constants';

const hideDefaultMarkerButton = () => {
const markerBtns = [
Expand All @@ -13,12 +13,11 @@ const hideDefaultMarkerButton = () => {
};

export default function FeedbackButton() {
const [globals, updateGlobals] = useGlobals();
const [markerLoaded, setMarkerLoaded] = useState();
const { destination, mode, ...config } = useParameter('marker', {});
const isActive = globals[WIDGET_KEY];

useEffect(() => {
if (!destination || isActive) {
if (!destination || markerLoaded || window.Marker) {
return;
}

Expand All @@ -29,25 +28,22 @@ export default function FeedbackButton() {
})
.then(() => {
hideDefaultMarkerButton();
updateGlobals({
[WIDGET_KEY]: true,
});
setMarkerLoaded(true);
});
}, [destination]);

const handleSendFeedback = useCallback(() => {
window.Marker?.capture(mode);
}, [mode, globals[WIDGET_KEY]]);
}, [mode]);

return isActive ? (
return markerLoaded ? (
<Button
style={{
height: '28px',
marginBlockStart: '6px',
marginInlineStart: '4px',
}}
key={TOOL_ID}
active={isActive}
onClick={handleSendFeedback}
outline
small
Expand Down
1 change: 0 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export const ADDON_ID = 'marker';
export const TOOL_ID = `${ADDON_ID}/tool`;
export const WIDGET_KEY = 'markerFeedbackWidgetActive';
9 changes: 0 additions & 9 deletions src/preview.js

This file was deleted.

0 comments on commit 9fc6dca

Please sign in to comment.