Uses new `tainacan_mobile_app` page.

This commit is contained in:
mateuswetah 2022-06-29 18:33:12 -03:00
parent 3e4b85d8aa
commit 70bdd9ae2b
4 changed files with 46 additions and 28 deletions

View File

@ -41,7 +41,7 @@ export default {
const thumbnailPlaceholder = computed (() => require('../../assets/placeholder_square_small.png')); const thumbnailPlaceholder = computed (() => require('../../assets/placeholder_square_small.png'));
const openItemEdition = function(item: any) { const openItemEdition = function(item: any) {
wpStore.openInAppBrowser('/collections/' + item.collection_id + '/items/' + item.id + '/edit'); wpStore.openInAppBrowser('?page=tainacan_admin&mobileAppMode=true&itemEditionMode=true#/collections/' + item.collection_id + '/items/' + item.id + '/edit');
wpStore.listenEventInAppBrowser((event: InAppBrowserEvent) => { wpStore.listenEventInAppBrowser((event: InAppBrowserEvent) => {
if (event && if (event &&
event.data && event.data &&

View File

@ -117,7 +117,7 @@ export default defineComponent({
icon: documentOutline, icon: documentOutline,
data: 'single item', data: 'single item',
handler: () => { handler: () => {
wpStore.openInAppBrowser('/collections/' + props.id + '/items/new'); wpStore.openInAppBrowser('?page=tainacan_admin&mobileAppMode=true&itemEditionMode=true#/collections/' + props.id + '/items/new');
wpStore.listenEventInAppBrowser((event: InAppBrowserEvent) => { wpStore.listenEventInAppBrowser((event: InAppBrowserEvent) => {
if (event && if (event &&
event.data && event.data &&

View File

@ -98,7 +98,7 @@ export default {
this.wpStore.userSiteUrl = this.siteUrl; this.wpStore.userSiteUrl = this.siteUrl;
await this.wpStore.fetchApplicationAuthorization(this.siteUrl); await this.wpStore.fetchApplicationAuthorization(this.siteUrl);
if (this.wpStore.authorizationURL) { if (this.wpStore.authorizationURL) {
this.wpStore.createInAppBrowser(); this.wpStore.createInAppBrowser('?page=tainacan_mobile_app');
this.wpStore.inAppBrowser this.wpStore.inAppBrowser
.on("loadstop") .on("loadstop")
.subscribe(this.handleBrowserLoadStop); .subscribe(this.handleBrowserLoadStop);
@ -114,19 +114,17 @@ export default {
) { ) {
const params = new URLSearchParams(event.url.split("?")[1]); const params = new URLSearchParams(event.url.split("?")[1]);
if ( params.get("page") === "tainacan_admin" ) { if ( params.get("page") === "tainacan_mobile_app" ) {
const userLogin = params.get("user_login"); const userLogin = params.get("user_login");
let userToken = params.get("password"); let userToken = params.get("password");
console.log(userToken)
if ( if (
typeof userToken == "string" && typeof userToken == "string" &&
userToken.indexOf("#") >= 0 userToken.indexOf("#") >= 0
) )
userToken = userToken.split("#")[0]; userToken = userToken.split("#")[0];
console.log(userToken, userLogin)
if (!!userLogin && !!userToken) {
this.wpStore.inAppBrowser.hide();
if (!!userLogin && !!userToken) {
await this.wpStore.login( await this.wpStore.login(
this.siteUrl, this.siteUrl,
userLogin, userLogin,
@ -134,6 +132,7 @@ export default {
); );
this.$router.push("/home"); this.$router.push("/home");
} }
this.wpStore.inAppBrowser.hide();
} }
} }
}, },

View File

@ -36,6 +36,7 @@ const useWpStore = defineStore("wp", {
this.userSiteUrl = ""; this.userSiteUrl = "";
this.userToken = ""; this.userToken = "";
this.userLogin = ""; this.userLogin = "";
delete this.inAppBrowser;
console.error("Erro no login:", err); console.error("Erro no login:", err);
return err; return err;
} }
@ -46,6 +47,7 @@ const useWpStore = defineStore("wp", {
this.userSiteUrl = ""; this.userSiteUrl = "";
this.userToken = ""; this.userToken = "";
this.userToken = ""; this.userToken = "";
delete this.inAppBrowser;
await store.set("userIsLoggedIn", false); await store.set("userIsLoggedIn", false);
await store.set("userSiteUrl", ""); await store.set("userSiteUrl", "");
await store.set("userToken", ""); await store.set("userToken", "");
@ -54,6 +56,7 @@ const useWpStore = defineStore("wp", {
this.userSiteUrl = ""; this.userSiteUrl = "";
this.userToken = ""; this.userToken = "";
this.userToken = ""; this.userToken = "";
delete this.inAppBrowser;
console.error("Erro no logoff:", err); console.error("Erro no logoff:", err);
return err; return err;
} }
@ -88,8 +91,8 @@ const useWpStore = defineStore("wp", {
this.userLogin = await store.get("userLogin"); this.userLogin = await store.get("userLogin");
this.userToken = await store.get("userToken"); this.userToken = await store.get("userToken");
}, },
createInAppBrowser(url = '',extraParams = 'location=yes,hideurlbar=yes,fullscreen=no,zoom=no,hardwareback=no,toolbarcolor=#ffffff') { createInAppBrowser(url = '',extraParams = 'location=no,fullscreen=no,zoom=no,hardwareback=yes') {
let tainacanAdminUrl = this.userSiteUrl + "/wp-admin/admin.php?page=tainacan_admin&mobileAppMode=true&itemEditionMode=true" + url; let tainacanAdminUrl = this.userSiteUrl + "/wp-admin/admin.php" + url;
if (!this.userIsLoggedIn && this.authorizationURL) if (!this.userIsLoggedIn && this.authorizationURL)
tainacanAdminUrl = this.authorizationURL + "?app_name=TainacanMobileApp&success_url=" + tainacanAdminUrl; tainacanAdminUrl = this.authorizationURL + "?app_name=TainacanMobileApp&success_url=" + tainacanAdminUrl;
@ -99,22 +102,26 @@ const useWpStore = defineStore("wp", {
openInAppBrowser(url: string) { openInAppBrowser(url: string) {
if (!this.inAppBrowser || !this.inAppBrowser.executeScript) if (!this.inAppBrowser || !this.inAppBrowser.executeScript)
this.createInAppBrowser('#' + url, 'hidden=yes,location=yes,hideurlbar=yes,fullscreen=no,zoom=no,hardwareback=no,toolbarcolor=#ffffff'); this.createInAppBrowser(url, 'hidden=yes,location=no,fullscreen=no,zoom=no,hardwareback=yes');
else {
const urlRedirectionScript = ` const urlRedirectionScript = `
try { try {
window.history.replaceState( window.history.replaceState(
null, null,
null, null,
'${this.userSiteUrl}/wp-admin/admin.php?page=tainacan_admin&mobileAppMode=true&itemEditionMode=true#${url}' '${this.userSiteUrl}/wp-admin/admin.php?page=tainacan_mobile_app'
); );
window.history.go(0); window.history.pushState(
} catch(err){ null,
console.log('catch', err); null,
} '${this.userSiteUrl}/wp-admin/admin.php${url}'
`; );
this.inAppBrowser.executeScript({ code: urlRedirectionScript }); window.history.go(0);
} } catch(err){
console.log('catch', err);
}`;
this.inAppBrowser.executeScript({ code: urlRedirectionScript });
this.inAppBrowser.show(); this.inAppBrowser.show();
}, },
hideInAppBrowser() { hideInAppBrowser() {
@ -123,9 +130,21 @@ const useWpStore = defineStore("wp", {
}, },
listenEventInAppBrowser(event: any) { listenEventInAppBrowser(event: any) {
this.inAppBrowser.on('message').subscribe(event); this.inAppBrowser.on('message').subscribe(event);
this.inAppBrowser.on('exit').subscribe((anEvent: any) => { this.inAppBrowser.on('exit').subscribe(() => {
delete this.inAppBrowser; delete this.inAppBrowser;
}) });
this.inAppBrowser.on("loadstop").subscribe((event: any) => {
if (
event.url &&
typeof event.url == "string" &&
event.url.split("?") &&
event.url.split("?").length >= 2
) {
const params = event.url.split("?")[1];
if ( params.indexOf("tainacan_mobile_app") >= 0)
this.inAppBrowser.hide();
}
});
} }
}, },
}); });