Unverified Commit 85ebfe5a authored by Mael NICOLAS's avatar Mael NICOLAS Committed by Nicolas Pouillard

[HELP] Can't make the "i pass a callback to ref" idea compile

parent 429b318a
......@@ -40,9 +40,10 @@ exports.forceLinkClass = FL.default;
}
const applyOnCamera = function(f, props){
const camera = props.sigma.cameras[0];
f(camera);
const applyOnCamera = function(props, f){
console.log(props);
//const camera = props.sigma.cameras[0];
//f(camera)
};
exports.applyOnCamera = applyOnCamera;
......@@ -4,8 +4,8 @@ import Prelude
import Data.Nullable (Nullable)
import Effect (Effect)
import Effect.Uncurried (EffectFn2, runEffectFn2)
import React (Children, ReactClass, ReactElement, ReactRef, SyntheticEventHandler, createElement, unsafeCreateElement)
import React.DOM.Props (Props)
import Thermite (EventHandler)
import Unsafe.Coerce (unsafeCoerce)
import Gargantext.Types (class Optional)
......@@ -254,14 +254,17 @@ type Camera =
angle :: Number
}
foreign import applyOnCamera :: forall a. (a -> EventHandler) -> SyntheticEventHandler (Nullable ReactRef)
foreign import applyOnCameraImpl :: forall a. EffectFn2 (Nullable ReactRef) (a -> EventHandler) Unit
applyOnCamera :: forall a. (Nullable ReactRef) -> (a -> EventHandler) -> Effect Unit
applyOnCamera = runEffectFn2 applyOnCameraImpl
type SigmaProps =
( renderer :: Renderer
, settings :: SigmaSettings
, style :: SigmaStyle
, graph :: SigmaGraphData
, ref :: SyntheticEventHandler (Nullable ReactRef)
, ref :: (Nullable ReactRef) -> Effect Unit
, onClickNode :: SigmaNodeEvent -> Unit
, onOverNode :: SigmaNodeEvent -> Unit
, onOutNode :: SigmaNodeEvent -> Effect Unit
......
......@@ -33,6 +33,7 @@ import Gargantext.Components.Tree as Tree
import Gargantext.Config as Config
import Gargantext.Config.REST (get, post)
import Gargantext.Pages.Corpus.Graph.Tabs as GT
import Gargantext.Prelude (flip)
import Gargantext.Utils (getter)
import Math (cos, sin)
import Partial.Unsafe (unsafePartial)
......@@ -56,6 +57,7 @@ data Action
| ChangeNodeSize Number
| DisplayEdges
| SaveCamera Camera
-- | Zoom Boolean
newtype SelectedNode = SelectedNode {id :: String, label :: String}
......@@ -176,6 +178,10 @@ performAction (SaveCamera c) _ _ =
modifyState_ $ \(State s) -> do
State $ ((_camera) .~ (Just c)) s
--performAction (Zoom True) _ _ =
-- modifyState_ $ \() -> do
-- State $
convert :: GraphData -> SigmaGraphData
convert (GraphData r) = SigmaGraphData { nodes, edges}
where
......@@ -199,10 +205,11 @@ render d p (State {sigmaGraphData, settings, legendData}) c =
case sigmaGraphData of
Nothing -> []
Just graph ->
[ sigma { graph, settings
[ sigma { graph
, settings
, renderer : canvas
, style : sStyle { height : "96%"}
, ref: applyOnCamera (d <<< SaveCamera)
, ref: flip applyOnCamera <<< d <<< SaveCamera
, onClickNode : \e -> unsafePerformEffect $ do
_ <- log "this should be deleted"
-- _ <- logs $ unsafeCoerce e
......@@ -503,7 +510,11 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render']
[ span [] [text "Edges"],input [_type "range", _id "myRange", value "90"]
]
, li'
[ button [className "btn btn-primary"] [text "Save"] -- TODO: Implement Save!
[ button [className "btn btn-primary"
, onClick \_ -> do
_ <- log "Hey there" -- $ show st.camera
pure unit
] [text "Save"] -- TODO: Implement Save!
]
]
......@@ -523,7 +534,7 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render']
[ sigma { graph, settings
, renderer : canvas
, style : sStyle { height : "95%"}
, ref: applyOnCamera $ d <<< SaveCamera
, ref: flip applyOnCamera <<< d <<< SaveCamera
, onClickNode : \e -> unsafePerformEffect $ do
_ <- log " hello 2"
--logs $ unsafeCoerce e
......
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