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 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) => {
if (event &&
event.data &&

View File

@ -117,7 +117,7 @@ export default defineComponent({
icon: documentOutline,
data: 'single item',
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) => {
if (event &&
event.data &&

View File

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

View File

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