Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
momentollogy committed Apr 13, 2023
1 parent 5dfe0cd commit a44f371
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ <h1>Arduino Piano Buzzer Song Creator V1 <br> <small>by momentollogy</small><br>

<button id="copySongBtn" style="display: none;" onclick="copySongToClipboard(songString)">Copy Song</button>
<button id="postSongButton" class="post-song">Post Song</button>

<button id="loadSongButton" class="load-song">Load Song</button>


Expand Down Expand Up @@ -647,33 +648,21 @@ <h1>Arduino Piano Buzzer Song Creator V1 <br> <small>by momentollogy</small><br>
document.getElementById('loadSongButton').addEventListener('click', loadSong);


async function saveSong() {
function saveSong() {
try {
// Authenticate and load the Google Sheets API
await initClient();
// await gapi.auth2.getAuthInstance().signIn(); // Comment out this line

// Format song data for the Google Sheet
const songTitle = document.getElementById("song-title").value || "Untitled_Song";
const songLength = recordedNotes.length;
const songArray = recordedNotes.map(note => JSON.stringify(note)).join(',');

const values = [[songTitle, songLength, songArray]];

// Call the Google Sheets API to append the data
const spreadsheetId = "1C9cqSvijRkJepxErd_jL0HQ4PCrjC0h7arOYj41DDOg";
const range = "Sheet1!A:C";
const response = await gapi.client.sheets.spreadsheets.values.append({
spreadsheetId: spreadsheetId,
range: range,
valueInputOption: "RAW",
insertDataOption: "INSERT_ROWS",
resource: {
values: values,
},
});
const songData = {
title: songTitle,
length: songLength,
notes: songArray,
};

localStorage.setItem(songTitle, JSON.stringify(songData));

console.log("Song data saved to Google Sheet:", response.result);
console.log("Song data saved to local storage:", songData);
} catch (error) {
console.error("Error saving song data:", error);
}
Expand Down

0 comments on commit a44f371

Please sign in to comment.