A platform for community discussion. Free, open, simple.
DEV: Migrate jump-to-post to the new modal api (#23058)
Jarek Radosz822ecdc91a7d
diff --git a/app/assets/javascripts/discourse/app/components/modal/jump-to-post.hbs b/app/assets/javascripts/discourse/app/components/modal/jump-to-post.hbsnew file mode 100644index 00000000000..99eda3b5d6c--- /dev/null+++ b/app/assets/javascripts/discourse/app/components/modal/jump-to-post.hbs@@ -0,0 +1,51 @@+<DModal+ @closeModal={{@closeModal}}+ @title={{i18n "topic.progress.jump_prompt_long"}}+ class="jump-to-post-modal"+>+ <:body>+ <div class="jump-to-post-form">+ <div class="jump-to-post-control">+ <span class="index">#</span>+ <Input+ @value={{this.postNumber}}+ @type="number"+ autofocus="true"+ id="post-jump"+ />+ <span class="input-hint-text post-number">+ {{i18n "topic.progress.jump_prompt_of" count=this.filteredPostsCount}}+ </span>+ </div>++ <div class="separator">+ <span class="text">+ {{i18n "topic.progress.jump_prompt_or"}}+ </span>+ <hr class="right" />+ </div>++ <div class="jump-to-date-control">+ <span class="input-hint-text post-date">+ {{i18n "topic.progress.jump_prompt_to_date"}}+ </span>+ <DatePicker+ @value={{this.postDate}}+ @defaultDate="YYYY-MM-DD"+ id="post-date"+ class="date-input"+ />+ </div>+ </div>+ </:body>++ <:footer>+ <DButton+ @action={{this.jump}}+ @label="composer.modal_ok"+ type="submit"+ class="btn-primary"+ />+ <DModalCancel @close={{@closeModal}} />+ </:footer>+</DModal>\ No newline at end of filediff --git a/app/assets/javascripts/discourse/app/components/modal/jump-to-post.js b/app/assets/javascripts/discourse/app/components/modal/jump-to-post.jsnew file mode 100644index 00000000000..f71a0cb5c52--- /dev/null+++ b/app/assets/javascripts/discourse/app/components/modal/jump-to-post.js@@ -0,0 +1,32 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { action } from "@ember/object";++export default class JumpToPost extends Component {+ @tracked postNumber;+ @tracked postDate;++ get filteredPostsCount() {+ return this.args.model.topic.postStream.filteredPostsCount;+ }++ _jumpToIndex(postsCounts, postNumber) {+ const where = Math.min(postsCounts, Math.max(1, parseInt(postNumber, 10)));+ this.args.model.jumpToIndex(where);+ this.args.closeModal();+ }++ _jumpToDate(date) {+ this.args.model.jumpToDate(date);+ this.args.closeModal();+ }++ @action+ jump() {+ if (this.postNumber) {+ this._jumpToIndex(this.filteredPostsCount, this.postNumber);+ } else if (this.postDate) {+ this._jumpToDate(this.postDate);+ }+ }+}diff --git a/app/assets/javascripts/discourse/app/components/topic-navigation.js b/app/assets/javascripts/discourse/app/components/topic-navigation.jsindex 447933706a8..6edc1b87c1d 100644--- a/app/assets/javascripts/discourse/app/components/topic-navigation.js+++ b/app/assets/javascripts/discourse/app/components/topic-navigation.js@@ -1,20 +1,23 @@+import Component from "@ember/component";+import { inject as service } from "@ember/service";import PanEvents, {SWIPE_DISTANCE_THRESHOLD,SWIPE_VELOCITY_THRESHOLD,} from "discourse/mixins/pan-events";-import Component from "@ember/component";import EmberObject from "@ember/object";import discourseDebounce from "discourse-common/lib/debounce";import { headerOffset } from "discourse/lib/offset-calculator";import { next } from "@ember/runloop";import discourseLater from "discourse-common/lib/later";import { observes } from "discourse-common/utils/decorators";-import showModal from "discourse/lib/show-modal";+import JumpToPost from "./modal/jump-to-post";const MIN_WIDTH_TIMELINE = 924,MIN_HEIGHT_TIMELINE = 325;export default Component.extend(PanEvents, {+ modal: service(),+classNameBindings: ["info.topicProgressExpanded:topic-progress-expanded","info.renderTimeline:with-timeline:with-topic-progress",@@ -132,13 +135,12 @@ export default Component.extend(PanEvents, {keyboardTrigger(e) {if (e.type === "jump") {- const controller = showModal("jump-to-post", {- modalClass: "jump-to-post-modal",- });- controller.setProperties({- topic: this.topic,- jumpToIndex: this.attrs.jumpToIndex,- jumpToDate: this.attrs.jumpToDate,+ this.modal.show(JumpToPost, {+ model: {+ topic: this.topic,+ jumpToIndex: this.attrs.jumpToIndex,+ jumpToDate: this.attrs.jumpToDate,+ },});}},diff --git a/app/assets/javascripts/discourse/app/controllers/jump-to-post.js b/app/assets/javascripts/discourse/app/controllers/jump-to-post.jsdeleted file mode 100644index 968b3e78eac..00000000000--- a/app/assets/javascripts/discourse/app/controllers/jump-to-post.js+++ /dev/null@@ -1,36 +0,0 @@-import Controller from "@ember/controller";-import ModalFunctionality from "discourse/mixins/modal-functionality";-import { reads } from "@ember/object/computed";-import { action } from "@ember/object";--export default Controller.extend(ModalFunctionality, {- model: null,- postNumber: null,- postDate: null,- filteredPostsCount: reads("topic.postStream.filteredPostsCount"),-- @action- jump() {- if (this.postNumber) {- this._jumpToIndex(this.filteredPostsCount, this.postNumber);- } else if (this.postDate) {- this._jumpToDate(this.postDate);- }- },-- _jumpToIndex(postsCounts, postNumber) {- const where = Math.min(postsCounts, Math.max(1, parseInt(postNumber, 10)));- this.jumpToIndex(where);- this._close();- },-- _jumpToDate(date) {- this.jumpToDate(date);- this._close();- },-- _close() {- this.setProperties({ postNumber: null, postDate: null });- this.send("closeModal");- },-});diff --git a/app/assets/javascripts/discourse/app/controllers/topic.js b/app/assets/javascripts/discourse/app/controllers/topic.jsindex a857bab5c14..c21434ec14a 100644--- a/app/assets/javascripts/discourse/app/controllers/topic.js+++ b/app/assets/javascripts/discourse/app/controllers/topic.js@@ -37,6 +37,7 @@ import { spinnerHTML } from "discourse/helpers/loading-spinner";import { BookmarkFormData } from "discourse/lib/bookmark";import DeleteTopicConfirmModal from "discourse/components/modal/delete-topic-confirm";import ConvertToPublicTopicModal from "discourse/components/modal/convert-to-public-topic";+import JumpToPost from "discourse/components/modal/jump-to-post";let customPostMessageCallbacks = {};@@ -880,15 +881,12 @@ export default Controller.extend(bufferedProperty("model"), {},jumpToPostPrompt() {- const topic = this.model;- const modal = showModal("jump-to-post", {- modalClass: "jump-to-post-modal",- });- modal.setProperties({- topic,- postNumber: null,- jumpToIndex: (index) => this.send("jumpToIndex", index),- jumpToDate: (date) => this.send("jumpToDate", date),+ this.modal.show(JumpToPost, {+ model: {+ topic: this.model,+ jumpToIndex: (index) => this.send("jumpToIndex", index),+ jumpToDate: (date) => this.send("jumpToDate", date),+ },});},diff --git a/app/assets/javascripts/discourse/app/services/modal.js b/app/assets/javascripts/discourse/app/services/modal.jsindex a0f69fd1b62..f50eefa58cf 100644--- a/app/assets/javascripts/discourse/app/services/modal.js+++ b/app/assets/javascripts/discourse/app/services/modal.js@@ -33,7 +33,6 @@ const KNOWN_LEGACY_MODALS = ["history","ignore-duration-with-username","ignore-duration",- "jump-to-post","login","move-to-topic","post-enqueued",diff --git a/app/assets/javascripts/discourse/app/templates/modal/jump-to-post.hbs b/app/assets/javascripts/discourse/app/templates/modal/jump-to-post.hbsdeleted file mode 100644index f5446f4b8be..00000000000--- a/app/assets/javascripts/discourse/app/templates/modal/jump-to-post.hbs+++ /dev/null@@ -1,46 +0,0 @@-<DModalBody @title="topic.progress.jump_prompt_long">-- <div class="jump-to-post-form">- <div class="jump-to-post-control">- <span class="index">#</span>- <Input- id="post-jump"- @type="number"- @value={{this.postNumber}}- @insert-newline={{action "jump"}}- autofocus="true"- />- <span class="input-hint-text post-number">- {{i18n "topic.progress.jump_prompt_of" count=this.filteredPostsCount}}- </span>- </div>-- <div class="separator">- <span class="text">- {{i18n "topic.progress.jump_prompt_or"}}- </span>- <hr class="right" />- </div>-- <div class="jump-to-date-control">- <span class="input-hint-text post-date">- {{i18n "topic.progress.jump_prompt_to_date"}}- </span>- <DatePicker- @id="post-date"- @class="date-input"- @value={{this.postDate}}- @defaultDate="YYYY-MM-DD"- />- </div>- </div>-</DModalBody>--<div class="modal-footer">- <DButton- @class="btn-primary"- @action={{action "jump"}}- @label="composer.modal_ok"- />- <DModalCancel @close={{route-action "closeModal"}} />-</div>\ No newline at end of filediff --git a/app/assets/javascripts/discourse/tests/acceptance/jump-to-test.js b/app/assets/javascripts/discourse/tests/acceptance/jump-to-test.jsindex c0e622c841d..3e979670213 100644--- a/app/assets/javascripts/discourse/tests/acceptance/jump-to-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/jump-to-test.js@@ -1,4 +1,4 @@-import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";+import { acceptance } from "discourse/tests/helpers/qunit-helpers";import { click, currentURL, fillIn, visit } from "@ember/test-helpers";import { test } from "qunit";@@ -7,11 +7,11 @@ acceptance("Jump to", function (needs) {needs.mobileView();needs.pretender((server, helper) => {- server.get("/t/280/excerpts.json", () => helper.response(200, []));- server.get("/t/280/3.json", () => helper.response(200, {}));+ server.get("/t/280/excerpts.json", () => helper.response([]));+ server.get("/t/280/3.json", () => helper.response({}));server.get("/posts/by-date/280/:date", (req) => {if (req.params["date"] === "2014-02-24") {- return helper.response(200, {+ return helper.response({post_number: 3,});}@@ -25,7 +25,7 @@ acceptance("Jump to", function (needs) {await click("nav#topic-progress .nums");await click("button.jump-to-post");- assert.ok(exists(".jump-to-post-modal"), "it shows the modal");+ assert.dom(".jump-to-post-modal").exists("it shows the modal");await fillIn("input.date-picker", "2014-02-24");await click(".jump-to-post-modal .btn-primary");