From 45c1c0acbdc49c3e271bb62af9d7ea1c022319b2 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Mon, 22 Jan 2024 18:01:26 +0100 Subject: [PATCH] Added feed selection #654 --- CHANGELOG.md | 1 + .../piral-debug-utils/src/emulator.ts | 20 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d49fcbedf..adda02c1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Fixed issue with monorepos using Rush (#667) - Improved internal navigation Blazor pilets using `piral-blazor` +- Added feed selection view for remote emulator website (#654) ## 1.4.3 (December 26, 2023) diff --git a/src/utilities/piral-debug-utils/src/emulator.ts b/src/utilities/piral-debug-utils/src/emulator.ts index 0aa477b1e..cb41aa47e 100644 --- a/src/utilities/piral-debug-utils/src/emulator.ts +++ b/src/utilities/piral-debug-utils/src/emulator.ts @@ -3,17 +3,23 @@ import type { PiletRequester } from 'piral-base'; import type { EmulatorConnectorOptions } from './types'; export function installPiletEmulator(requestPilets: PiletRequester, options: EmulatorConnectorOptions) { - const { addPilet, removePilet, integrate, piletApiFallback = '/$pilet-api' } = options; + const { + addPilet, + removePilet, + integrate, + piletApiFallback = 'https://feed.piral.cloud/api/v1/pilet/emulator-website', + } = options; integrate(() => { // check if pilets should be loaded + const dbgPiletApiKey = 'dbg:pilet-api'; const loadPilets = sessionStorage.getItem('dbg:load-pilets') === 'on'; const noPilets: PiletRequester = () => Promise.resolve([]); const requester = loadPilets ? requestPilets : noPilets; const promise = requester(); // the window['dbg:pilet-api'] should point to an API address used as a proxy, fall back to '/$pilet-api' if unavailable - const piletApi = window['dbg:pilet-api'] || piletApiFallback; + const piletApi = window[dbgPiletApiKey] || sessionStorage.getItem(dbgPiletApiKey) || piletApiFallback; // either take a full URI or make it an absolute path relative to the current origin const initialTarget = /^https?:/.test(piletApi) @@ -26,7 +32,15 @@ export function installPiletEmulator(requestPilets: PiletRequester, options: Emu const appendix = fetch(initialTarget) .then((res) => res.json()) - .then((item) => (Array.isArray(item) ? item : [item])); + .then((item) => + Array.isArray(item) + ? item + : item && typeof item === 'object' + ? Array.isArray(item.items) + ? item.items + : [item] + : [], + ); ws.onmessage = ({ data }) => { const hardRefresh = sessionStorage.getItem('dbg:hard-refresh') === 'on';