From bdd97ff9313d7c695b8b12d205d1c813908a265c Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Wed, 19 Jul 2023 11:43:00 +0200 Subject: [PATCH] DEV: Convert fast-edit on mobile to a modal (#22570) Motivation: to fix an issue with fast-edit positioning on mobile (android) Trying to correctly position that textarea/popper element proved difficult see: https://meta.discourse.org/t/fast-edit-input-container-position/263190 --- .../discourse/app/components/fast-edit.hbs | 17 ++ .../discourse/app/components/fast-edit.js | 42 ++++ .../app/components/modal/fast-edit.hbs | 7 + .../discourse/app/components/quote-button.hbs | 26 +-- .../discourse/app/components/quote-button.js | 183 +++++++----------- .../discourse/app/lib/quote-state.js | 6 + .../discourse/app/modifiers/auto-focus.js | 12 ++ 7 files changed, 160 insertions(+), 133 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/components/fast-edit.hbs create mode 100644 app/assets/javascripts/discourse/app/components/fast-edit.js create mode 100644 app/assets/javascripts/discourse/app/components/modal/fast-edit.hbs create mode 100644 app/assets/javascripts/discourse/app/modifiers/auto-focus.js diff --git a/app/assets/javascripts/discourse/app/components/fast-edit.hbs b/app/assets/javascripts/discourse/app/components/fast-edit.hbs new file mode 100644 index 00000000000..de29fc2d107 --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/fast-edit.hbs @@ -0,0 +1,17 @@ +
+ + + +
\ No newline at end of file diff --git a/app/assets/javascripts/discourse/app/components/fast-edit.js b/app/assets/javascripts/discourse/app/components/fast-edit.js new file mode 100644 index 00000000000..2d6d2acdae4 --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/fast-edit.js @@ -0,0 +1,42 @@ +import Component from "@glimmer/component"; +import { tracked } from "@glimmer/tracking"; +import { action } from "@ember/object"; +import { ajax } from "discourse/lib/ajax"; +import { popupAjaxError } from "discourse/lib/ajax-error"; +import { fixQuotes } from "discourse/components/quote-button"; +import { translateModKey } from "discourse/lib/utilities"; +import I18n from "I18n"; + +export default class FastEdit extends Component { + @tracked value = this.args.initialValue; + @tracked isSaving = false; + + buttonTitle = I18n.t("composer.title", { + modifier: translateModKey("Meta+"), + }); + + @action + updateValue(event) { + this.value = event.target.value; + } + + @action + async save() { + this.isSaving = true; + + try { + const result = await ajax(`/posts/${this.args.post.id}`); + const newRaw = result.raw.replace( + fixQuotes(this.args.initialValue), + fixQuotes(this.value) + ); + + await this.args.post.save({ raw: newRaw }); + } catch (error) { + popupAjaxError(error); + } finally { + this.isSaving = false; + this.args.afterSave?.(); + } + } +} diff --git a/app/assets/javascripts/discourse/app/components/modal/fast-edit.hbs b/app/assets/javascripts/discourse/app/components/modal/fast-edit.hbs new file mode 100644 index 00000000000..d8e5987197c --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/modal/fast-edit.hbs @@ -0,0 +1,7 @@ + + + \ No newline at end of file diff --git a/app/assets/javascripts/discourse/app/components/quote-button.hbs b/app/assets/javascripts/discourse/app/components/quote-button.hbs index 2eb7e71912f..f545f744348 100644 --- a/app/assets/javascripts/discourse/app/components/quote-button.hbs +++ b/app/assets/javascripts/discourse/app/components/quote-button.hbs @@ -2,7 +2,7 @@ {{#if this.embedQuoteButton}}
- {{#if this.siteSettings.enable_fast_edit}} - {{#if this._displayFastEditInput}} -
-