Commit c0a13ee7 authored by Abinaya Sudhir's avatar Abinaya Sudhir

Solved initial state calling issue

parent aab569f8
...@@ -23,20 +23,29 @@ import Prelude hiding (div) ...@@ -23,20 +23,29 @@ import Prelude hiding (div)
import React.DOM (a, button, div, form, h2, h3, h4, i, input, label, li, p, span, text, ul) import React.DOM (a, button, div, form, h2, h3, h4, i, input, label, li, p, span, text, ul)
import React.DOM.Props (_id, _type, className, href, maxLength, name, onClick, onInput, placeholder, target, value) import React.DOM.Props (_id, _type, className, href, maxLength, name, onClick, onInput, placeholder, target, value)
import Routing.Hash.Aff (setHash) import Routing.Hash.Aff (setHash)
import Thermite (PerformAction, Render, Spec, modifyState, simpleSpec) import Thermite (PerformAction, Render, Spec, cotransform, modifyState, simpleSpec)
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
newtype State = State type State =
{ select_database :: Boolean { select_database :: Boolean
, unselect_database :: Boolean -- dummy state , unselect_database :: Boolean -- dummy state
, response :: Array Response
}
newtype Response = Response
{
count_count :: Int
, count_message :: Maybe String
, count_name :: String
} }
initialState :: State initialState :: State
initialState = State initialState =
{ {
select_database : true select_database : true
, unselect_database : true , unselect_database : true
, response : []
} }
...@@ -44,6 +53,7 @@ data Action ...@@ -44,6 +53,7 @@ data Action
= NoOp = NoOp
| SelectDatabase Boolean | SelectDatabase Boolean
| UnselectDatabase Boolean | UnselectDatabase Boolean
| LoadDatabaseDetails
performAction :: forall eff props. PerformAction (console :: CONSOLE, ajax :: AJAX,dom::DOM | eff) State props Action performAction :: forall eff props. PerformAction (console :: CONSOLE, ajax :: AJAX,dom::DOM | eff) State props Action
...@@ -51,11 +61,19 @@ performAction NoOp _ _ = void do ...@@ -51,11 +61,19 @@ performAction NoOp _ _ = void do
modifyState id modifyState id
performAction (SelectDatabase selected) _ _ = void do performAction (SelectDatabase selected) _ _ = void do
modifyState \(State state) -> State $ state { select_database = selected } modifyState \( state) -> state { select_database = selected }
performAction (UnselectDatabase unselected) _ _ = void do performAction (UnselectDatabase unselected) _ _ = void do
modifyState \(State state) -> State $ state { unselect_database = unselected } modifyState \( state) -> state { unselect_database = unselected }
performAction (LoadDatabaseDetails) _ _ = void do
res <- lift $ getDatabaseDetails
case res of
Left err -> cotransform $ \(state) -> state
Right resData -> do
cotransform $ \(state) -> state {response = resData}
...@@ -92,13 +110,12 @@ addcorpusviewSpec = simpleSpec performAction render ...@@ -92,13 +110,12 @@ addcorpusviewSpec = simpleSpec performAction render
] ]
getDatabaseDetails :: forall eff. Aff (console::CONSOLE,ajax :: AJAX | eff) (Either String (Array Response))
getDatabaseDetais = do getDatabaseDetails = do
let token = "" let token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MTk5OTg1ODMsInVzZXJfaWQiOjUsImVtYWlsIjoiYWxleGFuZHJlLmRlbGFub2VAaXNjcGlmLmZyIiwidXNlcm5hbWUiOiJkZXZlbG9wZXIifQ.Os-3wuFNSmRIxCZi98oFNBu2zqGc0McO-dgDayozHJg"
-- liftEff $ log $ "calling update Age "
affResp <- liftAff $ attempt $ affjax defaultRequest affResp <- liftAff $ attempt $ affjax defaultRequest
{ method = Left GET { method = Left GET
, url ="http://unstable.gargantext.org/api/auth/token" , url ="http://localhost:8009/count"
, headers = [ ContentType applicationJSON , headers = [ ContentType applicationJSON
, Accept applicationJSON , Accept applicationJSON
, RequestHeader "Authorization" $ "Bearer " <> token , RequestHeader "Authorization" $ "Bearer " <> token
...@@ -115,24 +132,10 @@ getDatabaseDetais = do ...@@ -115,24 +132,10 @@ getDatabaseDetais = do
-- updateProfileAge :: forall eff. State -> UpdateAgeReq -> Aff (console::CONSOLE,ajax :: AJAX | eff) (Either String UpdateProfileUserProfile) instance decodeJsonresponse :: DecodeJson Response where
-- updateProfileAge state reqBody = do decodeJson json = do
-- let token = fromMaybe "" $ (\(State s) -> s.token) state obj <- decodeJson json
-- liftEff $ log $ "calling update Age " <> show reqBody count_count <- obj .? "count_count"
-- affResp <- liftAff $ attempt $ affjax defaultRequest count_message <- obj .? "count_message"
-- { method = Left PUT count_name <- obj .? "count_name"
-- , url = host <> "api/users/update_profile_fields" pure $ Response {count_count,count_message,count_name }
-- , headers = [ ContentType applicationJSON
-- , Accept applicationJSON
-- , RequestHeader "Authorization" $ "Bearer " <> token
-- ]
-- , content = Just $ encodeJson reqBody
-- }
-- case affResp of
-- Left err -> do
-- pure $ Left $ show err
-- Right a -> do
-- liftEff $ log $ "POST method Completed"
-- liftEff $ log $ "GET /api response: " <> show a.response
-- let res = decodeJson a.response
-- pure res
...@@ -3,6 +3,7 @@ module Main where ...@@ -3,6 +3,7 @@ module Main where
import Prelude import Prelude
import Control.Monad.Eff (Eff) import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE)
import DOM (DOM) import DOM (DOM)
import DOM.HTML (window) as DOM import DOM.HTML (window) as DOM
import DOM.HTML.Types (htmlDocumentToParentNode) as DOM import DOM.HTML.Types (htmlDocumentToParentNode) as DOM
...@@ -11,6 +12,7 @@ import DOM.Node.ParentNode (QuerySelector(..)) ...@@ -11,6 +12,7 @@ import DOM.Node.ParentNode (QuerySelector(..))
import DOM.Node.ParentNode (querySelector) as DOM import DOM.Node.ParentNode (querySelector) as DOM
import Data.Maybe (fromJust) import Data.Maybe (fromJust)
import Navigation (dispatchAction, initAppState, layoutSpec) import Navigation (dispatchAction, initAppState, layoutSpec)
import Network.HTTP.Affjax (AJAX)
import PageRouter (routeHandler, routing) import PageRouter (routeHandler, routing)
import Partial.Unsafe (unsafePartial) import Partial.Unsafe (unsafePartial)
import React as R import React as R
...@@ -19,9 +21,9 @@ import Routing (matches) ...@@ -19,9 +21,9 @@ import Routing (matches)
import Routing.Hash (getHash, setHash) import Routing.Hash (getHash, setHash)
import Thermite as T import Thermite as T
main :: forall e. Eff (dom:: DOM | e) Unit main :: forall e. Eff (dom:: DOM, console :: CONSOLE, ajax :: AJAX | e ) Unit
main = do main = do
case T.createReactSpec layoutSpec initAppState of case T.createReactSpec layoutSpec initAppState of
{ spec, dispatcher } -> void $ do { spec, dispatcher } -> void $ do
let setRouting this = void $ do let setRouting this = void $ do
matches routing (routeHandler (dispatchAction (dispatcher this))) matches routing (routeHandler (dispatchAction (dispatcher this)))
......
...@@ -3,6 +3,9 @@ module Navigation where ...@@ -3,6 +3,9 @@ module Navigation where
import DOM import DOM
import AddCorpusview as AC import AddCorpusview as AC
import Control.Monad.Aff.Class (liftAff)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Class (liftEff)
import Control.Monad.Eff.Console (CONSOLE) import Control.Monad.Eff.Console (CONSOLE)
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Foldable (fold) import Data.Foldable (fold)
...@@ -13,7 +16,7 @@ import Login as LN ...@@ -13,7 +16,7 @@ import Login as LN
import Network.HTTP.Affjax (AJAX) import Network.HTTP.Affjax (AJAX)
import PageRouter (Routes(..)) import PageRouter (Routes(..))
import Prelude hiding (div) import Prelude hiding (div)
import React.DOM (a, div, i, img, li, span, text, ul) import React.DOM (a, div, i, img, li, span, text, ul)
import React.DOM.Props (_data, _id, aria, className, href, role, src, style, tabIndex, target, title) import React.DOM.Props (_data, _id, aria, className, href, role, src, style, tabIndex, target, title)
import Thermite (PerformAction, Render, Spec, _render, defaultRender, focus, modifyState, simpleSpec, withState) import Thermite (PerformAction, Render, Spec, _render, defaultRender, focus, modifyState, simpleSpec, withState)
...@@ -28,7 +31,7 @@ type AppState = ...@@ -28,7 +31,7 @@ type AppState =
initAppState :: AppState initAppState :: AppState
initAppState = initAppState =
{ currentRoute : Just AddCorpus { currentRoute : Just AddCorpus
, landingState : L.initialState , landingState : L.initialState
, loginState : LN.initialState , loginState : LN.initialState
, addCorpusState : AC.initialState , addCorpusState : AC.initialState
...@@ -210,6 +213,7 @@ sidebarnavSpec = simpleSpec performAction render ...@@ -210,6 +213,7 @@ sidebarnavSpec = simpleSpec performAction render
] ]
layoutSpec :: forall eff props. Spec (E eff) AppState props Action layoutSpec :: forall eff props. Spec (E eff) AppState props Action
layoutSpec = layoutSpec =
fold fold
...@@ -234,5 +238,5 @@ dispatchAction dispatcher _ Login = do ...@@ -234,5 +238,5 @@ dispatchAction dispatcher _ Login = do
dispatchAction dispatcher _ AddCorpus = do dispatchAction dispatcher _ AddCorpus = do
_ <- dispatcher $ SetRoute $ AddCorpus _ <- dispatcher $ SetRoute $ AddCorpus
_ <- dispatcher $ AddCorpusA $ AC.NoOp _ <- dispatcher $ AddCorpusA $ AC.LoadDatabaseDetails
pure unit pure unit
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