Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 368 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 368 Rev 774
Línea 1... Línea 1...
1
import React from "react";
1
import React from 'react'
2
import { useDispatch } from "react-redux";
2
import { useDispatch } from 'react-redux'
3
import { axios } from "../../../../utils";
3
import { axios } from '../../../../utils'
4
import { addNotification } from "../../../../redux/notification/notification.actions";
4
import { addNotification } from '../../../../redux/notification/notification.actions'
Línea 5... Línea 5...
5
 
5
 
6
const ShareController = ({
6
const ShareController = ({
7
  children,
7
  children,
8
  shareData,
8
  shareData,
9
  onInteraction,
9
  onInteraction,
10
  onSuccess,
10
  onSuccess,
11
  onError,
11
  onError,
12
  onNonNativeShare,
12
  onNonNativeShare,
13
  disabled,
13
  disabled
14
}) => {
14
}) => {
Línea 15... Línea 15...
15
  const dispatch = useDispatch();
15
  const dispatch = useDispatch()
16
 
16
 
17
  const getShareUrl = async (url = "") => {
17
  const getShareUrl = async (url = '') => {
18
    axios
18
    axios
19
      .get(url)
19
      .get(url)
20
      .then(({ data }) => {
20
      .then(({ data }) => {
21
        if (!data.success) {
21
        if (!data.success) {
22
          dispatch(addNotification({ style: "danger", msg: data.data }));
22
          dispatch(addNotification({ style: 'danger', msg: data.data }))
Línea 23... Línea 23...
23
          throw new Error(err);
23
          throw new Error(data.data)
24
        }
24
        }
25
 
25
 
26
        return data.data;
26
        return data.data
27
      })
-
 
28
      .catch((err) => {
27
      })
29
        onError(err);
28
      .catch((err) => {
Línea 30... Línea 29...
30
        throw new Error(err);
29
        onError(err)
31
      });
30
      })
32
  };
31
  }
33
 
32
 
34
  const handleOnClick = async () => {
33
  const handleOnClick = async () => {
35
    onInteraction?.();
34
    onInteraction?.()
36
    if (navigator?.share) {
35
    if (navigator?.share) {
37
      try {
36
      try {
38
        const shareUrl = await getShareUrl(shareData.url);
37
        const shareUrl = await getShareUrl(shareData.url)
39
        await navigator.share({ ...shareData, url: shareUrl });
38
        await navigator.share({ ...shareData, url: shareUrl })
40
        onSuccess?.();
-
 
41
      } catch (err) {
39
        onSuccess?.()
42
        dispatch(addNotification({ style: "danger", msg: "Error" }));
40
      } catch (err) {
43
        onError?.(err);
41
        dispatch(addNotification({ style: 'danger', msg: 'Error' }))
44
        throw new Error(err);
42
        onError?.(err)
45
      }
43
      }
46
    } else if (window?.AndroidShareHandler) {
44
    } else if (window?.AndroidShareHandler) {
47
      try {
45
      try {
48
        window.AndroidShareHandler.share(shareData.url, "", "");
46
        window.AndroidShareHandler.share(shareData.url, '', '')
49
      } catch (error) {
47
      } catch (error) {
50
        throw new Error(err);
48
        onError?.(error)
51
      }
49
      }
Línea 52... Línea 50...
52
    } else {
50
    } else {
53
      onNonNativeShare?.();
51
      onNonNativeShare?.()
54
    }
52
    }
55
  };
53
  }
56
 
54
 
57
  return (
55
  return (
58
    <button
56
    <button
59
      className="feed__action"
57
      className='feed__action'
60
      onClick={handleOnClick}
58
      onClick={handleOnClick}
61
      type="button"
59
      type='button'
62
      disabled={disabled}
60
      disabled={disabled}
Línea 63... Línea 61...
63
    >
61
    >