Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
logging-scratch-gui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Goessmann
logging-scratch-gui
Commits
fb7fd9ee
Commit
fb7fd9ee
authored
6 years ago
by
Paul Kaplan
Browse files
Options
Downloads
Patches
Plain Diff
Refactor manual fetch and use xhr instead
parent
6a3f6fa8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/containers/stage-selector.jsx
+2
-2
2 additions, 2 deletions
src/containers/stage-selector.jsx
src/containers/target-pane.jsx
+4
-5
4 additions, 5 deletions
src/containers/target-pane.jsx
src/lib/backpack-api.js
+19
-1
19 additions, 1 deletion
src/lib/backpack-api.js
with
25 additions
and
8 deletions
src/containers/stage-selector.jsx
+
2
−
2
View file @
fb7fd9ee
...
...
@@ -12,6 +12,7 @@ import DragConstants from '../lib/drag-constants';
import
DropAreaHOC
from
'
../lib/drop-area-hoc.jsx
'
;
import
{
emptyCostume
}
from
'
../lib/empty-assets
'
;
import
sharedMessages
from
'
../lib/shared-messages
'
;
import
{
fetchCode
}
from
'
../lib/backpack-api
'
;
import
StageSelectorComponent
from
'
../components/stage-selector/stage-selector.jsx
'
;
...
...
@@ -101,8 +102,7 @@ class StageSelector extends React.Component {
name
:
dragInfo
.
payload
.
name
},
this
.
props
.
id
);
}
else
if
(
dragInfo
.
dragType
===
DragConstants
.
BACKPACK_CODE
)
{
fetch
(
dragInfo
.
payload
.
bodyUrl
)
.
then
(
response
=>
response
.
json
())
fetchCode
(
dragInfo
.
payload
.
bodyUrl
)
.
then
(
blocks
=>
{
this
.
props
.
vm
.
shareBlocksToTarget
(
blocks
,
this
.
props
.
id
);
this
.
props
.
vm
.
refreshWorkspace
();
...
...
This diff is collapsed.
Click to expand it.
src/containers/target-pane.jsx
+
4
−
5
View file @
fb7fd9ee
...
...
@@ -19,6 +19,7 @@ import {handleFileUpload, spriteUpload} from '../lib/file-uploader.js';
import
sharedMessages
from
'
../lib/shared-messages
'
;
import
{
emptySprite
}
from
'
../lib/empty-assets
'
;
import
{
highlightTarget
}
from
'
../reducers/targets
'
;
import
{
fetchSprite
,
fetchCode
}
from
'
../lib/backpack-api
'
;
class
TargetPane
extends
React
.
Component
{
constructor
(
props
)
{
...
...
@@ -166,8 +167,7 @@ class TargetPane extends React.Component {
}
else
if
(
dragInfo
.
dragType
===
DragConstants
.
BACKPACK_SPRITE
)
{
// TODO storage does not have a way of loading zips right now, and may never need it.
// So for now just grab the zip manually.
fetch
(
dragInfo
.
payload
.
bodyUrl
)
.
then
(
response
=>
response
.
arrayBuffer
())
fetchSprite
(
dragInfo
.
payload
.
bodyUrl
)
.
then
(
sprite3Zip
=>
this
.
props
.
vm
.
addSprite
(
sprite3Zip
));
}
else
if
(
targetId
)
{
// Something is being dragged over one of the sprite tiles or the backdrop.
...
...
@@ -189,12 +189,11 @@ class TargetPane extends React.Component {
},
targetId
);
}
else
if
(
dragInfo
.
dragType
===
DragConstants
.
BACKPACK_SOUND
)
{
this
.
props
.
vm
.
addSound
({
md5
:
dragInfo
.
payload
.
body
,
md5
:
dragInfo
.
payload
.
bod
i
y
,
name
:
dragInfo
.
payload
.
name
},
targetId
);
}
else
if
(
dragInfo
.
dragType
===
DragConstants
.
BACKPACK_CODE
)
{
fetch
(
dragInfo
.
payload
.
bodyUrl
)
.
then
(
response
=>
response
.
json
())
fetchCode
(
dragInfo
.
payload
.
bodyUrl
)
.
then
(
blocks
=>
{
this
.
props
.
vm
.
shareBlocksToTarget
(
blocks
,
targetId
);
this
.
props
.
vm
.
refreshWorkspace
();
...
...
This diff is collapsed.
Click to expand it.
src/lib/backpack-api.js
+
19
−
1
View file @
fb7fd9ee
...
...
@@ -73,6 +73,22 @@ const deleteBackpackObject = ({
});
});
// Two types of backpack items are not retreivable through storage
// code, as json and sprite3 as arraybuffer zips.
const
fetchAs
=
responseType
=>
uri
=>
new
Promise
((
resolve
,
reject
)
=>
{
xhr
({
uri
,
responseType
},
(
error
,
response
)
=>
{
if
(
error
||
response
.
statusCode
!==
200
)
{
return
reject
();
}
return
resolve
(
response
.
body
);
});
});
// These two helpers allow easy fetching of backpack code and sprite zips
// Use the curried fetchAs here so the consumer does not worry about XHR responseTypes
const
fetchCode
=
fetchAs
(
'
json
'
);
const
fetchSprite
=
fetchAs
(
'
arraybuffer
'
);
export
{
getBackpackContents
,
saveBackpackObject
,
...
...
@@ -80,5 +96,7 @@ export {
costumePayload
,
soundPayload
,
spritePayload
,
codePayload
codePayload
,
fetchCode
,
fetchSprite
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment