-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
93 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" }), | ||
|
@@ -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") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.