Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
c0a13ee7
Commit
c0a13ee7
authored
Mar 06, 2018
by
Abinaya Sudhir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Solved initial state calling issue
parent
aab569f8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
36 deletions
+45
-36
AddCorpusview.purs
src/AddCorpusview.purs
+34
-31
Main.purs
src/Main.purs
+4
-2
Navigation.purs
src/Navigation.purs
+7
-3
No files found.
src/AddCorpusview.purs
View file @
c0a13ee7
...
@@ -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
src/Main.purs
View file @
c0a13ee7
...
@@ -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,7 +21,7 @@ import Routing (matches)
...
@@ -19,7 +21,7 @@ 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
...
...
src/Navigation.purs
View file @
c0a13ee7
...
@@ -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)
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment