From b889ed131c00e9969a1767dda047e2f71abd099b Mon Sep 17 00:00:00 2001
From: Mudada <mael.nicolas@imt.fr>
Date: Mon, 21 Jan 2019 14:48:01 +0100
Subject: [PATCH] [HELP] working on a basic alert ffi

Problem with type for myGoto
---
 src/Gargantext/Components/GraphExplorer/Sigmajs.js   |  6 ++++++
 src/Gargantext/Components/GraphExplorer/Sigmajs.purs | 10 +++++++---
 src/Gargantext/Pages/Corpus/Graph.purs               |  3 ++-
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/Gargantext/Components/GraphExplorer/Sigmajs.js b/src/Gargantext/Components/GraphExplorer/Sigmajs.js
index c02cae2a..66cb4d98 100644
--- a/src/Gargantext/Components/GraphExplorer/Sigmajs.js
+++ b/src/Gargantext/Components/GraphExplorer/Sigmajs.js
@@ -39,3 +39,9 @@ exports.sigmaEnableWebGLClass = SJS.SigmaEnableWebGL;
 exports.forceLinkClass = FL.default;
 
 }
+
+const myGoto = function(sigma){
+    alert("My goto ffi");
+};
+
+exports.myGoto = myGoto;
diff --git a/src/Gargantext/Components/GraphExplorer/Sigmajs.purs b/src/Gargantext/Components/GraphExplorer/Sigmajs.purs
index 1bd4ec8e..309a9667 100644
--- a/src/Gargantext/Components/GraphExplorer/Sigmajs.purs
+++ b/src/Gargantext/Components/GraphExplorer/Sigmajs.purs
@@ -2,8 +2,11 @@ module Gargantext.Components.GraphExplorer.Sigmajs where
 
 import Prelude
 
+import Data.Nullable (Nullable)
+import Data.Unit (Unit)
 import Effect (Effect)
-import React (Children, ReactClass, ReactElement, createElement, unsafeCreateElement)
+import React (Children, ReactClass, ReactElement, ReactRef, createElement, unsafeCreateElement)
+import React.DOM.Props (Props)
 import Unsafe.Coerce (unsafeCoerce)
 import Gargantext.Types (class Optional)
 
@@ -242,12 +245,14 @@ sigmaSettings :: forall o. Optional o SigmaSettingProps => { | o } -> SigmaSetti
 sigmaSettings = unsafeCoerce
 
 foreign import data SigmaStyle :: Type
+foreign import myGoto :: Nullable ReactRef -> Effect Unit
 
 type SigmaProps =
   ( renderer :: Renderer
   , settings :: SigmaSettings
   , style :: SigmaStyle
   , graph :: SigmaGraphData
+  , ref :: (Nullable ReactRef -> Effect Unit) -> Props
   , onClickNode :: SigmaNodeEvent -> Unit
   , onOverNode :: SigmaNodeEvent -> Unit
   , onOutNode :: SigmaNodeEvent -> Effect Unit
@@ -311,13 +316,12 @@ newtype ScalingMode = ScalingMode String
 scalingMode :: { inside :: ScalingMode
 , outside :: ScalingMode
 }
+
 scalingMode =
   { inside : ScalingMode "inside"
   , outside : ScalingMode "outside"
   }
 
-
-
 type SigmaSettingProps =
   ( clone :: Boolean
   , immutable :: Boolean
diff --git a/src/Gargantext/Pages/Corpus/Graph.purs b/src/Gargantext/Pages/Corpus/Graph.purs
index 22b2166a..09eb9b83 100644
--- a/src/Gargantext/Pages/Corpus/Graph.purs
+++ b/src/Gargantext/Pages/Corpus/Graph.purs
@@ -25,7 +25,7 @@ import Effect.Aff (Aff, attempt)
 import Effect.Aff.Class (liftAff)
 import Effect.Class (liftEffect)
 import Effect.Console (log)
-import Gargantext.Components.GraphExplorer.Sigmajs (Color(Color), SigmaEasing, SigmaGraphData(SigmaGraphData), SigmaNode, SigmaSettings, canvas, edgeShape, edgeShapes, forceAtlas2, sStyle, sigma, sigmaEasing, sigmaEdge, sigmaEnableWebGL, sigmaNode, sigmaSettings)
+import Gargantext.Components.GraphExplorer.Sigmajs (Color(Color), SigmaEasing, SigmaGraphData(SigmaGraphData), SigmaNode, SigmaSettings, canvas, edgeShape, edgeShapes, forceAtlas2, myGoto, sStyle, sigma, sigmaEasing, sigmaEdge, sigmaEnableWebGL, sigmaNode, sigmaSettings)
 import Gargantext.Components.GraphExplorer.Types (Cluster(..), MetaData(..), Edge(..), GraphData(..), Legend(..), Node(..), getLegendData)
 import Gargantext.Components.Login.Types (AuthData(..), TreeId)
 import Gargantext.Components.RandomText (words)
@@ -192,6 +192,7 @@ render d p (State {sigmaGraphData, settings, legendData}) c =
       [ sigma { graph, settings
               , renderer : canvas
               , style : sStyle { height : "95%"}
+              , ref: myGoto
               , onClickNode : \e -> unsafePerformEffect $ do
                  _ <- log "hello"
                  -- _ <- logs $ unsafeCoerce e
-- 
2.21.0