Skip to content

Commit

Permalink
fix: Storyly cta behavior with deeplinks on LLD
Browse files Browse the repository at this point in the history
  • Loading branch information
KVNLS committed Jun 11, 2024
1 parent 68fab96 commit 60c9206
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/soft-hairs-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ledger-live-desktop": minor
---

Fix Storyly cta behavior with deeplinks
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ export const InformationDrawer = ({
const tabIndex = useMemo(() => tabs.findIndex(tab => tab.id === tabId), [tabId, tabs]);
const CurrentPanel = tabs[tabIndex].Component;
return (
<SideDrawer isOpen={isOpen} onRequestClose={onRequestClose} direction="left">
<SideDrawer
isOpen={isOpen}
onRequestClose={onRequestClose}
direction="left"
forceDisableFocusTrap
>
<Box height="100%" px="40px">
<TabBar
fullWidth
Expand Down
18 changes: 17 additions & 1 deletion apps/ledger-live-desktop/src/storyly/StorylyProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import React, { createContext, useState, useContext, ReactNode, useRef, useEffect } from "react";
import useFeature from "@ledgerhq/live-common/featureFlags/useFeature";
import { closeAllModal } from "~/renderer/actions/modals";
import { context } from "~/renderer/drawers/Provider";
import { closeInformationCenter } from "~/renderer/actions/UI";
import { useDispatch } from "react-redux";
import { openURL } from "~/renderer/linking";
import { Feature_Storyly, StorylyInstanceType } from "@ledgerhq/types-live";

import { StorylyRef } from "storyly-web";
Expand All @@ -24,6 +29,8 @@ const getTokenForInstanceId = (stories: StoriesType, targetInstanceId: string):

const StorylyProvider: React.FC<StorylyProviderProps> = ({ children }) => {
const [url, setUrl] = useState<string | null>(null);
const dispatch = useDispatch();
const { setDrawer } = useContext(context);
const [token, setToken] = useState<string | null>(null);
const [query, setQuery] = useState<{ g?: string; s?: string; play?: string }>({});

Expand All @@ -39,10 +46,19 @@ const StorylyProvider: React.FC<StorylyProviderProps> = ({ children }) => {
token: token,
events: {
closeStoryGroup: clear,
actionClicked: story => {
if (story?.media?.actionUrl) {
openURL(story.media.actionUrl);
storylyRef.current?.close?.();
dispatch(closeAllModal());
setDrawer();
dispatch(closeInformationCenter());
}
},
},
});
storylyRef.current?.openStory({ group: query?.g, story: query?.s, playMode: query?.play });
}, [params, token, query]);
}, [params, token, query, dispatch, setDrawer]);

useEffect(() => {
if (url) {
Expand Down
16 changes: 15 additions & 1 deletion apps/ledger-live-desktop/src/storyly/useStoryly.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { useFeature } from "@ledgerhq/live-common/featureFlags/index";
import { StorylyInstanceID } from "@ledgerhq/types-live";
import { useLayoutEffect, useRef } from "react";
import { useLayoutEffect, useRef, useContext } from "react";
import { useSelector } from "react-redux";
import { closeAllModal } from "~/renderer/actions/modals";
import { context } from "~/renderer/drawers/Provider";
import { useDispatch } from "react-redux";
import { languageSelector } from "~/renderer/reducers/settings";
import { StorylyStyleProps, useStorylyDefaultStyleProps } from "./style";
import { openURL } from "~/renderer/linking";
import { StorylyRef, StorylyData } from "storyly-web";

/**
Expand All @@ -19,6 +23,8 @@ export const useStoryly = (
instanceId: StorylyInstanceID,
options?: { styleProps: StorylyStyleProps },
) => {
const dispatch = useDispatch();
const { setDrawer } = useContext(context);
const ref = useRef<StorylyRef>();
const dataRef = useRef<StorylyData>();
const props = useStorylyDefaultStyleProps();
Expand All @@ -38,6 +44,14 @@ export const useStoryly = (
dataRef.current = data;
// Triggered when story is ready.
},
actionClicked: story => {
if (story?.media?.actionUrl) {
openURL(story.media.actionUrl);
ref.current?.close?.();
dispatch(closeAllModal());
setDrawer();
}
},
},
props: { ...props, ...options?.styleProps },
});
Expand Down
13 changes: 13 additions & 0 deletions apps/ledger-live-desktop/src/types/storyly-web.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ declare module "storyly-web" {
id: number;
}>;

type Story = {
group_id: number;
id: number;
index: number;
media: {
actionUrl?: string;
};
seen: boolean;
title: string;
};

/**
* Storyly Options
*/
Expand All @@ -15,6 +26,7 @@ declare module "storyly-web" {
events?: {
closeStoryGroup?(): void;
isReady?(data: StorylyData): void;
actionClicked?(story: Story): void;
};
lang?: Language;
segments?: string[];
Expand All @@ -29,6 +41,7 @@ declare module "storyly-web" {
setSegments: (options: StorylyOptions["segments"]) => void;
setLang: (options: { language: StorylyOptions["lang"] }) => void;
openStory: (props: openStoryParams) => void;
close: () => void;
}

interface openStoryParams {
Expand Down

0 comments on commit 60c9206

Please sign in to comment.