@frak-labs/components 1.0.1 → 1.0.2-beta.9b94b95c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,54 +0,0 @@
1
- import { DebugInfoGatherer, trackEvent } from "@frak-labs/core-sdk";
2
- import { modalBuilder } from "@frak-labs/core-sdk/actions";
3
- import { useCallback, useState } from "preact/hooks";
4
- import { FrakRpcError, RpcErrorCodes } from "@frak-labs/frame-connector";
5
- //#region src/components/ButtonShare/hooks/useShareModal.ts
6
- /**
7
- * Open the share modal
8
- *
9
- * @description
10
- * This function will open the share modal, lazily creating a modal builder on demand.
11
- */
12
- function useShareModal(targetInteraction, placement, sharingLink) {
13
- const [debugInfo, setDebugInfo] = useState(void 0);
14
- const [isError, setIsError] = useState(false);
15
- return {
16
- handleShare: useCallback(async () => {
17
- if (!window.FrakSetup?.client) {
18
- console.error("Frak client not found");
19
- setDebugInfo(DebugInfoGatherer.empty().formatDebugInfo("Frak client not found"));
20
- setIsError(true);
21
- return;
22
- }
23
- const builder = modalBuilder(window.FrakSetup.client, {});
24
- try {
25
- await builder.sharing(sharingLink ? { link: sharingLink } : {}).display((metadata) => ({
26
- ...metadata,
27
- targetInteraction
28
- }), placement);
29
- } catch (e) {
30
- if (e instanceof FrakRpcError && e.code === RpcErrorCodes.clientAborted) {
31
- console.debug("User aborted the modal");
32
- return;
33
- }
34
- const debugInfo = window.FrakSetup.client.debugInfo.formatDebugInfo(e);
35
- trackEvent(window.FrakSetup.client, "share_modal_error", {
36
- placement,
37
- target_interaction: targetInteraction,
38
- error: e instanceof Object && "message" in e ? e.message : "Unknown error"
39
- });
40
- setDebugInfo(debugInfo);
41
- setIsError(true);
42
- console.error("Error while opening the modal", e);
43
- }
44
- }, [
45
- targetInteraction,
46
- placement,
47
- sharingLink
48
- ]),
49
- isError,
50
- debugInfo
51
- };
52
- }
53
- //#endregion
54
- export { useShareModal as t };