$(function() { // Make add music on page load
makeAddMusicMenus();
});
$('#submit-music').submit(async function(event) {
event.preventDefault();
// Get boost amount from selector
const boostAmount = $("#boost-blux option:selected").val();
let txid = "";
try {
// Only handle BLUX boost if amount is selected and greater than 0
if(boostAmount && parseInt(boostAmount) > 0) {
txid = await sendBluxBoostTransaction(boostAmount);
} else {
// Set txid to empty string or some indicator that no transaction was needed
txid = "";
}
// Proceed with original form submission logic
await handleAddMusicSubmission(txid);
} catch (error) {
$('#add-music-success').removeClass('alert-success').addClass('alert-danger')
.html(`Boost failed: ${error.message}`).fadeIn().delay(3000).fadeOut();
}
});
async function handleAddMusicSubmission(txid) { // Take submit form and make it yo bish.
// Call getGeopol first and await its result
try {
// GetGeopol Called
await getGeopol(
$("#submit-music-btn").attr("valueLng"),
$("#submit-music-btn").attr("valueLat")
);
} catch (error) {
console.error("Geolocation failed:", error);
valid = false;
errors.push("Could not determine location. Please try again.");
}
//--- We gon need some facts in this erria ---\\
let yt = $("#yt").val();
let sc = $("#sc").val();
let spot = $("#spot").val();
let atomict = $("#atomict").val();
var atomicc = "";// = $("#atomict").attr("collection");
let mood = $("#mood option:selected").val();
let genre = $("#genre option:selected").val();
let format = $("#format option:selected").val();
let songLat = $("#submit-music-btn").attr("valuelat");
let songLng = $("#submit-music-btn").attr("valuelng");
let songIso3 = $("#submit-music-btn").attr("songiso3");
let boost_blux_val = $("#boost-blux option:selected").val() || 0; // Default to 0 if undefined or null
var songstateid = $("#submit-music-btn").attr("songstateid");
var songcityascii = $("#submit-music-btn").attr("songcityascii");
// YouTube URL:, sc, spot, Atomic Token:, mood, Genre:, Format:, Latitude:, Longitude:, ISO3 Country Code:, Boost BLUX Value:, State ID:, City ASCII:,
errors = [];
spotSlug = "";
scSlug = "";
ytSlug = "";
ytChannel = "";
valid = true;
if (yt) {
await validateYouTubeUrl(yt);
}
if (sc) {
validateSoundcloudUrl(sc);
}
if (spot) {
validateSpotifyUrl(spot);
}
//--- Check if content is blank ---\\
if ((!spot && !sc && !yt)) {
errors.push("The Sound of Silence. Good choice.");
valid = false;
}
//--- Require YT Videos also have another Player ---\\
if ((!spot && !sc) && yt) {
errors.push("π₯ For YouTube, we require at least 1 other player of the same song/album. If you aren't yet distributing your music to all platforms you may use Soundcloud; playlists work.");
valid = false;
}
/*/--- Limit posting to 1 per minute ---\\
if(Cookies.get('lastPost') !== undefined) { /// CHECK THIS
valid = false;
errors.push("To combat spam, please wait 30 seconds between posts. β±οΈ");
}
/*/
//--- Make sure they marked Genre/Mood/Format ---\\
if(genre == "" || mood == "" || format == "") {
valid = false;
errors.push("Don't forget about the genre, mood, and format");
}
if(typeof songIso3 == 'undefined') {
valid = false;
errors.push("Please post on land and try again.");
}
// --- Make sure user is logged in --- \\
if($("#boost-title").text() == 'Log in to post') {
valid = false;
errors.push("You must be logged in to post.");
}
// --- Make NFT use NFT type --- \\
if((atomict == '') && format == "nft") {
valid = false;
errors.push("To use NFT format, you must include Template ID");
}
// --- Force NFT type to only be for NFTs--- \\
if((atomict != '') && format != "nft") {
valid = false;
errors.push("To use Template ID, you must choose NFT format ");
}
// --- Get Collection + Verify Audio or Video field --- \\
console.log("atomict",atomict);
if (atomict != ''){
await getAtomicCollection(atomict)
}
var justSendIt = {
"yt":ytSlug,
"yt_channel":window.ytChannelf ? window.ytChannelf: "",
"sc":scSlug,
"spot":spotSlug,
"mood":mood,
"genre":genre,
"lat":songLat,
"lng":songLng,
"format":format,
"iso3":songIso3,
"atomict":atomict,
"atomicc": atomicc || '',
"city_ascii":(typeof songcityascii !== 'undefined') ? songcityascii: "",
"state_code":(typeof songstateid !== 'undefined') ? songstateid: "",
"boost_blux": boost_blux_val,
"boost_tx": txid, // Will be populated if boost succeeds
"posted_by": window.session?.actor.toString() || ""
};
console.log("//justSendIt", justSendIt);
if (Cookies.get('username') !== undefined){
justSendIt.username = Cookies.get('username');
}
if( valid ){ // Send that shit
$.ajax({
method:"post",
url:'php/add_music.php',
data:justSendIt,
dataType:"json"
}) // END .ajax()
.done(function(data) {
// console.log("Response data:", data);
if (data.success == true)
{
// Hide any previous errors
$("#add-music-error").hide();
// Show Success Message
$("#add-music-success").html('Your music has been posted to the map. π Upvote this track and it will grow bigger π±π³').fadeIn(222);
// --- Send event to Google Analytics --- \\ ADD THIS WHEN WE GO LIVE
Cookies.set('lastPost', 'true', { expires: 150 });
console.log("no duplicate error");
$("#yt, #sc, #spot").val('');
//--- Remove +Music Marker ---\\
if (typeof addMusicMarker !== 'undefined')
{
addMusicMarker.remove();
}
// -- Post Song to Map -- \\
//Cookies.set('getItSteemy', data.songid); // Adds cookie that will make user post to Steemit
var marker = L.circleMarker(
[songLat,songLng],
{
radius: 20,
"title": data.songid,
color: genreColors[genre],
fillColor: moodColors[mood]
}
)
.on("click", function (e)
{
//--- Force refresh with ID GET param that makes content display ---\\
urlGet.id = data.songid;
//window.location = location.protocol+'//'+location.host+location.pathname + "?" + $.param(urlGet);
window.location = window.location.protocol + "//" + window.location.host + ( !areWeLive ? "/cxc/" : "/")+ "?id=" + urlGet.id;
}
).addTo(mymap);
} else //END/CTN if (typeof addMusicMarker !== 'undefined')
{
$("#music-geopol-info, #add-music-error, #add-music-success").hide();
//--- either There was a duplicate ---\\
if (data.success == false)
{
// console.log("Error Message Should Appear");
if(typeof data.duplicate != undefined){
$("#add-music-error").html('It looks like we already have that song on the map. Try another!').show();
} else {
$("#add-music-error").html('A wild Error appeared. We aren\'t sure why π€ Try again later.').show();
}
} else {
// --- or Show Exact Error --- \\
htmlErrors = [];
if (data.scInvalid){
htmlErrors.push("The Soundcloud link is in the right format, but showing nothing π§ Make sure it's public and try again.");
}
if (data.ytInvalid){
htmlErrors.push("The YouTube link seems legit, but we can't embedd it. Make sure it's public and try again π§");
}
if (data.spotInvalid){
htmlErrors.push("The Spotify link seems cool, but isn't working. Make sure it's a song not an album π§ Click the three dots and then \"copy song link\".");
}
if (data.duplicate){
htmlErrors.push("It looks like that song is already on the map. Try another +π΅");
}
console.log(errors);
htmlErrorsExpanded = htmlErrors.join("
");
$("#add-music-error").html(htmlErrorsExpanded).show();
}
} //END if (typeof addMusicMarker !== 'undefined')
// console.log(data);
})
.fail(function(jqXHR, textStatus, errorThrown) {
// console.log("AJAX Error Details:");
// console.log("Status:", jqXHR.status);
// console.log("Response Text:", jqXHR.responseText);
// console.log("Text Status:", textStatus);
// console.log("Error Thrown:", errorThrown);
// If we got a 200 status but empty response, try to handle it as success
if (jqXHR.status === 200) {
// console.log("Server returned 200 but response couldn't be parsed as JSON. Treating as success.");
// Show a more specific message to the user
$("#alert-holder")
.prepend('
Your music has been added ππΊπ΅ Please refresh the page to see your submission on the map.