Skip to content

A platform for community discussion. Free, open, simple.

REFACTOR: Remove container from pwa-utils

Robin Wardc7c3fd420938
diff --git a/app/assets/javascripts/discourse/app/components/invite-panel.js b/app/assets/javascripts/discourse/app/components/invite-panel.js
index 42308e2c7a3..76d8481d75b 100644
--- a/app/assets/javascripts/discourse/app/components/invite-panel.js
+++ b/app/assets/javascripts/discourse/app/components/invite-panel.js
@@ -1,7 +1,7 @@
import I18n from "I18n";
import discourseComputed from "discourse-common/utils/decorators";
import { isEmpty } from "@ember/utils";
-import EmberObject, { action, computed } from "@ember/object";
+import EmberObject, { action } from "@ember/object";
import { alias, and, equal } from "@ember/object/computed";
import Component from "@ember/component";
import { emailValid } from "discourse/lib/utilities";
@@ -189,10 +189,6 @@ export default Component.extend({
);
},
- showContactPicker: computed(function() {
- return this.capabilities.hasContactPicker;
- }),
-
@discourseComputed("emailOrUsername")
showCustomMessage(emailOrUsername) {
return this.inviteModel === this.currentUser || emailValid(emailOrUsername);
@@ -454,7 +450,7 @@ export default Component.extend({
@action
searchContact() {
- getNativeContact(["email"], false).then(result => {
+ getNativeContact(this.capabilities, ["email"], false).then(result => {
this.set("emailOrUsername", result[0].email[0]);
});
}
diff --git a/app/assets/javascripts/discourse/app/components/share-popup.js b/app/assets/javascripts/discourse/app/components/share-popup.js
index 580a6c99ab9..810a9d5f2ca 100644
--- a/app/assets/javascripts/discourse/app/components/share-popup.js
+++ b/app/assets/javascripts/discourse/app/components/share-popup.js
@@ -134,7 +134,9 @@ export default Component.extend({
// use native webshare only when the user clicks on the "chain" icon
if (!$currentTarget.hasClass("post-date")) {
- nativeShare({ url }).then(null, () => this._showUrl($currentTarget, url));
+ nativeShare(this.capabilities, { url }).then(null, () =>
+ this._showUrl($currentTarget, url)
+ );
} else {
this._showUrl($currentTarget, url);
}
diff --git a/app/assets/javascripts/discourse/app/lib/pwa-utils.js b/app/assets/javascripts/discourse/app/lib/pwa-utils.js
index 23746a0cb35..84f4bffcfe4 100644
--- a/app/assets/javascripts/discourse/app/lib/pwa-utils.js
+++ b/app/assets/javascripts/discourse/app/lib/pwa-utils.js
@@ -1,7 +1,6 @@
import { Promise } from "rsvp";
-export function nativeShare(data) {
- const caps = Discourse.__container__.lookup("capabilities:main");
+export function nativeShare(caps, data) {
return new Promise((resolve, reject) => {
if (!(caps.isIOS || caps.isAndroid || caps.isWinphone)) {
reject();
@@ -27,12 +26,10 @@ export function nativeShare(data) {
});
}
-export function getNativeContact(properties, multiple) {
- const caps = Discourse.__container__.lookup("capabilities:main");
+export function getNativeContact(caps, properties, multiple) {
return new Promise((resolve, reject) => {
if (!caps.hasContactPicker) {
- reject();
- return;
+ return reject();
}
navigator.contacts
diff --git a/app/assets/javascripts/discourse/app/templates/components/invite-panel.hbs b/app/assets/javascripts/discourse/app/templates/components/invite-panel.hbs
index a014db3b544..c4bff577784 100644
--- a/app/assets/javascripts/discourse/app/templates/components/invite-panel.hbs
+++ b/app/assets/javascripts/discourse/app/templates/components/invite-panel.hbs
@@ -38,7 +38,7 @@
value=emailOrUsername
placeholderKey="topic.invite_reply.email_placeholder"}}
{{/if}}
- {{#if showContactPicker}}
+ {{#if capabilities.hasContactPicker}}
{{d-button
icon="address-book"
action=(action "searchContact")