From bbc9f1048c3e8746a14b521d4d928cf9b8929c51 Mon Sep 17 00:00:00 2001 From: William Raiford Date: Wed, 16 Feb 2022 12:44:42 -0600 Subject: [PATCH] fixed back bug. fixed camera flipped bug. * back button works on android now. * haven't tested ios. * camera flipped using capacitor by using html5 capture input. * https://github.com/ionic-team/pwa-elements/issues/11#issuecomment-597129425 --- ionic-gib/package.json | 12 +- ionic-gib/src/app/app.component.ts | 12 +- .../action-bar/action-bar.component.html | 8 + .../common/action-bar/action-bar.component.ts | 19 +- .../app/common/bases/ibgib-component-base.ts | 43 +++-- ionic-gib/src/app/common/constants.ts | 1 + ionic-gib/src/app/common/types/ux.ts | 2 +- ionic-gib/src/app/ibgib/ibgib.page.ts | 93 +++------- ionic-gib/src/app/services/common.service.ts | 62 +++++-- .../app/services/ionic-ibgib-nav.service.ts | 162 ++++++++++++++++-- .../src/app/services/ng-ibgib-nav.service.ts | 79 ++++++--- .../views/chat-view/chat-view.component.ts | 12 +- .../root-list-view.component.ts | 19 +- .../tag-list-view/tag-list-view.component.ts | 8 +- 14 files changed, 378 insertions(+), 154 deletions(-) diff --git a/ionic-gib/package.json b/ionic-gib/package.json index 2878138b..3d9b1d05 100644 --- a/ionic-gib/package.json +++ b/ionic-gib/package.json @@ -39,13 +39,15 @@ "sync:android": "ionic capacitor sync android", "sync:ios": "ionic capacitor sync ios", + "man:ff:createprofiles": "echo 'creates test profiles for ff. each profile retains data between sessions. you can delete profiles in ff at url \"about:profiles\"'", "ff:createprofiles": "/Applications/Firefox.app/Contents/MacOS/firefox -CreateProfile \"ibgibtest1\" && /Applications/Firefox.app/Contents/MacOS/firefox -CreateProfile \"ibgibtest2\" && /Applications/Firefox.app/Contents/MacOS/firefox -CreateProfile \"ibgibtest3\"", - "ff": "npm run ff:profile:1", + "man:ff": "echo 'ff starts firefox with web-ext. the numbers after are the test profiles, for simultaneous users. the \"none\" is no profile, which does not retain data between sessions.'", + "ff": "npm run ff:1", "ff:chrome": "web-ext run -s './www' -t firefox-desktop -t chromium --firefox-profile=ibgibtest1 --keep-profile-changes --browser-console", - "ff:profile:none": "web-ext run -s './www' -t firefox-desktop --browser-console", - "ff:profile:1": "web-ext run -s './www' -t firefox-desktop --firefox-profile=ibgibtest1 --keep-profile-changes --browser-console", - "ff:profile:2": "web-ext run -s './www' -t firefox-desktop --firefox-profile=ibgibtest2 --keep-profile-changes --browser-console", - "ff:profile:3": "web-ext run -s './www' -t firefox-desktop --firefox-profile=ibgibtest3 --keep-profile-changes --browser-console", + "ff:none": "web-ext run -s './www' -t firefox-desktop --browser-console", + "ff:1": "web-ext run -s './www' -t firefox-desktop --firefox-profile=ibgibtest1 --keep-profile-changes --browser-console", + "ff:2": "web-ext run -s './www' -t firefox-desktop --firefox-profile=ibgibtest2 --keep-profile-changes --browser-console", + "ff:3": "web-ext run -s './www' -t firefox-desktop --firefox-profile=ibgibtest3 --keep-profile-changes --browser-console", "chrome": "web-ext run -s './www' -t chromium --keep-profile-changes --browser-console", "test": "ng test", "lint": "ng lint", diff --git a/ionic-gib/src/app/app.component.ts b/ionic-gib/src/app/app.component.ts index 466920ea..f004d4ee 100644 --- a/ionic-gib/src/app/app.component.ts +++ b/ionic-gib/src/app/app.component.ts @@ -196,6 +196,10 @@ export class AppComponent extends IbgibComponentBase } // navToAddr = this.tagsAddr; + this.platform.backButton.subscribeWithPriority(10, async () => { + if (this.common?.nav) { await this.common.nav.back(); } + }); + } catch (error) { console.error(`${lc} ${error.message}`); console.error(`${lc} debug create here`); @@ -204,9 +208,15 @@ export class AppComponent extends IbgibComponentBase } finally { this.initializing = false; this.splashScreen.hide(); - if (navToAddr) { await this.navTo({addr: navToAddr}); } + if (navToAddr) { + await this.go({ + toAddr: navToAddr, + fromAddr: h.getIbGibAddr({ibGib: this.ibGib_Context}), + }); + } } }); + if (logalot) { console.log(`${lc} complete. waiting for platform.ready...`); } } diff --git a/ionic-gib/src/app/common/action-bar/action-bar.component.html b/ionic-gib/src/app/common/action-bar/action-bar.component.html index 900c259d..6089ffd2 100644 --- a/ionic-gib/src/app/common/action-bar/action-bar.component.html +++ b/ionic-gib/src/app/common/action-bar/action-bar.component.html @@ -11,7 +11,15 @@ + + + + + + + \ No newline at end of file diff --git a/ionic-gib/src/app/common/action-bar/action-bar.component.ts b/ionic-gib/src/app/common/action-bar/action-bar.component.ts index 7c2f6089..03f4c6ee 100644 --- a/ionic-gib/src/app/common/action-bar/action-bar.component.ts +++ b/ionic-gib/src/app/common/action-bar/action-bar.component.ts @@ -60,10 +60,11 @@ export class ActionBarComponent extends IbgibComponentBase }, { name: 'camera', - type: 'button', + type: 'inputfile-camera', text: 'camera', icon: 'camera-outline', - handler: async (event) => await this.actionAddPic(event), + filepicked: async (event) => await this.actionAddImage(event), + // filepicked: async (event) => await this.handleHtml5PicButton(event), }, { name: 'file', @@ -203,7 +204,10 @@ export class ActionBarComponent extends IbgibComponentBase } else { navToAddr = getIbGibAddr({ibGib: newComment}); } - await this.navTo({addr: navToAddr}); + // await this.go({ + // toAddr: navToAddr, + // fromAddr: h.getIbGibAddr({ibGib: this.ibGib_Context}), + // }); } catch (error) { console.error(`${lc} ${error.message}`) @@ -336,7 +340,10 @@ export class ActionBarComponent extends IbgibComponentBase const navToAddr = this.isMeta ? getIbGibAddr({ibGib: ibGibToRel8}) : getIbGibAddr({ibGib: newContext}); - await this.navTo({addr: navToAddr}); + await this.go({ + toAddr: navToAddr, + fromAddr: h.getIbGibAddr({ibGib: this.ibGib_Context}), + }); } } catch (error) { console.error(`${lc} ${error.message}`); @@ -379,6 +386,10 @@ export class ActionBarComponent extends IbgibComponentBase } } + async handleHtml5PicButton(event: any): Promise { + await this.actionAddImage(event); + } + async actionShowInfo(event: MouseEvent): Promise { const lc = `${this.lc}[${this.actionShowInfo.name}]`; try { diff --git a/ionic-gib/src/app/common/bases/ibgib-component-base.ts b/ionic-gib/src/app/common/bases/ibgib-component-base.ts index 29ecef22..41270429 100644 --- a/ionic-gib/src/app/common/bases/ibgib-component-base.ts +++ b/ionic-gib/src/app/common/bases/ibgib-component-base.ts @@ -4,11 +4,12 @@ import { IbGibAddr, Ib, Gib, V1, TransformResult } from "ts-gib"; import { Injectable } from "@angular/core"; // import { FilesService } from 'src/app/services/files.service'; import { IbgibItem, PicData, CommentData, LatestEventInfo } from '../types'; -import { CommonService } from 'src/app/services/common.service'; +import { CommonService, NavInfo } from 'src/app/services/common.service'; import { DEFAULT_META_IB_STARTS } from '../constants'; import { Subscription } from 'rxjs'; import * as h from 'ts-gib/dist/helper'; import * as c from '../../common/constants'; +import { getGibInfo } from 'ts-gib/dist/V1/transforms/transform-helper'; const logalot = c.GLOBAL_LOG_A_LOT || false; @@ -299,17 +300,37 @@ export abstract class IbgibComponentBase } } - async navTo({ - addr, - queryParamsHandling = 'preserve', + async go({ + toAddr, + fromAddr, queryParams, - }: { - addr: string, - queryParamsHandling?: 'merge' | 'preserve', - queryParams?: { [key: string]: any }, - }): Promise { - if (logalot) { console.log(`navigating to addr: ${addr}`); } - this.common.nav.navTo({addr, queryParamsHandling, queryParams}); + queryParamsHandling = 'preserve', + isModal, + }: NavInfo): Promise { + let lc: string = '[invalid lc] (E: 9048c65ff92e4a08b840cf15d0a2867c)'; + try { + lc = `${this.lc}[${this.go.name}(${toAddr || 'falsy'}) from (${fromAddr || 'falsy'})]`; + if (logalot) { console.log(`starting`); } + + if (!toAddr) { throw new Error(`toAddr required. (E: 963988b52c9047a6bfd3adc87db8d99b)`); } + const toAddr_TjpGib = getGibInfo({ibGibAddr: toAddr}).tjpGib; + + fromAddr = fromAddr ?? this.addr ?? undefined; + const fromAddr_TjpGib = this.addr ? getGibInfo({ibGibAddr: this.addr}).tjpGib : undefined; + + await this.common.nav.go({ + toAddr, toAddr_TjpGib, + fromAddr, fromAddr_TjpGib, + queryParamsHandling, + queryParams, + isModal, + }); + + console.log(`${lc} complete.`) + } catch (error) { + console.error(`${lc} ${error.message}`); + } + // await this.common.nav.navigateRoot(['ibgib', addr], { // queryParamsHandling: 'preserve', // animated: true, diff --git a/ionic-gib/src/app/common/constants.ts b/ionic-gib/src/app/common/constants.ts index 83e0a76f..eed71fd8 100644 --- a/ionic-gib/src/app/common/constants.ts +++ b/ionic-gib/src/app/common/constants.ts @@ -343,6 +343,7 @@ export const HEXADECIMAL_HASH_STRING_REGEXP_32 = /^[0-9a-fA-F]{32}$/; */ export const HEXADECIMAL_HASH_STRING_REGEXP_64 = /^[0-9a-fA-F]{64}$/; +export const QUERY_PARAM_PAUSED = 'paused'; // #region AWS Amazon diff --git a/ionic-gib/src/app/common/types/ux.ts b/ionic-gib/src/app/common/types/ux.ts index bc303e2a..1951f604 100644 --- a/ionic-gib/src/app/common/types/ux.ts +++ b/ionic-gib/src/app/common/types/ux.ts @@ -180,7 +180,7 @@ export const ActionItemName = { } export interface ActionItem { name: ActionItemName; - type: 'button' | 'inputfile'; + type: 'button' | 'inputfile' | 'inputfile-camera'; text: string; icon: string; handler?: (event: MouseEvent) => Promise; diff --git a/ionic-gib/src/app/ibgib/ibgib.page.ts b/ionic-gib/src/app/ibgib/ibgib.page.ts index 9a3443e2..f1f9764e 100644 --- a/ionic-gib/src/app/ibgib/ibgib.page.ts +++ b/ionic-gib/src/app/ibgib/ibgib.page.ts @@ -11,13 +11,12 @@ import * as h from 'ts-gib'; import { IbGibAddr, } from 'ts-gib'; import { getIbGibAddr, pretty } from 'ts-gib/dist/helper'; import { IbGib_V1 } from 'ts-gib/dist/V1'; -import { encrypt, decrypt, SaltStrategy } from 'encrypt-gib'; +import * as c from '../common/constants'; import { IbgibComponentBase } from '../common/bases/ibgib-component-base'; import { CommonService } from '../services/common.service'; import { SPECIAL_URLS } from '../common/constants'; import { LatestEventInfo, } from '../common/types'; -import * as c from '../common/constants'; import { IbgibFullscreenModalComponent } from '../common/ibgib-fullscreen-modal/ibgib-fullscreen-modal.component'; import { getFnAlert, } from '../common/helper'; @@ -60,63 +59,13 @@ export class IbGibPage extends IbgibComponentBase async ngOnInit() { const lc = `${this.lc}[${this.ngOnInit.name}]`; if (logalot) { console.log(`${lc} called.`) } - // this.folder = this.activatedRoute.snapshot.paramMap.get('addr'); - this.subscribeParamMap(); - super.ngOnInit(); - - // await this.testEncryptGib(); - } - - async testEncryptGib(): Promise { - const lc = `${this.lc}[${this.testEncryptGib.name}]`; - // debug test enc-gib - let initialData = 'here is some text'; - // let hexString = await encGib.encodeStringToHexString(data); - // let data2 = await encGib.decodeHexStringToString(hexString); - // console.log(`${lc} data: ${data}`); - // console.log(`${lc} hexString: ${hexString}`); - // console.log(`${lc} data2: ${data2}`); - const salt = await h.getUUID(); - const secret = `great p4SSw0rd?`; - let {encryptedData, errors} = await encrypt({ - dataToEncrypt: initialData, - initialRecursions: 100, - recursionsPerHash: 10, - salt, - saltStrategy: SaltStrategy.appendPerHash, - secret, - confirm: true, - }); - - if (logalot) { console.log(`${lc} initialData: ${initialData}`); } - if (encryptedData) { - if (logalot) { console.log(`${lc} encryptedData: ${encryptedData}`); } - - let { decryptedData, errors: errorsDecrypt } = await decrypt({ - encryptedData, - initialRecursions: 100, - recursionsPerHash: 10, - salt, - saltStrategy: SaltStrategy.appendPerHash, - secret, - }); - - if (decryptedData) { - if (logalot) { console.log(`${lc} decryptedData: ${decryptedData}`); } - if (decryptedData === initialData) { - if (logalot) { console.log(`${lc} initialData equals decryptedData`); } - } - } else { - console.error(`${lc} decryptedData falsy!`); - } - } else if (errors?.length > 0) { - console.error(`${lc} errored!!! here they are...`); - for (let error in errors) { console.error(`${lc} ${error}`); } - console.error(`${lc} end of errors.`) - } else { - if (logalot) { console.log(`${lc} no encryptedData and no errors?`); } + try { + // this.folder = this.activatedRoute.snapshot.paramMap.get('addr'); + this.subscribeParamMap(); + super.ngOnInit(); + } catch (error) { + console.error(`${lc} ${error.message}`); } - } ngOnDestroy() { @@ -153,7 +102,7 @@ export class IbGibPage extends IbgibComponentBase } updatePaused(): void { - this.paused = (this.activatedRoute.snapshot.queryParams['paused'] || 'false') === 'true'; + this.paused = (this.activatedRoute.snapshot.queryParams[c.QUERY_PARAM_PAUSED] || 'false') === 'true'; } subscribeParamMap() { @@ -175,10 +124,10 @@ export class IbGibPage extends IbgibComponentBase } } else { // default special non-ibgib handler, go to the tags ibGib - if (logalot) { console.log(`${lc} special url entered, navTo to tags ibGib`); } const tagsIbGib = await this.common.ibgibs.getSpecialIbgib({type: "tags"}); - addr = getIbGibAddr({ibGib: tagsIbGib}); - await this.navTo({addr}); + let tagsAddr = getIbGibAddr({ibGib: tagsIbGib}); + console.warn(`${lc} special url entered, so defaulting nav to tags ibGib (tagsAddr: ${tagsAddr}) (W: bcc8a669f4f44cbb837080615c3db51a)`); + await this.go({ toAddr: tagsAddr, fromAddr: this.addr }); } }); @@ -292,7 +241,13 @@ export class IbGibPage extends IbgibComponentBase if (this.paused) { this.paused = false; - await this.navTo({addr: this.addr, queryParams: { paused: null }, queryParamsHandling: 'merge'}) + await this.go({ + toAddr: this.addr, + fromAddr: this.addr, + queryParams: { [c.QUERY_PARAM_PAUSED]: null }, + queryParamsHandling: 'merge', + force: true, + }); } if (this.item) { this.item.refreshing = true; } await this.common.ibgibs.pingLatest_Local({ibGib: this.ibGib, tjp: this.tjp}); @@ -308,7 +263,12 @@ export class IbGibPage extends IbgibComponentBase if (!this.tjp) { await this.loadTjp(); } this.paused = true; - await this.navTo({addr: this.addr, queryParams: { paused: true }, queryParamsHandling: 'merge'}) + await this.go({ + toAddr: this.addr, + fromAddr: h.getIbGibAddr({ibGib: this.ibGib_Context}), + queryParams: { [c.QUERY_PARAM_PAUSED]: true }, + queryParamsHandling: 'merge' + }); } catch (error) { console.error(`${lc} ${error.message}`); } @@ -325,7 +285,10 @@ export class IbGibPage extends IbgibComponentBase if (!this.tjpAddr) { await this.loadTjp(); } if (info.tjpAddr !== this.tjpAddr) { return; } if (this.addr !== info.latestAddr) { - await this.navTo({addr: info.latestAddr}); // hack + await this.go({ + toAddr: info.latestAddr, + fromAddr: this.addr, + }); } } catch (error) { console.error(`${lc} ${error.message}`); diff --git a/ionic-gib/src/app/services/common.service.ts b/ionic-gib/src/app/services/common.service.ts index 150af85c..b65155bb 100644 --- a/ionic-gib/src/app/services/common.service.ts +++ b/ionic-gib/src/app/services/common.service.ts @@ -1,19 +1,57 @@ +import { ModalController } from '@ionic/angular'; import { Injectable, Inject } from '@angular/core'; -// import { FilesService } from './files.service'; + import { IbgibsService } from './ibgibs.service'; -import { IbGibAddr } from 'ts-gib'; -import { ModalController } from '@ionic/angular'; +import { Gib, IbGibAddr } from 'ts-gib'; + +export interface NavInfo { + /** The ibgib address we're going to. */ + toAddr: IbGibAddr, + /** + * tjpGib of the toAddr. + * + * if not provided, will get from incoming `toAddr`. + * + * ## notes + * + * When we navigate, sometimes it's just to update an ibgib + * within its own timeline. In this case, unless we're paused, we + * don't want to push the new address to the navigation stack, + * rather we want to replace the prior navigation info with the + * updated address. + */ + toAddr_TjpGib?: Gib; + /** The starting ibgib address from which we're leaving. */ + fromAddr: IbGibAddr, + /** + * tjpGib of the fromAddr. + * + * if not provided, will get from incoming `fromAddr`. + * + * ## notes + * + * When we navigate, sometimes it's just to update an ibgib + * within its own timeline. In this case, unless we're paused, we + * don't want to push the new address to the navigation stack, + * rather we want to replace the prior navigation info with the + * updated address. + */ + fromAddr_TjpGib?: Gib; + /** New query params for the navigation. */ + queryParams?: { [key: string]: any }, + /** How to reconcile existing query params with the new ones. */ + queryParamsHandling?: 'merge' | 'preserve' | '', + /** If true, then this navigation is opening a modal dialog. */ + isModal?: boolean; + /** + * If true, will navigate even if `toAddr === fromAddr`. + */ + force?: boolean; +} export interface IbgibNav { - navTo({ - addr, - queryParamsHandling, - queryParams, - }: { - addr: string, - queryParamsHandling?: 'merge' | 'preserve', - queryParams?: { [key: string]: any }, - }): Promise; + go(info: NavInfo): Promise; + back(): Promise; } /** diff --git a/ionic-gib/src/app/services/ionic-ibgib-nav.service.ts b/ionic-gib/src/app/services/ionic-ibgib-nav.service.ts index dea5b299..5472db03 100644 --- a/ionic-gib/src/app/services/ionic-ibgib-nav.service.ts +++ b/ionic-gib/src/app/services/ionic-ibgib-nav.service.ts @@ -1,10 +1,14 @@ import { Injectable } from '@angular/core'; -import { IbgibNav } from './common.service'; +import { IbgibNav, NavInfo } from './common.service'; import { NavController } from '@ionic/angular'; +import * as h from 'ts-gib/dist/helper'; + import * as c from '../common/constants'; +import { getGibInfo } from 'ts-gib/dist/V1/transforms/transform-helper'; +import { IBGIB_DELIMITER } from 'ts-gib/dist/V1'; -const logalot = c.GLOBAL_LOG_A_LOT || false; +const logalot = c.GLOBAL_LOG_A_LOT || false || true; @Injectable({ providedIn: 'root' @@ -13,32 +17,158 @@ export class IonicIbgibNavService implements IbgibNav { protected lc: string = `[${IonicIbgibNavService.name}]`; + stack: NavInfo[] = []; + constructor( private nav: NavController, - ) { } + ) { + } - async navTo({ - addr, - queryParamsHandling = 'preserve', + async go({ + toAddr, + toAddr_TjpGib, + fromAddr, + fromAddr_TjpGib, queryParams, - }: { - addr: string, - queryParamsHandling?: 'merge' | 'preserve', - queryParams?: { [key: string]: any }, - }): Promise { - const lc: string = `${this.lc}[${this.navTo.name}(${addr || 'undefined|null'})]`; - if (logalot) { console.log(`${lc} called`); } + queryParamsHandling = 'preserve', + isModal, + force, + }: NavInfo): Promise { + const lc: string = `${this.lc}[${this.go.name}]`; + if (logalot) { console.log(`${lc} starting...(${toAddr || 'falsy'}) from (${fromAddr || 'falsy'})`); } + let pushedToStack = false; try { - if (!addr) { throw new Error(`addr required`); } - await this.nav.navigateRoot(['ibgib', addr], { + if (!toAddr) { throw new Error(`toAddr required (E: f4d63bbc37ad4798826de4d2c9eab4a5)`); } + + if (fromAddr === IBGIB_DELIMITER) { fromAddr = undefined; } + + if (logalot) { console.log(`${lc} BEFORE stack: ${h.pretty(this.stack)}`); } + + if (this.stack.length > 0 && this.stack[this.stack.length-1].toAddr === toAddr) { + console.warn(`${lc} duplicate toAddr requested. Nav aborted. (W: cccab7e6ccd840f3a3ea32d9818da233)`) + return; + } else { + /** if we force with to/from addrs equal, then we're forcing a refresh */ + let forceRefresh = false; + if (toAddr === fromAddr) { + if (force) { + // we're performing some kidn of refresh or update + forceRefresh = true; + } else { + console.warn(`${lc} toAddr === fromAddr, so ignoring navigation request. (W: 28cf000a906a4c5caa957135bdfaa9dc)`); + return; // returns + } + } + /** We only want to push to the stack if we're not updating a timeline. */ + const pushToStack = + // we're not refreshing and... + !forceRefresh && + ( + // first navigation + this.stack.length === 0 || + // always push modal + isModal || + // navigating to non-timeline ibgib + !toAddr_TjpGib || + // navigating to NEW timeline + toAddr_TjpGib !== fromAddr_TjpGib || + // updating is paused, so we add even intra-timeline addresses to stack + Object.entries(queryParams ?? {}).some(([k,v]) => k === c.QUERY_PARAM_PAUSED && v === true) + ); + if (pushToStack) { + this.stack.push({ + toAddr, toAddr_TjpGib, + fromAddr, fromAddr_TjpGib, + queryParams, queryParamsHandling, + isModal, + }); + pushedToStack = true; + } + } + + if (!toAddr_TjpGib) { + const toInfo = getGibInfo({ibGibAddr: toAddr}); + toAddr_TjpGib = toInfo.tjpGib ?? undefined; + } + if (fromAddr && !fromAddr_TjpGib) { + const fromInfo = getGibInfo({ibGibAddr: fromAddr}); + fromAddr_TjpGib = fromInfo.tjpGib ?? undefined; + } + + // since we are handling our own stack information, we use `navigateRoot` + // which clears the stack with ionic nav. + await this.nav?.navigateRoot(['ibgib', toAddr], { queryParamsHandling, animated: true, animationDirection: 'forward', queryParams, + }).then(resNav => { + // debugger; + if (!resNav) { + // navResult is false? not sure what would cause this. + if (pushedToStack && this.stack.length > 0) { + console.warn(`${lc} navigation failed. popping errored nav from stack. (W: 3a8db90997be4d7da20554901c837218)`); + this.stack.pop(); + pushedToStack = false; + } + } }); + + if (logalot) { console.log(`${lc} AFTER stack: ${h.pretty(this.stack)}`); } + } catch (error) { - console.error(`${lc} ${error.message}`); + console.error(`${lc} aborting nav. error: ${error.message}`); + if (pushedToStack && this.stack.length > 0) { + if (logalot) { console.log(`${lc} popping errored nav from stack.`)} + this.stack.pop(); + pushedToStack = false; + } + } finally { + if (logalot) { console.log(`${lc} complete.`); } } } + async back(): Promise { + const lc = `${this.lc}[${this.back.name}]`; + if (logalot) { console.log(`${lc} starting...`); } + try { + if (logalot) { console.log(`${lc} stack: ${h.pretty(this.stack)}`); } + // debugger; + // query params handling will require taking a snapshot of the query + // params after going forward with the given merge strategy, i.e., it + // would be best to get the actual url and go there. But we don't have + // that information easily here, so for now, we're going to just merge the + // current into the previous...best effort crunch. + if (this.stack.length === 0) { + if (logalot) { console.warn(`${lc} back stack is completely empty? (W: c62f8e5a00324b879abd7e4a2999d5da)`); } + return; + } else if (this.stack.length === 1) { + // stack is 1, which is our first address and we don't pop. + // and we don't nav. + if (logalot) { console.log(`${lc} back stack is at start.`); } + } else { + this.stack.pop(); + const {toAddr, queryParams, queryParamsHandling, isModal } = + this.stack[this.stack.length-1]; + + if (!isModal) { + // normal back button navigation + await this.nav.navigateRoot(['ibgib', toAddr], { + queryParamsHandling, + animated: true, + animationDirection: 'back', + queryParams, + }); + } else { + // not sure how to handle this yet! + console.warn(`${lc} back called with isModal === true. not sure how to handle this. (W: 071e08be57ca4c9c9c292922e56cf38d)`) + } + } + + } catch (error) { + console.error(`${lc} ${error.message}`); + } finally { + if (logalot) { console.log(`${lc} complete.`); } + } + } } diff --git a/ionic-gib/src/app/services/ng-ibgib-nav.service.ts b/ionic-gib/src/app/services/ng-ibgib-nav.service.ts index 429f5427..2b913054 100644 --- a/ionic-gib/src/app/services/ng-ibgib-nav.service.ts +++ b/ionic-gib/src/app/services/ng-ibgib-nav.service.ts @@ -1,28 +1,51 @@ -import { Injectable } from '@angular/core'; -import { Router } from '@angular/router'; -import { IbgibNav } from './common.service'; - -@Injectable({ - providedIn: 'root' -}) -export class NgIbgibNavService implements IbgibNav { - - protected lc: string = `[${NgIbgibNavService.name}]`; - - constructor( - private router: Router, - ) { } - - async navTo({ addr }: { addr: string; }): Promise { - const lc: string = `${this.lc}[${this.navTo.name}(${addr || 'undefined|null'})]`; - console.log(`${lc} called`); - try { - await this.router.navigate(['ibgib', addr], { - queryParamsHandling: 'preserve', - }); - } catch (error) { - console.error(`${lc} ${error.message}`); - } - } - -} +// import { Injectable } from '@angular/core'; +// import { Router } from '@angular/router'; + +// import * as c from '../common/constants'; +// import { IbgibNav, NavInfo } from './common.service'; + +// const logalot = c.GLOBAL_LOG_A_LOT || false; + +// @Injectable({ +// providedIn: 'root' +// }) +// export class NgIbgibNavService implements IbgibNav { + +// protected lc: string = `[${NgIbgibNavService.name}]`; + +// stack: NavInfo[] = []; + +// constructor( +// private router: Router, +// ) { } + +// async go({ +// toAddr, +// fromAddr, +// queryParamsHandling, +// queryParams, +// isModal, +// }: NavInfo): Promise { +// const lc: string = `${this.lc}[${this.go.name}(${toAddr || 'undefined|null'}) from (${fromAddr || 'undefined|null'})]`; +// if (logalot) { console.log(`${lc} starting...`); } +// try { +// await this.router.navigate(['ibgib', toAddr], { +// queryParamsHandling: 'preserve', +// }).then(resNav => { +// debugger; +// if (resNav) { +// this.stack.push({toAddr, fromAddr, queryParamsHandling, queryParams}); +// } else { +// console.warn(`${lc} navigation failed. Did not add nav info to stack. (W: a9463a5b52ae4c78b24e4a73cf2bff62)`); +// } +// }); + +// } catch (error) { +// console.error(`${lc} ${error.message}`); +// } finally { +// if (logalot) { console.log(`${lc} complete.`); } +// } +// } + + +// } diff --git a/ionic-gib/src/app/views/chat-view/chat-view.component.ts b/ionic-gib/src/app/views/chat-view/chat-view.component.ts index 09e296af..cb39c2b1 100644 --- a/ionic-gib/src/app/views/chat-view/chat-view.component.ts +++ b/ionic-gib/src/app/views/chat-view/chat-view.component.ts @@ -1,10 +1,13 @@ import { Component, OnInit, OnDestroy, Input, ChangeDetectorRef } from '@angular/core'; + +import * as h from 'ts-gib/dist/helper'; import { IbGibAddr } from 'ts-gib'; +import { IbGib_V1 } from 'ts-gib/dist/V1'; + +import * as c from '../../common/constants'; import { CommonService } from 'src/app/services/common.service'; import { IbgibItem } from 'src/app/common/types'; import { IbgibListComponentBase } from 'src/app/common/bases/ibgib-list-component-base'; -import { IbGib_V1 } from 'ts-gib/dist/V1'; -import * as c from '../../common/constants'; const logalot = c.GLOBAL_LOG_A_LOT || false; @@ -53,7 +56,10 @@ export class ChatViewComponent extends IbgibListComponentBase async itemClicked(item: IbgibItem): Promise { if (logalot) { console.log(`item: ${JSON.stringify(item, null, 2)}`); } - await this.navTo({addr: item.addr}); + await this.go({ + toAddr: item.addr, + fromAddr: h.getIbGibAddr({ibGib: this.ibGib_Context}), + }); // this.clicked.emit(item); } } diff --git a/ionic-gib/src/app/views/root-list-view/root-list-view.component.ts b/ionic-gib/src/app/views/root-list-view/root-list-view.component.ts index b9781c80..8969e960 100644 --- a/ionic-gib/src/app/views/root-list-view/root-list-view.component.ts +++ b/ionic-gib/src/app/views/root-list-view/root-list-view.component.ts @@ -1,10 +1,15 @@ import { Component, OnInit, ChangeDetectorRef, Input } from '@angular/core'; -import { IbgibListComponentBase } from 'src/app/common/bases/ibgib-list-component-base'; -import { CommonService } from 'src/app/services/common.service'; -import { IbgibItem } from 'src/app/common/types'; + import { IbGibAddr } from 'ts-gib'; import { IbGib_V1 } from 'ts-gib/dist/V1'; +import * as h from 'ts-gib/dist/helper'; + import * as c from '../../common/constants'; +import { IbgibListComponentBase } from 'src/app/common/bases/ibgib-list-component-base'; +import { CommonService } from 'src/app/services/common.service'; +import { IbgibItem } from 'src/app/common/types'; + +const logalot = c.GLOBAL_LOG_A_LOT || false || true; @Component({ selector: 'root-list', @@ -54,8 +59,10 @@ export class RootListViewComponent } async rootClicked(item: IbgibItem): Promise { - console.log(`item: ${JSON.stringify(item, null, 2)}`); - await this.navTo({addr: item.addr}); - // this.clicked.emit(item); + if (logalot) { console.log(`item: ${JSON.stringify(item, null, 2)}`); } + await this.go({ + toAddr: item.addr, + fromAddr: h.getIbGibAddr({ibGib: this.ibGib_Context}), + }); } } diff --git a/ionic-gib/src/app/views/tag-list-view/tag-list-view.component.ts b/ionic-gib/src/app/views/tag-list-view/tag-list-view.component.ts index a6876709..27ecba40 100644 --- a/ionic-gib/src/app/views/tag-list-view/tag-list-view.component.ts +++ b/ionic-gib/src/app/views/tag-list-view/tag-list-view.component.ts @@ -1,12 +1,13 @@ import { Component, OnInit, ChangeDetectorRef, Input } from '@angular/core'; +import * as h from 'ts-gib/dist/helper'; import { IbGibAddr } from 'ts-gib'; import { IbGib_V1 } from 'ts-gib/dist/V1'; +import * as c from '../../common/constants'; import { IbgibListComponentBase } from 'src/app/common/bases/ibgib-list-component-base'; import { CommonService } from 'src/app/services/common.service'; import { IbgibItem } from 'src/app/common/types'; -import * as c from '../../common/constants'; const logalot = c.GLOBAL_LOG_A_LOT || false; @@ -62,7 +63,10 @@ export class TagListViewComponent async tagClicked(item: IbgibItem): Promise { if (logalot) { console.log(`item: ${JSON.stringify(item, null, 2)}`); } - await this.navTo({addr: item.addr}); + await this.go({ + toAddr: item.addr, + fromAddr: h.getIbGibAddr({ibGib: this.ibGib_Context}), + }); // this.clicked.emit(item); } }