Commit bf623050 authored by Karen Konou's avatar Karen Konou

[Action share] Implement clipboard functionality for sharing URLs

parent 514d4953
Pipeline #7560 passed with stages
in 20 minutes and 5 seconds
...@@ -24,6 +24,7 @@ import Gargantext.Types (ID, NodeID, NodeType) ...@@ -24,6 +24,7 @@ import Gargantext.Types (ID, NodeID, NodeType)
import Gargantext.Types as GT import Gargantext.Types as GT
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.SimpleJSON as GUSJ import Gargantext.Utils.SimpleJSON as GUSJ
import Gargantext.Utils.Clipboard (modalClipboard)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Simple.JSON as JSON import Simple.JSON as JSON
...@@ -212,12 +213,23 @@ shareURLInnercpt :: R.Component (url :: String) ...@@ -212,12 +213,23 @@ shareURLInnercpt :: R.Component (url :: String)
shareURLInnercpt = here.component "shareURLInner" cpt shareURLInnercpt = here.component "shareURLInner" cpt
where where
cpt { url } _ = do cpt { url } _ = do
R.useEffect' $ modalClipboard ".copy" url
pure $ Tools.panelNoFooter pure $ Tools.panelNoFooter
{ mError: Nothing { mError: Nothing
, iconName: "share-alt" , iconName: "share-alt"
, textTitle: "Share the node (URL)" , textTitle: "Share the node (URL)"
} }
[ H.div {} [ H.text url ] ] [ H.div {}
[ H.text url
, B.iconButton
{ name: "clone"
, title: "Copy to clipboard"
, className: "copy"
, callback: \_ -> pure unit
}
]
]
loadUrl :: { session :: Session, id :: NodeID, nodeType :: NodeType } -> AffRESTError String loadUrl :: { session :: Session, id :: NodeID, nodeType :: NodeType } -> AffRESTError String
loadUrl { session, id, nodeType } = get session $ GR.ShareURL id nodeType loadUrl { session, id, nodeType } = get session $ GR.ShareURL id nodeType
import ClipboardJS from "clipboard";
export function _modalClipboard(el, url) {
modal_id = document.getElementsByClassName("b-modal modal show")[0].id
return new ClipboardJS(el, {
container: document.getElementById(modal_id),
text: function(trigger) {
return url
}
});
}
module Gargantext.Utils.Clipboard where
import Effect (Effect)
import Effect.Uncurried (EffectFn2, runEffectFn2)
import Gargantext.Prelude
foreign import _modalClipboard :: EffectFn2 String String Unit
modalClipboard :: String -> String -> Effect Unit
modalClipboard = runEffectFn2 _modalClipboard
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment