Skip to content

Fix dietary restriction autosave on initial profile load - #1820

Open
Avinash-006 wants to merge 4 commits into
BCStudentSoftwareDevTeam:developmentfrom
Avinash-006:fix/dietary-restrictions-autosave
Open

Avinash-006 wants to merge 4 commits into
BCStudentSoftwareDevTeam:developmentfrom
Avinash-006:fix/dietary-restrictions-autosave

Conversation

@Avinash-006

Copy link
Copy Markdown
Contributor

Issue Description

Fixes issue #1818.

On a freshly loaded profile, editing dietary restrictions does not send a save request until the user changes the "No dietary restrictions" switch. The textarea's input listener is registered inside the switch's change listener, so each additional switch change also registers another input listener and causes duplicate requests.

Changes

  • Register the dietary textarea input listener once during page initialization.
  • Keep the existing one-second debounce, with a timer shared by the textarea and switch handlers.
  • Consolidate the two switch handlers while preserving show/hide behavior and the immediate "No dietary restrictions" save.
  • Cancel a queued text save when the switch changes.

Testing

  • node --check app/static/js/userProfile.js — passed.
  • git diff --check — passed.
  • Executed the complete profile script in a temporary Node VM harness with mocked jQuery events, AJAX, and timers. Five behavioral checks failed against the original upstream file and passed with this change: initial typing without toggling, rapid typing debounce, cancellation of a queued save when checking the switch, repeated switch changes producing only one save per edit, and clearing the textarea.
  • The temporary harness is not committed. The full Python/MySQL suite and a live application browser test were not run because this environment has no MySQL server.

Suggested application verification

  1. Open a profile's Edit Personal Information modal with the no-restrictions switch off. Type a restriction without touching the switch and wait one second. Confirm the saved notification appears and the value survives a refresh.
  2. Type several changes quickly. Confirm only the final value is submitted after one second of inactivity.
  3. Start typing and check No dietary restrictions before the debounce expires. Confirm one immediate save and that the textarea hides.
  4. Toggle the switch several times, leave it off, and type a restriction. Confirm the textarea is visible and only one save request is sent.
  5. Clear the textarea and wait one second. Confirm the empty value is saved.

Bind the dietary input handler once during page initialization and share
its debounce timer with the no-restrictions switch. Consolidate the switch
handlers and cancel pending text saves when changing the switch.

Fixes BCStudentSoftwareDevTeam#1818
Comment thread app/static/js/userProfile.js Outdated
}

$("#checkDietRestriction").on("change", function() {
clearTimeout(typingTimer);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clearTimeout(typingTimer) here is not necessary because we are not using setTimeout() in this function.

Comment thread app/static/js/userProfile.js Outdated

var typingTimer;
var saveInterval = 1000; //milliseconds
// Register once on page load so typing saves without first changing the switch.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we remove the clearTimeout(typingTImer) above we should declare the variables around here as it is standard to declare variables close to where they are first use: var typingTimer;
var saveInterval = 1000; //milliseconds

Comment thread app/static/js/userProfile.js Outdated

var typingTimer;
var saveInterval = 1000; //milliseconds
// Register once on page load so typing saves without first changing the switch.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also remove this comment: // Register once on page load so typing saves without first changing the switch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants