Commit 5f98197e authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[upload] more upload work

parent 6fc84226
...@@ -270,7 +270,7 @@ performAction = performAction' where ...@@ -270,7 +270,7 @@ performAction = performAction' where
performAction' (SharePublic { params }) p = sharePublic params p performAction' (SharePublic { params }) p = sharePublic params p
performAction' (AddContact params) p = addContact params p performAction' (AddContact params) p = addContact params p
performAction' (AddNode name nodeType) p = addNode' name nodeType p performAction' (AddNode name nodeType) p = addNode' name nodeType p
performAction' (UploadFile nodeType fileType mName blob) p = uploadFile' nodeType fileType mName blob p performAction' (UploadFile nodeType fileType mName contents) p = uploadFile' nodeType fileType mName contents p
performAction' (UploadArbitraryFile mName blob) p = uploadArbitraryFile' mName blob p performAction' (UploadArbitraryFile mName blob) p = uploadArbitraryFile' mName blob p
performAction' DownloadNode _ = liftEffect $ log "[performAction] DownloadNode" performAction' DownloadNode _ = liftEffect $ log "[performAction] DownloadNode"
performAction' (MoveNode {params}) p = moveNode params p performAction' (MoveNode {params}) p = moveNode params p
...@@ -316,8 +316,8 @@ performAction = performAction' where ...@@ -316,8 +316,8 @@ performAction = performAction' where
addContact params p@{ nodeId: id } = addContact params p@{ nodeId: id } =
void $ Contact.contactReq p.session id params void $ Contact.contactReq p.session id params
uploadFile' nodeType fileType mName blob p@{ tasks, nodeId: id } = do uploadFile' nodeType fileType mName contents p@{ tasks, nodeId: id } = do
task <- uploadFile p.session nodeType id fileType {mName, blob} task <- uploadFile p.session nodeType id fileType {mName, contents}
liftEffect $ do liftEffect $ do
GAT.insert id task tasks GAT.insert id task tasks
log2 "[performAction] UploadFile, uploaded, task:" task log2 "[performAction] UploadFile, uploaded, task:" task
......
...@@ -276,7 +276,7 @@ performAction (ShareTeam username) p = shareTeam username p ...@@ -276,7 +276,7 @@ performAction (ShareTeam username) p = shareTeam username p
performAction (SharePublic { params }) p = sharePublic params p performAction (SharePublic { params }) p = sharePublic params p
performAction (AddContact params) p = addContact params p performAction (AddContact params) p = addContact params p
performAction (AddNode name nodeType) p = addNode' name nodeType p performAction (AddNode name nodeType) p = addNode' name nodeType p
performAction (UploadFile nodeType fileType mName blob) p = uploadFile' nodeType fileType mName blob p performAction (UploadFile nodeType fileType mName contents) p = uploadFile' nodeType fileType mName contents p
performAction (UploadArbitraryFile mName blob) p = uploadArbitraryFile' mName blob p performAction (UploadArbitraryFile mName blob) p = uploadArbitraryFile' mName blob p
performAction DownloadNode _ = liftEffect $ log "[performAction] DownloadNode" performAction DownloadNode _ = liftEffect $ log "[performAction] DownloadNode"
performAction (MoveNode {params}) p = moveNode params p performAction (MoveNode {params}) p = moveNode params p
......
...@@ -28,7 +28,7 @@ data Action = AddNode String GT.NodeType ...@@ -28,7 +28,7 @@ data Action = AddNode String GT.NodeType
| RenameNode String | RenameNode String
| UpdateNode UpdateNodeParams | UpdateNode UpdateNodeParams
| DoSearch GT.AsyncTaskWithType | DoSearch GT.AsyncTaskWithType
| UploadFile GT.NodeType FileType (Maybe String) UploadFileBlob | UploadFile GT.NodeType FileType (Maybe String) String
| UploadArbitraryFile (Maybe String) UploadFileBlob | UploadArbitraryFile (Maybe String) UploadFileBlob
| DownloadNode | DownloadNode
| RefreshTree | RefreshTree
......
...@@ -202,8 +202,9 @@ uploadButtonCpt = here.component "uploadButton" cpt ...@@ -202,8 +202,9 @@ uploadButtonCpt = here.component "uploadButton" cpt
case fileType' of case fileType' of
Arbitrary -> Arbitrary ->
dispatch $ UploadArbitraryFile (Just name) blob dispatch $ UploadArbitraryFile (Just name) blob
_ -> _ -> do
dispatch $ UploadFile nodeType fileType' (Just name) blob contents <- readAsText blob
dispatch $ UploadFile nodeType fileType' (Just name) contents
liftEffect $ do liftEffect $ do
T.write_ Nothing mFile T.write_ Nothing mFile
T.write_ CSV fileType T.write_ CSV fileType
...@@ -313,10 +314,10 @@ uploadFile :: Session ...@@ -313,10 +314,10 @@ uploadFile :: Session
-> GT.NodeType -> GT.NodeType
-> ID -> ID
-> FileType -> FileType
-> {blob :: UploadFileBlob, mName :: Maybe String} -> {contents :: String, mName :: Maybe String}
-> Aff GT.AsyncTaskWithType -> Aff GT.AsyncTaskWithType
uploadFile session nodeType id fileType {mName, blob: UploadFileBlob blob} = do uploadFile session nodeType id fileType { mName, contents } = do
contents <- readAsText blob -- contents <- readAsText blob
task <- postWwwUrlencoded session p (bodyParams contents) task <- postWwwUrlencoded session p (bodyParams contents)
pure $ GT.AsyncTaskWithType {task, typ: GT.Form} pure $ GT.AsyncTaskWithType {task, typ: GT.Form}
--postMultipartFormData session p fileContents --postMultipartFormData session p fileContents
...@@ -453,6 +454,7 @@ uploadTermButtonCpt = here.component "uploadTermButton" cpt ...@@ -453,6 +454,7 @@ uploadTermButtonCpt = here.component "uploadTermButton" cpt
onClick mFile' uploadType' e = do onClick mFile' uploadType' e = do
let {name, blob} = unsafePartial $ fromJust mFile' let {name, blob} = unsafePartial $ fromJust mFile'
void $ launchAff do void $ launchAff do
_ <- dispatch $ UploadFile nodeType uploadType' (Just name) blob contents <- readAsText blob
_ <- dispatch $ UploadFile nodeType uploadType' (Just name) contents
liftEffect $ do liftEffect $ do
T.write_ Nothing mFile T.write_ Nothing mFile
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