Skip to content

Commit

Permalink
feat: Add other streaming services
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlauer-Hax committed Sep 26, 2024
1 parent 85b33f2 commit b42c371
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
46 changes: 39 additions & 7 deletions pages/music/edit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { API, createActionList, createBreadcrumb, createTagList, LoadingSpinner, Navigation, stupidErrorAlert } from "shared/mod.ts";
import { asRef, Body, Empty, Grid, isMobile, Label, Vertical, WebGen } from "webgen/mod.ts";
import { asRef, Body, Button, Color, Empty, Grid, Image, ImageComponent, isMobile, Label, SheetDialog, Vertical, WebGen } from "webgen/mod.ts";
import "../../assets/css/main.css";
import "../../assets/css/music.css";
import { DynaNavigation } from "../../components/nav.ts";
Expand All @@ -9,6 +9,13 @@ import { ChangeDrop } from "./views/changeDrop.ts";
import { ChangeSongs } from "./views/changeSongs.ts";
import { DropTypeToText } from "./views/list.ts";

// @deno-types="https://raw.githubusercontent.com/lucsoft-DevTeam/lucsoft.de/master/custom.d.ts"
import spotify from "../music-landing/assets/spotify.svg";
// @deno-types="https://raw.githubusercontent.com/lucsoft-DevTeam/lucsoft.de/master/custom.d.ts"
import deezer from "../music-landing/assets/deezer.svg";
// @deno-types="https://raw.githubusercontent.com/lucsoft-DevTeam/lucsoft.de/master/custom.d.ts"
import tidal from "../music-landing/assets/tidal.svg";

await RegisterAuthRefresh();

WebGen({
Expand Down Expand Up @@ -94,12 +101,11 @@ sheetStack.setDefault(Vertical(
: Empty(),
drop.type === "PUBLISHED"
? {
id: "spotify",
title: "Spotify",
subtitle: "Open your Drop on Spotify",
clickHandler: async () => {
const url = await API.music.id(drop._id).spotify().then(stupidErrorAlert);
globalThis.open(url.spotify, "_blank");
id: "streamingservices",
title: "Open",
subtitle: "Navigate to your Drop on Streaming Services",
clickHandler: () => {
StreamingServiesDialog.open();
},
}
: Empty(),
Expand Down Expand Up @@ -143,3 +149,29 @@ renewAccessTokenIfNeeded().then(async () => {
.then(stupidErrorAlert)
.then((x) => drop.setValue(x));
});

const streamingImages: Record<string, ImageComponent> = {
spotify: Image(spotify, "Spotify"),
deezer: Image(deezer, "Deezer"),
tidal: Image(tidal, "Tidal"),
};

const StreamingServiesDialog = SheetDialog(
sheetStack,
"Streaming Services",
await API.music.id(data.id).services().then(stupidErrorAlert).then((x) =>
Vertical(
...Object.entries(x).map(([key, value]) =>
Button("Open in " + key[0].toUpperCase() + key.slice(1))
.onClick(() => globalThis.open(value, "_blank"))
.addPrefix(
streamingImages[key]
.setHeight("1.5rem")
.setWidth("1.5rem")
.setMargin("0 0.35rem 0 -0.3rem"),
)
),
Object.values(x).every((x) => !x) ? Label("No Links available :(").setTextSize("2xl") : Empty(),
).setGap("0.5rem")
),
);
4 changes: 2 additions & 2 deletions pages/shared/restSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,8 @@ export const API = {
})
.then(blob())
.catch(reject),
spotify: () =>
fetch(`${API.BASE_URL}music/${id}/spotify`, {
services: () =>
fetch(`${API.BASE_URL}music/${id}/services`, {
headers: headers(API.getToken()),
})
.then(json<{ spotify: string }>())
Expand Down

0 comments on commit b42c371

Please sign in to comment.