A platform for community discussion. Free, open, simple.
FIX: Default event end date picker to next day
Jake Goldsboroughc948a9a4e754
diff --git a/plugins/discourse-events/assets/javascripts/discourse/components/compact-event-editor.gjs b/plugins/discourse-events/assets/javascripts/discourse/components/compact-event-editor.gjsindex fc656c904f7..3dbeafd319d 100644--- a/plugins/discourse-events/assets/javascripts/discourse/components/compact-event-editor.gjs+++ b/plugins/discourse-events/assets/javascripts/discourse/components/compact-event-editor.gjs@@ -473,6 +473,18 @@ export default class CompactEventEditor extends Component {next(() => event.target.showPicker?.());}+ @action+ focusEndDateInput(event) {+ if (!this.endsAt && this.startsAt) {+ const oldConfig = this.#configSnapshot();+ this.endsAt = this.startsAt.clone().add(1, "day");+ this.#reconcileReminders(oldConfig, this.#configSnapshot());+ this.#emitChange();+ }++ this.focusDateInput(event);+ }+@actionhandleTextInputFocus(event) {if (this.capabilities.isIOS) {@@ -781,10 +793,11 @@ export default class CompactEventEditor extends Component {<div class="composer-event__date-wrapper"><inputclass="composer-event__date-input"+ min={{this.formattedStartDate}}type="date"value={{this.formattedEndDate}}{{on "change" this.onEndDateChange}}- {{on "focus" this.focusDateInput}}+ {{on "focus" this.focusEndDateInput}}/><spanclass={{dConcatClassdiff --git a/plugins/discourse-events/test/javascripts/integration/components/compact-event-editor-test.gjs b/plugins/discourse-events/test/javascripts/integration/components/compact-event-editor-test.gjsindex ea4321c32ea..05bb5f89726 100644--- a/plugins/discourse-events/test/javascripts/integration/components/compact-event-editor-test.gjs+++ b/plugins/discourse-events/test/javascripts/integration/components/compact-event-editor-test.gjs@@ -1,4 +1,4 @@-import { fillIn, render } from "@ember/test-helpers";+import { fillIn, findAll, render, triggerEvent } from "@ember/test-helpers";import { module, test } from "qunit";import { setupRenderingTest } from "discourse/tests/helpers/component-test";import CompactEventEditor from "discourse/plugins/discourse-events/discourse/components/compact-event-editor";@@ -172,4 +172,33 @@ module("Integration | Component | CompactEventEditor", function (hooks) {"location stops advertising URLs once url is a separate row");});++ test("defaults the end date to the day after the start date", async function (assert) {+ const initialState = stateWith({+ allDay: true,+ startsAt: moment("2027-07-14T00:00:00Z"),+ endsAt: null,+ });+ let lastState = null;+ await renderEditor(initialState, (state) => (lastState = state));++ assert+ .dom(findAll(".composer-event__date-input")[1])+ .hasAttribute("min", "2027-07-14");++ const endDateInput = findAll(".composer-event__date-input")[1];+ endDateInput.showPicker = () => {};+ await triggerEvent(endDateInput, "focus");++ assert.strictEqual(lastState.endsAt.format("YYYY-MM-DD"), "2027-07-15");+ assert.dom(endDateInput).hasValue("2027-07-15");++ const startDateInput = findAll(".composer-event__date-input")[0];+ startDateInput.value = "2027-08-20";+ await triggerEvent(startDateInput, "change");++ assert+ .dom(findAll(".composer-event__date-input")[1])+ .hasAttribute("min", "2027-08-20");+ });});