Skip to content

Commit

Permalink
ci fix
Browse files Browse the repository at this point in the history
  • Loading branch information
greg6775 committed Jan 20, 2024
1 parent 1cdeef8 commit 0cc3a64
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 142 deletions.
31 changes: 3 additions & 28 deletions assets/css/wizard.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,6 @@ nav.music {
height: 100%;
}

.inverted-class .wgtable {
width: calc(100vw - 32px);
max-width: 50rem;
max-height: 25rem;
overflow: auto;
height: 100vh;
box-sizing: border-box;
gap: 8px;
background: white;
color: black;
padding: 0 16px;
border-radius: 8px;
--color-grayscaled-lightness: 0%;
--color-grayscaled-font: white;
}

.inverted-class :not(.artists-list)>.grayscaled.wiconbutton {
color: hsl(var(--background-color-h), var(--background-color-s), var(--background-color-l));
background: transparent;
}

.wbutton.disabled {
z-index: 0;
}
Expand Down Expand Up @@ -128,11 +107,7 @@ span.title {
}
}

.artist-table .wgtable {
gap: 12px;
margin: 12px 0;
}

.artist-table .wgtable .column {
gap: 12px;
.inverted-class .wgtable {
width: calc(100vw - 32px);
max-width: 50rem;
}
12 changes: 5 additions & 7 deletions pages/_legacy/music/changeDrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import * as zod from "https://deno.land/x/[email protected]/mod.ts";
import { ZodError } from "https://deno.land/x/[email protected]/mod.ts";
import { API } from "shared/mod.ts";
import { stupidErrorAlert } from "shared/restSpec.ts";
import { AdvancedImage, Box, Button, CenterV, DropAreaInput, DropDownInput, Empty, Grid, Horizontal, IconButton, Image, Label, MIcon, Spacer, StateHandler, TextInput, Validate, asState, createFilePicker, getErrorMessage } from "webgen/mod.ts";
import { AdvancedImage, Box, Button, CenterV, DropAreaInput, DropDownInput, Empty, Grid, Horizontal, IconButton, Image, Label, MIcon, Spacer, TextInput, Validate, asState, createFilePicker, getErrorMessage } from "webgen/mod.ts";
import artwork from "../../../assets/img/template-artwork.png";
import genres from "../../../data/genres.json" with { type: "json" };
import language from "../../../data/language.json" with { type: "json" };
import { Artist, DATE_PATTERN, artist, song, userString } from "../../../spec/music.ts";
import { DATE_PATTERN, Drop, artist, song, userString } from "../../../spec/music.ts";
import { EditArtistsDialog, allowedImageFormats, getSecondary } from "../helper.ts";
import { uploadArtwork } from "./data.ts";

export function ChangeDrop(drop: StateHandler<{ _id: string | undefined, title: string | undefined, release: string | undefined, language: string | undefined, artists: Artist[], artwork: string | undefined, compositionCopyright: string | undefined, soundRecordingCopyright: string | undefined, primaryGenre: string | undefined, secondaryGenre: string | undefined; }>) {
export function ChangeDrop(drop: Drop) {
const state = asState({
artworkClientData: <AdvancedImage | string | undefined>(drop.artwork ? <AdvancedImage>{ type: "direct", source: () => API.music.id(drop._id!).artwork().then(stupidErrorAlert) } : undefined),
loading: false,
validationState: <ZodError | undefined>undefined
});

const { data, error, validate } = Validate(
drop,
asState(drop),
zod.object({
title: userString,
artists: artist.array().refine(x => x.some(([ , , type ]) => type == "PRIMARY"), { message: "At least one primary artist is required" }),
Expand Down Expand Up @@ -91,9 +91,7 @@ export function ChangeDrop(drop: StateHandler<{ _id: string | undefined, title:
Grid(
DropDownInput("Primary Genre", Object.keys(genres))
.sync(data, "primaryGenre")
.onChange(() => {
data.secondaryGenre = undefined!;
}),
.onChange(() => data.secondaryGenre = undefined!),
data.$primaryGenre.map(primaryGenre => DropDownInput("Secondary Genre", getSecondary(genres, primaryGenre) ?? [])
.sync(data, "secondaryGenre")
.addClass("border-box")
Expand Down
68 changes: 25 additions & 43 deletions pages/_legacy/music/changeSongs.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,47 @@
import * as zod from "https://deno.land/x/[email protected]/mod.ts";
import { API } from "shared/mod.ts";
import { Box, Button, CenterV, Empty, Grid, Horizontal, Label, Spacer, StateHandler, Validate, asState, createFilePicker, getErrorMessage } from "webgen/mod.ts";
import { Artist, DATE_PATTERN, Song, artist, song, userString } from "../../../spec/music.ts";
import { Box, Button, CenterV, Empty, Grid, Horizontal, Label, Spacer, Validate, asState, createFilePicker, getErrorMessage } from "webgen/mod.ts";
import { Drop, song } from "../../../spec/music.ts";
import { allowedAudioFormats } from "../helper.ts";
import { uploadSongToDrop } from "./data.ts";
import { ManageSongs } from "./table.ts";

export function ChangeSongs(drop: StateHandler<{ _id: string, songs: Song[], title: string | undefined, release: string | undefined, language: string | undefined, artists: Artist[], primaryGenre: string | undefined, secondaryGenre: string | undefined, }>) {
export function ChangeSongs(drop: Drop) {
const state = asState({
uploadingSongs: <string[]>[],
validationState: <zod.ZodError | undefined>undefined
});

const { data, error, validate } = Validate(
drop,
asState(drop),
zod.object({
title: userString,
artists: artist.array().refine(x => x.some(([ , , type ]) => type == "PRIMARY"), { message: "At least one primary artist is required" }),
release: zod.string().regex(DATE_PATTERN, { message: "Not a date" }),
language: zod.string(),
primaryGenre: zod.string(),
secondaryGenre: zod.string(),
compositionCopyright: userString,
soundRecordingCopyright: userString,
artwork: zod.string(),
songs: song.array().min(1, { message: "At least one song is required" }),
})
);

return Grid(
[
{ width: 2 },
Horizontal(
Box(state.$validationState.map(error => error ? CenterV(
Label(getErrorMessage(error))
.addClass("error-message")
.setMargin("0 0.5rem 0 0")
)
: Empty()).asRefComponent()),
Spacer(),
Button("Save")
.onClick(async () => {
const validation = validate();
if (error.getValue()) return state.validationState = error.getValue();
if (validation) await API.music.id(data._id!).update(validation);
location.reload(); // Handle this Smarter => Make it a Reload Event.
})
),
],
[
{ width: 2 },
ManageSongs(data),
],
[
{ width: 2 },
Horizontal(
Spacer(),
Button("Add a new Song")
.onClick(() => createFilePicker(allowedAudioFormats.join(",")).then(file => uploadSongToDrop(data, state.$uploadingSongs, file)))
Horizontal(
Box(state.$validationState.map(error => error ? CenterV(
Label(getErrorMessage(error))
.addClass("error-message")
.setMargin("0 0.5rem 0 0")
)
],
: Empty()).asRefComponent()),
Spacer(),
Button("Save")
.onClick(async () => {
const validation = validate();
if (error.getValue()) return state.validationState = error.getValue();
if (validation) await API.music.id(data._id!).update(validation);
location.reload(); // Handle this Smarter => Make it a Reload Event.
})
),
ManageSongs(data),
Horizontal(
Spacer(),
Button("Add a new Song")
.onClick(() => createFilePicker(allowedAudioFormats.join(",")).then(file => uploadSongToDrop(data, state.$uploadingSongs, file)))
)
)
.setGap("15px")
.setPadding("15px 0 0 0");
Expand Down
3 changes: 2 additions & 1 deletion pages/_legacy/music/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export function uploadSongToDrop(state: StateHandler<{ songs: Song[]; artists: A
}, file);
}

export function uploadArtwork(id: string, file: File, artworkClientData: Reference<AdvancedImage | string | undefined>, loading: Reference<boolean>, artwork: Reference<string | undefined>) {
//is there a better way for those typings??
export function uploadArtwork(id: string, file: File, artworkClientData: Reference<AdvancedImage | string | undefined>, loading: Reference<boolean>, artwork: Reference<string> | Reference<string | undefined>) {
const blobUrl = URL.createObjectURL(file);
artworkClientData.setValue({ type: "uploading", filename: file.name, blobUrl, percentage: 0 });
loading.setValue(true);
Expand Down
63 changes: 19 additions & 44 deletions pages/_legacy/music/edit.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { API, LoadingSpinner, Navigation, createActionList, createBreadcrumb, createTagList, stupidErrorAlert } from "shared/mod.ts";
import { Body, Empty, Grid, Horizontal, Label, Spacer, Vertical, WebGen, asState, isMobile, ref } from "webgen/mod.ts";
import { Body, Empty, Grid, Horizontal, Label, Spacer, Vertical, WebGen, asState, isMobile } from "webgen/mod.ts";
import '../../../assets/css/main.css';
import '../../../assets/css/music.css';
import { DynaNavigation } from "../../../components/nav.ts";
import { Artist, Drop, DropType, Song } from "../../../spec/music.ts";
import { Drop, DropType } from "../../../spec/music.ts";
import '../../hosting/views/table2.css';
import { DropTypeToText } from "../../music/views/list.ts";
import { RegisterAuthRefresh, changeThemeColor, permCheck, renewAccessTokenIfNeeded, saveBlob, sheetStack, showPreviewImage } from "../helper.ts";
Expand All @@ -26,83 +26,71 @@ if (!data.id) {
}

const state = asState({
loaded: false,
_id: data.id,
title: <string | undefined>undefined,
type: <DropType | undefined>undefined,
release: <string | undefined>undefined,
language: <string | undefined>undefined,
artists: <Artist[]>[],
primaryGenre: <string | undefined>undefined,
secondaryGenre: <string | undefined>undefined,
compositionCopyright: <string | undefined>undefined,
soundRecordingCopyright: <string | undefined>undefined,
artwork: <string | undefined>undefined,
songs: <Song[]>[],
drop: <Drop | undefined>undefined,
});

sheetStack.setDefault(Vertical(
DynaNavigation("Music"),
state.$loaded.map(loaded => loaded ? Navigation({
title: ref`${state.$title}`,
state.$drop.map(drop => drop ? Navigation({
title: drop.title,
children: [
Horizontal(
//TODO: Make this look better
Label(DropTypeToText(state.type!)).setTextSize("2xl"),
Label(DropTypeToText(drop.type)).setTextSize("2xl"),
Spacer()
),
{
id: "edit-drop",
title: "Drop",
subtitle: "Change Title, Release Date, ...",
children: [
ChangeDrop(state)
ChangeDrop(drop)
]
},
{
id: "edit-songs",
title: "Songs",
subtitle: "Move Songs, Remove Songs, Add Songs, ...",
children: [
ChangeSongs(state),
ChangeSongs(drop),
]
},
{
id: "export",
title: "Export",
subtitle: "Download your complete Drop with every Song",
clickHandler: async () => {
const blob = await API.music.id(state._id).download().then(stupidErrorAlert);
saveBlob(blob, `${state.title}.tar`);
const blob = await API.music.id(drop._id).download().then(stupidErrorAlert);
saveBlob(blob, `${drop.title}.tar`);
}
},
Permissions.canCancelReview(state.type!) ?
Permissions.canCancelReview(drop.type) ?
{
id: "cancel-review",
title: "Cancel Review",
subtitle: "Need to change Something? Cancel it now",
clickHandler: async () => {
await API.music.id(state._id).type.post(DropType.Private);
await API.music.id(drop._id).type.post(DropType.Private);
location.reload();
},
} : Empty(),
Permissions.canSubmit(state.type!) ?
Permissions.canSubmit(drop.type) ?
{
id: "publish",
title: "Publish",
subtitle: "Submit your Drop for Approval",
clickHandler: async () => {
await API.music.id(state._id).type.post(DropType.UnderReview);
await API.music.id(drop._id).type.post(DropType.UnderReview);
location.reload();
},
} : Empty(),
Permissions.canTakedown(state.type!) ?
Permissions.canTakedown(drop.type) ?
{
id: "takedown",
title: "Takedown",
subtitle: "Completely Takedown your Drop",
clickHandler: async () => {
await API.music.id(state._id).type.post(DropType.Private);
await API.music.id(drop._id).type.post(DropType.Private);
location.reload();
},
} : Empty()
Expand All @@ -116,7 +104,7 @@ sheetStack.setDefault(Vertical(
const list = Vertical(
menu.path.map(x => x == "-/" ?
Grid(
showPreviewImage(<Drop>{ _id: state._id, artwork: state.artwork }).addClass("image-preview")
showPreviewImage(<Drop>{ _id: drop._id, artwork: drop.artwork }).addClass("image-preview")
).setEvenColumns(1, "10rem")
: Empty()
).asRefComponent(),
Expand All @@ -137,26 +125,13 @@ Body(sheetStack);

const Permissions = {
canTakedown: (type: DropType) => type == "PUBLISHED",
canSubmit: (type: DropType) => (<Drop[ "type" ][]>[ "UNSUBMITTED", "PRIVATE" ]).includes(type),
canSubmit: (type: DropType) => (<DropType[]>[ "UNSUBMITTED", "PRIVATE" ]).includes(type),
canEdit: (type: DropType) => (type == "PRIVATE" || type == "UNSUBMITTED") || permCheck("/bbn/manage/drops"),
canCancelReview: (type: DropType) => type == "UNDER_REVIEW"
};

renewAccessTokenIfNeeded().then(async () => {
await API.music.id(data.id).get()
.then(stupidErrorAlert)
.then(drop => {
state.type = drop.type;
state.title = drop.title;
state.release = drop.release;
state.language = drop.language;
state.artists = asState(drop.artists ?? []);
state.primaryGenre = drop.primaryGenre;
state.secondaryGenre = drop.secondaryGenre;
state.compositionCopyright = drop.compositionCopyright;
state.soundRecordingCopyright = drop.soundRecordingCopyright;
state.artwork = drop.artwork;
state.songs = asState(drop.songs ?? []);
})
.then(() => state.loaded = true);
.then(drop => state.drop = drop);
});
27 changes: 27 additions & 0 deletions pages/_legacy/music/table.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.inverted-class .wgtable {
max-height: 25rem;
overflow: auto;
height: 100vh;
box-sizing: border-box;
gap: 8px;
background: white;
color: black;
padding: 0 16px;
border-radius: 8px;
--color-grayscaled-lightness: 0%;
--color-grayscaled-font: white;
}

.inverted-class :not(.artists-list)>.grayscaled.wiconbutton {
color: hsl(var(--background-color-h), var(--background-color-s), var(--background-color-l));
background: transparent;
}

.artist-table .wgtable {
gap: 12px;
margin: 12px 0;
}

.artist-table .wgtable .column {
gap: 12px;
}
1 change: 1 addition & 0 deletions pages/_legacy/music/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import language from "../../../data/language.json" with { type: "json" };
import { Artist, Song } from "../../../spec/music.ts";
import { Table2 } from "../../hosting/views/table2.ts";
import { EditArtistsDialog, ProfilePicture, getSecondary, getYearList } from "../helper.ts";
import "./table.css";

export function ManageSongs(state: StateHandler<{ songs: Song[]; primaryGenre: string | undefined; }>) {
return new Table2(state.$songs)
Expand Down
2 changes: 1 addition & 1 deletion pages/_legacy/newDrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ API.music.id(dropId).get().then(stupidErrorAlert)
const state = asState({
loaded: false,
_id: dropId,
upc: <string | undefined>undefined,
upc: <string | undefined | null>undefined,
title: <string | undefined>undefined,
release: <string | undefined>undefined,
language: <string | undefined>undefined,
Expand Down
Loading

0 comments on commit 0cc3a64

Please sign in to comment.