Skip to content

Instantly share code, notes, and snippets.

@jthoms1
Last active September 28, 2021 16:43
Show Gist options
  • Select an option

  • Save jthoms1/07d948e28dbdfba5bda76ad6472e36bc to your computer and use it in GitHub Desktop.

Select an option

Save jthoms1/07d948e28dbdfba5bda76ad6472e36bc to your computer and use it in GitHub Desktop.

Revisions

  1. jthoms1 revised this gist Sep 28, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions index.ts
    Original file line number Diff line number Diff line change
    @@ -6,10 +6,10 @@ const App: React.FC<InitialContext> = () => {
    const [startingRoute, setInitialRoute] = useState(null);

    useEffect(() => {
    const [context, sessionInfo] = await Promise.all(
    const [context, sessionInfo] = await Promise.all([
    Portals.getInitialContext(),
    ShopAPI.getSessionInfo()
    );
    ]);
    setInitialRoute(context.startingRoute);
    setSessionInfo(sessionInfo);
    }, []);
  2. jthoms1 revised this gist Sep 28, 2021. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions index.ts
    Original file line number Diff line number Diff line change
    @@ -6,9 +6,9 @@ const App: React.FC<InitialContext> = () => {
    const [startingRoute, setInitialRoute] = useState(null);

    useEffect(() => {
    const { context, sessionInfo } = await Promise.all(
    Portals.getInitialContext());
    ShopAPI.getSessionInfo());
    const [context, sessionInfo] = await Promise.all(
    Portals.getInitialContext(),
    ShopAPI.getSessionInfo()
    );
    setInitialRoute(context.startingRoute);
    setSessionInfo(sessionInfo);
  3. jthoms1 revised this gist Sep 2, 2021. 1 changed file with 14 additions and 19 deletions.
    33 changes: 14 additions & 19 deletions index.ts
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,19 @@
    import ShopAPI from './ShopAPIPlugin';
    import Portals from '@ionic/portals';

    interface InitialContext {
    startingRoute: string;
    }
    const App: React.FC<InitialContext> = () => {
    const [sessionInfo, setSession] = useState(null);
    const [startingRoute, setInitialRoute] = useState(null);

    Portals.getInitialContext<InitialContext>().then(({ value }) => {
    ReactDOM.render(<App />, document.getElementById('root')
    );
    });

    const App: React.FC<InitialContext> = ({ startingRoute }) => {
    <IonApp>
    <IonReactRouter>
    <IonRouterOutlet>
    <Redirect path="/" exact to={context.startingRoute} />
    <Route path="/address/:id" exact component={AddressPage} />
    <Route path="/checkout" exact component={CheckoutPage} />
    // ...
    </IonRouterOutlet>
    </IonReactRouter>
    </IonApp>
    useEffect(() => {
    const { context, sessionInfo } = await Promise.all(
    Portals.getInitialContext());
    ShopAPI.getSessionInfo());
    );
    setInitialRoute(context.startingRoute);
    setSessionInfo(sessionInfo);
    }, []);

    // ...
    }
    };
  4. jthoms1 revised this gist Sep 2, 2021. 1 changed file with 21 additions and 6 deletions.
    27 changes: 21 additions & 6 deletions index.ts
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,24 @@
    import ShopAPI from './ShopAPIPlugin';
    import Portals from '@ionic/portals';
    // ...

    const portalInitialContext =
    await Portals.getInitialContext<{ startingRoute: string >();
    const sessionInfo = await ShopAPI.getSession();

    console.log(portalInitialContext.startingRoute, sessionInfo);
    interface InitialContext {
    startingRoute: string;
    }

    Portals.getInitialContext<InitialContext>().then(({ value }) => {
    ReactDOM.render(<App />, document.getElementById('root')
    );
    });

    const App: React.FC<InitialContext> = ({ startingRoute }) => {
    <IonApp>
    <IonReactRouter>
    <IonRouterOutlet>
    <Redirect path="/" exact to={context.startingRoute} />
    <Route path="/address/:id" exact component={AddressPage} />
    <Route path="/checkout" exact component={CheckoutPage} />
    // ...
    </IonRouterOutlet>
    </IonReactRouter>
    </IonApp>
    };
  5. jthoms1 revised this gist Sep 2, 2021. 3 changed files with 30 additions and 12 deletions.
    3 changes: 2 additions & 1 deletion index.ts
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,8 @@ import ShopAPI from './ShopAPIPlugin';
    import Portals from '@ionic/portals';
    // ...

    const portalInitialContext = await Portals.getInitialContext<{ startingRoute: string >();
    const portalInitialContext =
    await Portals.getInitialContext<{ startingRoute: string >();
    const sessionInfo = await ShopAPI.getSession();

    console.log(portalInitialContext.startingRoute, sessionInfo);
    21 changes: 15 additions & 6 deletions portal.kt
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,17 @@
    import io.ionic.portals.Portal;
    // ...
    import io.ionic.portals.PortalFragment;

    val portal: Portal = PortalBuilder("myPortal")
    .addPlugin(ShopAPIPlugin::class.java)
    .setInitialContext(mapOf("startingRoute" to "/home"))
    .setStartDir("web_app")
    .create()
    class ProfileFragment : PortalFragment {

    override fun onViewCreated(@NotNull View view, Bundle savedInstanceState) {
    val portal: Portal = PortalBuilder("myPortal")
    .addPlugin(ShopAPIPlugin::class.java)
    .setInitialContext(mapOf("startingRoute" to "/home"))
    .setStartDir("web_app")
    .create()

    var portalView = PortalWebView();

    super.onViewCreated(portalView, savedInstanceState);
    }
    }
    18 changes: 13 additions & 5 deletions portal.swift
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,15 @@
    import IonicPortals
    // ...

    let portal = PortalBuilder("myPortal")
    .setInitialContext(["startingRoute", "/home"])
    .setStartDir("web_app")
    .create()
    class HomeViewController: AppParticipantViewController {

    override func viewDidLoad() {
    let portal = PortalBuilder("myPortal")
    .setInitialContext(["startingRoute", "/home"])
    .setStartDir("web_app")
    .create()

    self.view = PortalWebView(frame: view.frame, portal: portal)
    super.viewDidLoad()
    }

    }
  6. jthoms1 revised this gist Sep 1, 2021. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions index.ts
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    import ShopAPI, { SessionDetails } from './ShopAPIPlugin';
    import ShopAPI from './ShopAPIPlugin';
    import Portals from '@ionic/portals';
    // ...

    const portalInitialContext = await Portals.getInitialContext<{ sessionInfo: SessionDetails >();
    const cartContents = await ShopAPI.getCart();
    const portalInitialContext = await Portals.getInitialContext<{ startingRoute: string >();
    const sessionInfo = await ShopAPI.getSession();

    console.log(portalInitialContext.sessionInfo, cartContents);
    console.log(portalInitialContext.startingRoute, sessionInfo);
  7. jthoms1 revised this gist Sep 1, 2021. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion portal.kt
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,6 @@ import io.ionic.portals.Portal;

    val portal: Portal = PortalBuilder("myPortal")
    .addPlugin(ShopAPIPlugin::class.java)
    .setInitialContext(mapOf("answer" to 42))
    .setInitialContext(mapOf("startingRoute" to "/home"))
    .setStartDir("web_app")
    .create()
    2 changes: 1 addition & 1 deletion portal.swift
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,6 @@ import IonicPortals
    // ...

    let portal = PortalBuilder("myPortal")
    .setInitialContext(["myVariable", 42])
    .setInitialContext(["startingRoute", "/home"])
    .setStartDir("web_app")
    .create()
  8. jthoms1 revised this gist Sep 1, 2021. 1 changed file with 4 additions and 9 deletions.
    13 changes: 4 additions & 9 deletions portal.swift
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,7 @@
    import IonicPortals
    // ...

    let checkoutPortal = Portal("myPortal", "web_app")
    portal.initialContext = ["myVariable", 42]

    let portalWebView = PortalWebView(frame: view.frame, portal: portal)
    self.view = portalWebView
    self.bridge = portalWebView.bridge
    self.bridge.plugin(withName: "ShopAPI") as? ShopAPIPlugin

    super.viewDidLoad()
    let portal = PortalBuilder("myPortal")
    .setInitialContext(["myVariable", 42])
    .setStartDir("web_app")
    .create()
  9. jthoms1 revised this gist Aug 31, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.ts
    Original file line number Diff line number Diff line change
    @@ -5,4 +5,4 @@ import Portals from '@ionic/portals';
    const portalInitialContext = await Portals.getInitialContext<{ sessionInfo: SessionDetails >();
    const cartContents = await ShopAPI.getCart();

    console.log(portalInitialContext, cartContents);
    console.log(portalInitialContext.sessionInfo, cartContents);
  10. jthoms1 revised this gist Aug 31, 2021. 3 changed files with 3 additions and 3 deletions.
    2 changes: 1 addition & 1 deletion index.ts
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    import ShopAPI, { SessionDetails } from './ShopAPIPlugin';
    import Portals from '@ionic/portals';
    ...
    // ...

    const portalInitialContext = await Portals.getInitialContext<{ sessionInfo: SessionDetails >();
    const cartContents = await ShopAPI.getCart();
    2 changes: 1 addition & 1 deletion portal.kt
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    import io.ionic.portals.Portal;
    ...
    // ...

    val portal: Portal = PortalBuilder("myPortal")
    .addPlugin(ShopAPIPlugin::class.java)
    2 changes: 1 addition & 1 deletion portal.swift
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    import IonicPortals
    ...
    // ...

    let checkoutPortal = Portal("myPortal", "web_app")
    portal.initialContext = ["myVariable", 42]
  11. jthoms1 revised this gist Aug 31, 2021. 3 changed files with 7 additions and 0 deletions.
    1 change: 1 addition & 0 deletions index.ts
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    import ShopAPI, { SessionDetails } from './ShopAPIPlugin';
    import Portals from '@ionic/portals';
    ...

    const portalInitialContext = await Portals.getInitialContext<{ sessionInfo: SessionDetails >();
    const cartContents = await ShopAPI.getCart();
    3 changes: 3 additions & 0 deletions portal.kt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    import io.ionic.portals.Portal;
    ...

    val portal: Portal = PortalBuilder("myPortal")
    .addPlugin(ShopAPIPlugin::class.java)
    .setInitialContext(mapOf("answer" to 42))
    3 changes: 3 additions & 0 deletions portal.swift
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    import IonicPortals
    ...

    let checkoutPortal = Portal("myPortal", "web_app")
    portal.initialContext = ["myVariable", 42]

  12. jthoms1 created this gist Aug 31, 2021.
    7 changes: 7 additions & 0 deletions index.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    import ShopAPI, { SessionDetails } from './ShopAPIPlugin';
    import Portals from '@ionic/portals';

    const portalInitialContext = await Portals.getInitialContext<{ sessionInfo: SessionDetails >();
    const cartContents = await ShopAPI.getCart();

    console.log(portalInitialContext, cartContents);
    5 changes: 5 additions & 0 deletions portal.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    val portal: Portal = PortalBuilder("myPortal")
    .addPlugin(ShopAPIPlugin::class.java)
    .setInitialContext(mapOf("answer" to 42))
    .setStartDir("web_app")
    .create()
    9 changes: 9 additions & 0 deletions portal.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    let checkoutPortal = Portal("myPortal", "web_app")
    portal.initialContext = ["myVariable", 42]

    let portalWebView = PortalWebView(frame: view.frame, portal: portal)
    self.view = portalWebView
    self.bridge = portalWebView.bridge
    self.bridge.plugin(withName: "ShopAPI") as? ShopAPIPlugin

    super.viewDidLoad()