full release edit capabilities oh my goodness gracious

Signed-off-by: ari melody <ari@arimelody.me>
This commit is contained in:
ari melody 2024-08-31 01:30:30 +01:00
parent 34cddcfdb2
commit 604e2a4a7c
25 changed files with 1043 additions and 202 deletions

View file

@ -1,7 +1,9 @@
import Stateful from "/script/silver.min.js"
const releaseID = document.getElementById("release").dataset.id;
const artwork_input = document.getElementById("artwork");
const title_input = document.getElementById("title");
const artwork_img = document.getElementById("artwork");
const artwork_input = document.getElementById("artwork-file");
const type_input = document.getElementById("type");
const desc_input = document.getElementById("description");
const date_input = document.getElementById("release-date");
@ -10,20 +12,22 @@ const buylink_input = document.getElementById("buylink");
const vis_input = document.getElementById("visibility");
const save_btn = document.getElementById("save");
let token = atob(localStorage.getItem("arime-token"));
var artwork_data = artwork_img.attributes.src.value;
let edited = new Stateful(false);
var token = atob(localStorage.getItem("arime-token"));
let release_data = update_data(undefined);
var edited = new Stateful(false);
var release_data = update_data(undefined);
function update_data(old) {
let release_data = {
var release_data = {
visible: vis_input.value === "true",
title: undefined,
title: title_input.value,
description: desc_input.value,
type: type_input.value,
releaseDate: date_input.value,
artwork: artwork_input.attributes.src.value,
artwork: artwork_data,
buyname: buyname_input.value,
buylink: buylink_input.value,
};
@ -38,8 +42,6 @@ function update_data(old) {
function save_release() {
console.table(release_data);
edited.set(false);
(async () => {
const res = await fetch(
"/api/v1/music/" + releaseID, {
@ -61,15 +63,29 @@ function save_release() {
location = location;
})();
}
window.save_release = save_release;
edited.onUpdate(edited => {
save_btn.disabled = !edited;
})
artwork_input.addEventListener("click", () => {
title_input.addEventListener("change", () => {
release_data = update_data(release_data);
});
artwork_img.addEventListener("click", () => {
artwork_input.addEventListener("change", () => {
if (artwork_input.files.length > 0) {
const reader = new FileReader();
reader.onload = e => {
const data = e.target.result;
artwork_img.src = data;
artwork_data = data;
release_data = update_data(release_data);
};
reader.readAsDataURL(artwork_input.files[0]);
}
});
artwork_input.click();
});
type_input.addEventListener("change", () => {
release_data = update_data(release_data);
});