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)
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 Routing.Hash.Aff (setHash)
import Thermite (PerformAction, Render, Spec, modifyState, simpleSpec)
import Thermite (PerformAction, Render, Spec,
cotransform,
modifyState, simpleSpec)
import Unsafe.Coerce (unsafeCoerce)
newtype State = State
type State =
{ select_database :: Boolean
, 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 =
{
select_database : true
, unselect_database : true
, response : []
}
...
...
@@ -44,6 +53,7 @@ data Action
= NoOp
| SelectDatabase Boolean
| UnselectDatabase Boolean
| LoadDatabaseDetails
performAction :: forall eff props. PerformAction (console :: CONSOLE, ajax :: AJAX,dom::DOM | eff) State props Action
...
...
@@ -51,11 +61,19 @@ performAction NoOp _ _ = void do
modifyState id
performAction (SelectDatabase selected) _ _ = void do
modifyState \(
State state) -> State $
state { select_database = selected }
modifyState \(
state) ->
state { select_database = selected }
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
]
getDatabaseDetais = do
let token = ""
-- liftEff $ log $ "calling update Age "
getDatabaseDetails :: forall eff. Aff (console::CONSOLE,ajax :: AJAX | eff) (Either String (Array Response))
getDatabaseDetails = do
let token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MTk5OTg1ODMsInVzZXJfaWQiOjUsImVtYWlsIjoiYWxleGFuZHJlLmRlbGFub2VAaXNjcGlmLmZyIiwidXNlcm5hbWUiOiJkZXZlbG9wZXIifQ.Os-3wuFNSmRIxCZi98oFNBu2zqGc0McO-dgDayozHJg"
affResp <- liftAff $ attempt $ affjax defaultRequest
{ method = Left GET
, url ="http://
unstable.gargantext.org/api/auth/token
"
, url ="http://
localhost:8009/count
"
, headers = [ ContentType applicationJSON
, Accept applicationJSON
, RequestHeader "Authorization" $ "Bearer " <> token
...
...
@@ -115,24 +132,10 @@ getDatabaseDetais = do
-- updateProfileAge :: forall eff. State -> UpdateAgeReq -> Aff (console::CONSOLE,ajax :: AJAX | eff) (Either String UpdateProfileUserProfile)
-- updateProfileAge state reqBody = do
-- let token = fromMaybe "" $ (\(State s) -> s.token) state
-- liftEff $ log $ "calling update Age " <> show reqBody
-- affResp <- liftAff $ attempt $ affjax defaultRequest
-- { method = Left PUT
-- , url = host <> "api/users/update_profile_fields"
-- , 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
instance decodeJsonresponse :: DecodeJson Response where
decodeJson json = do
obj <- decodeJson json
count_count <- obj .? "count_count"
count_message <- obj .? "count_message"
count_name <- obj .? "count_name"
pure $ Response {count_count,count_message,count_name }
src/Main.purs
View file @
c0a13ee7
...
...
@@ -3,6 +3,7 @@ module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE)
import DOM (DOM)
import DOM.HTML (window) as DOM
import DOM.HTML.Types (htmlDocumentToParentNode) as DOM
...
...
@@ -11,6 +12,7 @@ import DOM.Node.ParentNode (QuerySelector(..))
import DOM.Node.ParentNode (querySelector) as DOM
import Data.Maybe (fromJust)
import Navigation (dispatchAction, initAppState, layoutSpec)
import Network.HTTP.Affjax (AJAX)
import PageRouter (routeHandler, routing)
import Partial.Unsafe (unsafePartial)
import React as R
...
...
@@ -19,7 +21,7 @@ import Routing (matches)
import Routing.Hash (getHash, setHash)
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
case T.createReactSpec layoutSpec initAppState of
{ spec, dispatcher } -> void $ do
...
...
src/Navigation.purs
View file @
c0a13ee7
...
...
@@ -3,6 +3,9 @@ module Navigation where
import DOM
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 Data.Either (Either(..))
import Data.Foldable (fold)
...
...
@@ -210,6 +213,7 @@ sidebarnavSpec = simpleSpec performAction render
]
layoutSpec :: forall eff props. Spec (E eff) AppState props Action
layoutSpec =
fold
...
...
@@ -234,5 +238,5 @@ dispatchAction dispatcher _ Login = do
dispatchAction dispatcher _ AddCorpus = do
_ <- dispatcher $ SetRoute $ AddCorpus
_ <- dispatcher $ AddCorpusA $ AC.
NoOp
_ <- dispatcher $ AddCorpusA $ AC.
LoadDatabaseDetails
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