A music player that connects to your cloud/distributed storage.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: refiner should restore ephemeral items

+61 -6
+61 -6
src/components/transformer/output/refiner/default/element.js
··· 1 - import { computed } from "~/common/signal.js"; 1 + import * as IDB from "idb-keyval"; 2 + 3 + import { computed, signal } from "~/common/signal.js"; 2 4 import { OutputTransformer } from "../../base.js"; 5 + 6 + const IDB_KEY_PLAYLISTS = 7 + "diffuse/transformer/output/refiner/default/playlistItems/ephemeral"; 8 + const IDB_KEY_TRACKS = 9 + "diffuse/transformer/output/refiner/default/tracks/ephemeral"; 3 10 4 11 /** 5 - * @import { OutputManagerDeputy } from "../../../../output/types.d.ts" 12 + * @import { OutputManagerDeputy } from "~/components/output/types.d.ts" 13 + * @import { PlaylistItem, Track } from "~/definitions/types.d.ts" 6 14 */ 7 15 8 16 /** ··· 14 22 15 23 const base = this.base(); 16 24 25 + // Ephemeral signals 26 + const ephemeralPlaylistItems = signal(/** @type {any[]} */ ([])); 27 + const ephemeralTracks = signal(/** @type {any[]} */ ([])); 28 + 29 + // Restore stored ephemeral items 30 + IDB.get(IDB_KEY_PLAYLISTS).then((items) => { 31 + if (items) ephemeralPlaylistItems.set(items); 32 + }); 33 + 34 + IDB.get(IDB_KEY_TRACKS).then((items) => { 35 + if (items) ephemeralTracks.set(items); 36 + }); 37 + 17 38 /** @type {OutputManagerDeputy} */ 18 39 const manager = { 19 40 facets: { ··· 25 46 playlistItems: { 26 47 ...base.playlistItems, 27 48 collection: computed(() => { 28 - return base.playlistItems.collection() ?? []; 49 + return [ 50 + ...(base.playlistItems.collection() ?? []), 51 + ...ephemeralPlaylistItems.get(), 52 + ]; 29 53 }), 30 54 save: async (newPlaylists) => { 31 - const filtered = newPlaylists.filter((p) => !p.ephemeral); 55 + /** @type {PlaylistItem[]} */ 56 + const ephemeral = []; 57 + 58 + const filtered = newPlaylists.filter((p) => { 59 + if (p.ephemeral) { 60 + ephemeral.push(p); 61 + return false; 62 + } else { 63 + return true; 64 + } 65 + }); 66 + 67 + await IDB.set(IDB_KEY_PLAYLISTS, ephemeral); 68 + ephemeralPlaylistItems.set(ephemeral); 69 + 32 70 await base.playlistItems.save(filtered); 33 71 }, 34 72 }, ··· 41 79 tracks: { 42 80 ...base.tracks, 43 81 collection: computed(() => { 44 - return base.tracks.collection() ?? []; 82 + return [ 83 + ...(base.tracks.collection() ?? []), 84 + ...ephemeralTracks.get(), 85 + ]; 45 86 }), 46 87 save: async (newTracks) => { 47 - const filtered = newTracks.filter((t) => !t.ephemeral); 88 + /** @type {Track[]} */ 89 + const ephemeral = []; 90 + 91 + const filtered = newTracks.filter((t) => { 92 + if (t.ephemeral) { 93 + ephemeral.push(t); 94 + return false; 95 + } else { 96 + return true; 97 + } 98 + }); 99 + 100 + await IDB.set(IDB_KEY_TRACKS, ephemeral); 101 + ephemeralTracks.set(ephemeral); 102 + 48 103 await base.tracks.save(filtered); 49 104 }, 50 105 },