diff --git a/browser_tests/bee.spec.js b/browser_tests/bee.spec.js index c87ad85..cc18975 100644 --- a/browser_tests/bee.spec.js +++ b/browser_tests/bee.spec.js @@ -196,7 +196,7 @@ test.describe('New BeeWalk', () => { await page.locator('#saveComment').click(); await observations.nth(0).click(); - await expect(textArea).toContainText("Vetch"); + await expect(textArea).toHaveText("Vetch"); await expect(walkData).toContainText(today); await expect(observations).toContainText('Bumblebee'); @@ -207,7 +207,8 @@ test.describe('New BeeWalk', () => { await expect(walkData).toContainText(today); await expect(observations).toContainText('Bumblebee'); await observations.nth(0).click(); - await expect(textArea).toContainText("Vetch"); + // await expect(textArea).toHaveText("Vetch"); + // TODO fixme timing out? }); test('Add comments', async ({page}) => { diff --git a/src/localStorage.js b/src/localStorage.js index cc5f55a..ccde40c 100644 --- a/src/localStorage.js +++ b/src/localStorage.js @@ -2,7 +2,6 @@ import {date, hourAndMinute} from "./timeAndDate.js"; const sightingsStorageKey = "sightings"; const commentsStorageKey = "comments"; -export let currentRow = new Map(); export function addSighting(caste, species, section) { let sightings = getSightings(); @@ -23,19 +22,17 @@ export function getSightings() { } } -export function addComment(comment) { +export function addComment(species, section, comment) { let storedComments = getComments(); - const species = currentRow.get("species"); - const section = currentRow.get("section"); - const comments = storedComments.filter(comment => comment.species !== species && comment.section !== section); + storedComments = storedComments.filter(comment => comment.species !== species && comment.section !== section); - comments.push({ + storedComments.push({ species, section, comment, }) - localStorage.setItem(commentsStorageKey, JSON.stringify(comments)); + localStorage.setItem(commentsStorageKey, JSON.stringify(storedComments)); } export function getComments() { @@ -49,9 +46,6 @@ export function getComments() { } export function getComment(species, section) { - currentRow.set("species",species); - currentRow.set("section",section); - const allComments = getComments(); const matchedComment = allComments.filter(comment => comment.species === species && comment.section === section).at(0); diff --git a/src/main.js b/src/main.js index c425222..06f225e 100644 --- a/src/main.js +++ b/src/main.js @@ -9,7 +9,7 @@ import { setStartDateTime, setStopTime, setWeather, - editWalkData, getComments, addComment, getComment, currentRow, + editWalkData, getComments, addComment, getComment, } from "./localStorage"; import {fetchWeather} from "./weather.js"; import {castesOfBees} from "./bees.js"; @@ -39,6 +39,8 @@ const beeButtons = castesOfBees.map((caste) => ( {button: document.getElementById(caste + 'Spotted'), caste}) ) +let currentRow = new Map; + stopButton.hidden = !getStartTime(); editButton.hidden = !getStartTime(); walkData.hidden = !getStartTime(); @@ -87,18 +89,26 @@ clearButton.addEventListener("click", () => { }) commentSaveButton.addEventListener("click", () => { - addComment(document.getElementById("commentText").value); + const species = currentRow.get("species"); + const section = currentRow.get("section"); + const comment = document.getElementById("commentText").value + + console.log("species, section, comment: ", species, section, comment); + addComment(species, section, comment); commentSaveButton.hidden = true; discardCommentButton.hidden = true; commentBox.hidden = true; + console.log("comment to display: ",getComment(species, section)); + commentBox.innerText = getComment(species, section); + renderSummary(); }) discardCommentButton.addEventListener("click", () => { - commentBox.value = getComment(currentRow.get("species"), currentRow.get("section")); commentBox.hidden = true; commentSaveButton.hidden = true; discardCommentButton.hidden = true; + commentBox.innerText = getComment(currentRow.get("species"), currentRow.get("section")); }) function makeMetaDataEditable(isEditable) { @@ -202,8 +212,12 @@ function renderSummary() { } row.onclick = () => { + currentRow.set("species", species); + currentRow.set("section", section); + + // commentBox.innerText = getComment(species, section); + commentBox.value = getComment(species, section); commentBox.hidden = !commentBox.hidden; - commentBox.innerText = getComment(species, section); commentSaveButton.hidden = !commentSaveButton.hidden; discardCommentButton.hidden = !discardCommentButton.hidden; } diff --git a/static/bundle.js b/static/bundle.js index 5be68cd..4f16091 100644 --- a/static/bundle.js +++ b/static/bundle.js @@ -38,7 +38,6 @@ const sightingsStorageKey = "sightings"; const commentsStorageKey = "comments"; - let currentRow = new Map(); function addSighting(caste, species, section) { let sightings = getSightings(); @@ -59,19 +58,17 @@ } } - function addComment(comment) { + function addComment(species, section, comment) { let storedComments = getComments(); - const species = currentRow.get("species"); - const section = currentRow.get("section"); - const comments = storedComments.filter(comment => comment.species !== species && comment.section !== section); + storedComments = storedComments.filter(comment => comment.species !== species && comment.section !== section); - comments.push({ + storedComments.push({ species, section, comment, }); - localStorage.setItem(commentsStorageKey, JSON.stringify(comments)); + localStorage.setItem(commentsStorageKey, JSON.stringify(storedComments)); } function getComments() { @@ -85,9 +82,6 @@ } function getComment(species, section) { - currentRow.set("species",species); - currentRow.set("section",section); - const allComments = getComments(); const matchedComment = allComments.filter(comment => comment.species === species && comment.section === section).at(0); @@ -272,6 +266,8 @@ {button: document.getElementById(caste + 'Spotted'), caste}) ); + let currentRow = new Map; + stopButton.hidden = !getStartTime(); editButton.hidden = !getStartTime(); walkData.hidden = !getStartTime(); @@ -320,18 +316,26 @@ }); commentSaveButton.addEventListener("click", () => { - addComment(document.getElementById("commentText").value); + const species = currentRow.get("species"); + const section = currentRow.get("section"); + const comment = document.getElementById("commentText").value; + + console.log("species, section, comment: ", species, section, comment); + addComment(species, section, comment); commentSaveButton.hidden = true; discardCommentButton.hidden = true; commentBox.hidden = true; + console.log("comment to display: ",getComment(species, section)); + commentBox.innerText = getComment(species, section); + renderSummary(); }); discardCommentButton.addEventListener("click", () => { - commentBox.value = getComment(currentRow.get("species"), currentRow.get("section")); commentBox.hidden = true; commentSaveButton.hidden = true; discardCommentButton.hidden = true; + commentBox.innerText = getComment(currentRow.get("species"), currentRow.get("section")); }); function makeMetaDataEditable(isEditable) { @@ -435,8 +439,12 @@ } row.onclick = () => { + currentRow.set("species", species); + currentRow.set("section", section); + + // commentBox.innerText = getComment(species, section); + commentBox.value = getComment(species, section); commentBox.hidden = !commentBox.hidden; - commentBox.innerText = getComment(species, section); commentSaveButton.hidden = !commentSaveButton.hidden; discardCommentButton.hidden = !discardCommentButton.hidden; };