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.

at v4 50 lines 1.2 kB view raw
1import * as Output from "~/common/output.js"; 2import { output } from "./output.js"; 3 4/** 5 * @import {Facet} from "~/definitions/types.d.ts" 6 */ 7 8/** 9 * @param {{ id: string }} _ 10 */ 11export function deleteFacet({ id }) { 12 return async () => { 13 const c = confirm("Are you sure you want to delete this facet?"); 14 if (!c) return; 15 16 const out = await output(); 17 const col = await Output.data(out.facets); 18 19 out.facets.save(col.filter((c) => !(c.id === id))); 20 }; 21} 22 23/** 24 * @param {{ id: string }} _ 25 */ 26export function toggleFacetEnabled({ id }) { 27 return async () => { 28 const out = await output(); 29 const col = await Output.data(out.facets); 30 const facet = col.find((c) => c.id === id); 31 if (!facet) return; 32 await out.facets.save([ 33 ...col.filter((c) => c.id !== id), 34 { ...facet, enabled: !(facet.enabled ?? true), updatedAt: new Date().toISOString() }, 35 ]); 36 }; 37} 38 39/** 40 * @param {Facet} facet 41 */ 42export async function saveFacet(facet) { 43 const out = await output(); 44 const col = await Output.data(out.facets); 45 const colWithoutId = col.filter((c) => c.id !== facet.id); 46 await out.facets.save([...colWithoutId, { 47 ...facet, 48 updatedAt: new Date().toISOString(), 49 }]); 50}