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
6be5ec1c
Commit
6be5ec1c
authored
7 years ago
by
Ray Schamp
Browse files
Options
Downloads
Patches
Plain Diff
Load projects through storage
With this change we only use `xhr` in the `CostumeCanvas` component.
parent
0cb28ea9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
Loading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lib/project-loader-hoc.jsx
+13
-34
13 additions, 34 deletions
src/lib/project-loader-hoc.jsx
with
13 additions
and
34 deletions
src/lib/project-loader-hoc.jsx
+
13
−
34
View file @
6be5ec1c
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
xhr
from
'
xhr
'
;
import
log
from
'
./log
'
;
import
log
from
'
./log
'
;
import
emptyProject
from
'
./empty-project.json
'
;
import
storage
from
'
./storage
'
;
class
ProjectLoaderConstructor
{
get
DEFAULT_PROJECT_DATA
()
{
return
emptyProject
;
}
load
(
id
,
callback
)
{
callback
=
callback
||
(
err
=>
log
.
error
(
err
));
xhr
({
uri
:
`https://projects.scratch.mit.edu/internalapi/project/
${
id
}
/get/`
},
(
err
,
res
,
body
)
=>
{
if
(
err
)
return
callback
(
err
);
callback
(
null
,
body
);
});
}
}
const
ProjectLoader
=
new
ProjectLoaderConstructor
();
/* Higher Order Component to provide behavior for loading projects by id from
/* Higher Order Component to provide behavior for loading projects by id from
* the window's hash (#this part in the url)
* the window's hash (#this part in the url)
...
@@ -35,13 +16,21 @@ const ProjectLoaderHOC = function (WrappedComponent) {
...
@@ -35,13 +16,21 @@ const ProjectLoaderHOC = function (WrappedComponent) {
this
.
updateProject
=
this
.
updateProject
.
bind
(
this
);
this
.
updateProject
=
this
.
updateProject
.
bind
(
this
);
this
.
state
=
{
this
.
state
=
{
projectId
:
null
,
projectId
:
null
,
projectData
:
this
.
fetchProjectId
().
length
?
null
:
JSON
.
stringify
(
ProjectLoader
.
DEFAULT_PROJECT_DATA
)
projectData
:
null
};
};
}
}
componentDidMount
()
{
componentDidMount
()
{
window
.
addEventListener
(
'
hashchange
'
,
this
.
updateProject
);
window
.
addEventListener
(
'
hashchange
'
,
this
.
updateProject
);
this
.
updateProject
();
this
.
updateProject
();
}
}
componentDidUpdate
(
prevProps
,
prevState
)
{
if
(
this
.
state
.
projectId
!==
prevState
.
projectId
)
{
storage
.
load
(
storage
.
AssetType
.
Project
,
this
.
state
.
projectId
,
storage
.
DataFormat
.
JSON
)
.
then
(
projectAsset
=>
this
.
setState
({
projectData
:
JSON
.
stringify
(
projectAsset
.
data
)}))
.
catch
(
err
=>
log
.
error
(
err
));
}
}
componentWillUnmount
()
{
componentWillUnmount
()
{
window
.
removeEventListener
(
'
hashchange
'
,
this
.
updateProject
);
window
.
removeEventListener
(
'
hashchange
'
,
this
.
updateProject
);
}
}
...
@@ -49,18 +38,9 @@ const ProjectLoaderHOC = function (WrappedComponent) {
...
@@ -49,18 +38,9 @@ const ProjectLoaderHOC = function (WrappedComponent) {
return
window
.
location
.
hash
.
substring
(
1
);
return
window
.
location
.
hash
.
substring
(
1
);
}
}
updateProject
()
{
updateProject
()
{
cons
t
projectId
=
this
.
fetchProjectId
();
le
t
projectId
=
this
.
fetchProjectId
();
if
(
projectId
!==
this
.
state
.
projectId
)
{
if
(
projectId
!==
this
.
state
.
projectId
)
{
if
(
projectId
.
length
<
1
)
{
if
(
projectId
.
length
<
1
)
projectId
=
0
;
return
this
.
setState
({
projectId
:
projectId
,
projectData
:
JSON
.
stringify
(
ProjectLoader
.
DEFAULT_PROJECT_DATA
)
});
}
ProjectLoader
.
load
(
projectId
,
(
err
,
body
)
=>
{
if
(
err
)
return
log
.
error
(
err
);
this
.
setState
({
projectData
:
body
});
});
this
.
setState
({
projectId
:
projectId
});
this
.
setState
({
projectId
:
projectId
});
}
}
}
}
...
@@ -80,6 +60,5 @@ const ProjectLoaderHOC = function (WrappedComponent) {
...
@@ -80,6 +60,5 @@ const ProjectLoaderHOC = function (WrappedComponent) {
export
{
export
{
ProjectLoaderHOC
as
default
,
ProjectLoaderHOC
as
default
ProjectLoader
};
};
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