Skip to content

Commit

Permalink
Added feed selection #654
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Jan 22, 2024
1 parent db3a7d1 commit 45c1c0a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
20 changes: 17 additions & 3 deletions src/utilities/piral-debug-utils/src/emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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';
Expand Down

0 comments on commit 45c1c0a

Please sign in to comment.