UNPKG

@redocly/theme

Version:

Shared UI components lib

65 lines 2.79 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.useConfigureReplay = useConfigureReplay; const react_1 = require("react"); function getReplayConfiguration(_context) { return __awaiter(this, void 0, void 0, function* () { // Customize this function to fetch replay configuration from your API endpoint // STEP 1: Uncomment the fetch code below and update the URL to your API endpoint // try { // const response = await fetch(`/api/replay-config/${_context.operation.operationId}`, { // method: 'GET', // headers: { // 'Content-Type': 'application/json', // }, // }); // if (!response.ok) { // throw new Error(`HTTP error! status: ${response.status}`); // } // const { token } = await response.json(); // return { // security: { // default: { // token: { // access_token: token, // } // } // } // }; // } catch (error) { // console.warn('Failed to fetch replay configuration:', error); // throw error; // } // STEP 2: Remove this return null statement once you've implemented the fetch above return null; }); } function useConfigureReplay(context, isOpened) { const [config, setConfig] = (0, react_1.useState)(); const refresh = (0, react_1.useCallback)(() => __awaiter(this, void 0, void 0, function* () { try { const result = yield getReplayConfiguration(context); setConfig(result); } catch (error) { console.warn('Failed to configure replay for operation:', context.operation.operationId, error); } // eslint-disable-next-line react-hooks/exhaustive-deps }), []); (0, react_1.useEffect)(() => { if (isOpened) { refresh(); } }, [isOpened, refresh]); return { config, refresh }; } //# sourceMappingURL=use-configure-replay.js.map