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