Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 31, 2026

Three related bugs in the schedule creation flow: default time showing past timestamps (e.g., "yesterday 16:40"), the datetime picker value wasn't captured on submit, and charge level slider changes were silently discarded.

Changes

  • Default time calculation: Fixed onChangeSchedule() to only use AI schedule times if they're in the future. The bug was that when an AI schedule existed (e.g., from yesterday when the vehicle was asleep), it would overwrite the correct 12-hour default with a past timestamp. Now checks aiTime > Date.now() before using AI schedule time, otherwise keeps the 12-hour default.

  • Datetime picker binding: Modified schedule-item.vue to emit localSchedule on add, and vehicle-schedule.vue to accept it. Previously only the initial default time was sent regardless of picker changes.

  • Charge level editing: Added newSchedule guard to setLevel() and setDateTime(). These methods called save() which early-returned for schedules without IDs, preventing local state updates. Changes now accumulate locally until submission.

Code flow

// Before: parent used stale initial time
addSchedule(callback) {
  await this.$scClient.updateSchedule(
    undefined, this.vehicle.id, this.newSchedule.type,
    this.newSchedule.level, new Date(this.newSchedule.time)  // ❌ never updated
  );
}

// After: child sends current state
addSchedule() {
  this.$emit('add', this.localSchedule, callback);  // ✅ includes picker changes
}
// Before: AI schedule time used unconditionally
if (f.type === GQLScheduleType.AI) {
  this.guideDateTime = DateTime.fromMillis(
    Math.ceil(new Date(f.time).getTime() / 60e4) * 60e4
  );  // ❌ could be in the past
}

// After: only use if future
if (f.type === GQLScheduleType.AI) {
  const aiTime = Math.ceil(new Date(f.time).getTime() / 60e4) * 60e4;
  if (aiTime > Date.now()) {  // ✅ check before using
    this.guideDateTime = DateTime.fromMillis(aiTime);
  }
}
Original prompt

This section details on the original issue you should resolve

<issue_title>App front-end issues when adding schedule</issue_title>
<issue_description>1. When adding a trip schedule for a vehicle that has been asleep since yesterday, I got the default time "yesterday 16:40". Where is the default time taken from?
2. When clicking "Add" it will use the default time, not the one you picked
3. Charge level can not be changed at all, only works when editing, not adding </issue_description>

<agent_instructions>## Engineering principles

  • Follow first principles and design by contract.
  • Use asserts to catch incorrect usage; do not guard-rail invalid input outside the contract.
  • Optimize and reduce redundancies; split into functions if the same work repeats.
  • Test, iterate, and test again.
  • Second-pass verification that all code is needed; all code must justify its existence, delete if possible.
  • When refactoring, compare logic to ensure behavior is unchanged; if changed, explain why.
  • Avoid aliases/duplicate helpers; prefer a single canonical API. Do not keep backward-compatible shims unless strictly required.
  • Keep dependencies minimal; prefer built-in libraries and self-contained code.
  • Document non-obvious decisions in code comments and PR descriptions.
    </agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits January 31, 2026 11:20
Co-authored-by: fredli74 <6632456+fredli74@users.noreply.github.com>
Co-authored-by: fredli74 <6632456+fredli74@users.noreply.github.com>
Co-authored-by: fredli74 <6632456+fredli74@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix front-end issues when adding trip schedule Fix schedule creation UI: time defaults, picker binding, and level editing Jan 31, 2026
Copilot AI requested a review from fredli74 January 31, 2026 11:25
@fredli74
Copy link
Owner

@copilot This statement makes no sense to me "Changed from now + 12h to now + 1h rounded to 10min intervals. The 12-hour offset caused past times when vehicles had been inactive."

This math cannot end up with a result < Date.now(), yes?

Math.ceil(Date.now() / 60e4) * 60e4 + 12 * 60 * 60e3

Also we do want the schedule 12h in the future, not 1h

Co-authored-by: fredli74 <6632456+fredli74@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 31, 2026

@copilot This statement makes no sense to me "Changed from now + 12h to now + 1h rounded to 10min intervals. The 12-hour offset caused past times when vehicles had been inactive."

This math cannot ...

You're absolutely right - my analysis was incorrect. The math Math.ceil(Date.now() / 60e4) * 60e4 + 12 * 60 * 60e3 always produces a future time.

The actual bug was in onChangeSchedule() (lines 72-76): when an AI schedule exists, it overwrites guideDateTime with the AI schedule's time WITHOUT checking if it's in the past. If the vehicle was asleep and has a stale AI schedule from yesterday, that past time becomes the default.

Fixed in dc91e83: Now only uses the AI schedule time if aiTime > Date.now(), otherwise keeps the 12-hour default. The original 12-hour offset calculation remains unchanged.

@fredli74 fredli74 marked this pull request as ready for review January 31, 2026 12:24
@fredli74 fredli74 merged commit 3d798f5 into master Jan 31, 2026
1 check passed
@fredli74 fredli74 deleted the copilot/fix-schedule-adding-issues branch January 31, 2026 12:27
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dc91e83be7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 188 to +193
async setLevel() {
this.localSchedule.level = this.levelSlider;
this.levelMenu = false;
await this.save();
if (!this.newSchedule) {
await this.save();
}

Choose a reason for hiding this comment

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

P2 Badge Keep displayed level in sync with submitted value

For new schedules, setLevel now only mutates localSchedule and addSchedule submits that local state, but the template still renders {{ schedule.level }} from the prop, which is never updated for new items. This creates a mismatch where the UI shows the old percentage while the submitted schedule uses the new one, so users can unknowingly submit a different level than they see. Consider binding the display to localSchedule.level or syncing newSchedule when edits happen.

Useful? React with 👍 / 👎.

Copy link
Owner

Choose a reason for hiding this comment

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

@codex update this branch with edits

Choose a reason for hiding this comment

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

Summary

Testing

  • ⚠️ Not run (not requested).

Screenshot

  • Not captured (app not run).

View task →

@fredli74 fredli74 restored the copilot/fix-schedule-adding-issues branch January 31, 2026 13:54
@fredli74
Copy link
Owner

@copilot @codex Restoring this branch since fix-schedule-adding-issue is not fully completed. We need to address the issue with {{ schedule.level }}

@chatgpt-codex-connector
Copy link

Summary

Testing

  • ⚠️ Not run (not requested).

View task →

@fredli74 fredli74 deleted the copilot/fix-schedule-adding-issues branch January 31, 2026 14:03
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.

App front-end issues when adding schedule

2 participants