Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
Hubs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ar-noc
Hubs
Commits
cdf94cc0
Commit
cdf94cc0
authored
6 years ago
by
Brian Peiris
Browse files
Options
Downloads
Patches
Plain Diff
preload environment images
parent
26431c68
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/react-components/hub-create-panel.js
+42
-14
42 additions, 14 deletions
src/react-components/hub-create-panel.js
with
42 additions
and
14 deletions
src/react-components/hub-create-panel.js
+
42
−
14
View file @
cdf94cc0
...
...
@@ -7,7 +7,7 @@ import faAngleLeft from "@fortawesome/fontawesome-free-solid/faAngleLeft";
import
faAngleRight
from
"
@fortawesome/fontawesome-free-solid/faAngleRight
"
;
import
FontAwesomeIcon
from
"
@fortawesome/react-fontawesome
"
;
import
de
a
fault_scene_preview_thumbnail
from
"
../assets/images/default_thumbnail.png
"
;
import
default_scene_preview_thumbnail
from
"
../assets/images/default_thumbnail.png
"
;
const
HUB_NAME_PATTERN
=
"
^[A-Za-z0-9-'
\"
:!@#$%^&*(),.?~ ]{4,64}$
"
;
...
...
@@ -21,15 +21,34 @@ class HubCreatePanel extends Component {
super
(
props
);
this
.
state
=
{
ready
:
false
,
name
:
generateHubName
(),
environmentIndex
:
Math
.
floor
(
Math
.
random
()
*
props
.
environments
.
length
),
// HACK: expand on small screens by default to ensure scene selection possible.
// Eventually this could/should be done via media queries.
expanded
:
window
.
innerWidth
<
420
environmentIndex
:
Math
.
floor
(
Math
.
random
()
*
props
.
environments
.
length
)
};
// HACK: expand on small screens by default to ensure scene selection possible.
// Eventually this could/should be done via media queries.
if
(
window
.
innerWidth
<
420
)
{
(
async
()
=>
{
const
environmentThumbnail
=
this
.
_getEnvironmentThumbnail
(
this
.
state
.
environmentIndex
);
await
this
.
_preloadImage
(
environmentThumbnail
.
srcset
);
this
.
setState
({
ready
:
true
,
expanded
:
true
});
})();
}
else
{
this
.
state
.
ready
=
true
;
}
}
_getEnvironmentThumbnail
=
environmentIndex
=>
{
const
environment
=
this
.
props
.
environments
[
environmentIndex
];
const
meta
=
environment
.
meta
||
{};
return
(
(
meta
.
images
||
[]).
find
(
i
=>
i
.
type
===
"
preview-thumbnail
"
)
||
{
srcset
:
default_scene_preview_thumbnail
}
);
};
createHub
=
async
e
=>
{
e
.
preventDefault
();
const
environment
=
this
.
props
.
environments
[
this
.
state
.
environmentIndex
];
...
...
@@ -64,12 +83,21 @@ class HubCreatePanel extends Component {
return
new
RegExp
(
HUB_NAME_PATTERN
).
test
(
this
.
state
.
name
)
&&
new
RegExp
(
hubAlphaPattern
).
test
(
this
.
state
.
name
);
};
setToEnvironmentOffset
=
offset
=>
{
_preloadImage
=
async
src
=>
{
const
img
=
new
Image
();
const
imgLoad
=
new
Promise
(
resolve
=>
img
.
addEventListener
(
"
load
"
,
resolve
));
img
.
srcset
=
src
;
await
imgLoad
;
};
setToEnvironmentOffset
=
async
offset
=>
{
const
numEnvs
=
this
.
props
.
environments
.
length
;
this
.
setState
(
state
=>
({
environmentIndex
:
((
state
.
environmentIndex
+
offset
)
%
this
.
props
.
environments
.
length
+
numEnvs
)
%
numEnvs
}));
const
environmentIndex
=
((
this
.
state
.
environmentIndex
+
offset
)
%
numEnvs
+
numEnvs
)
%
numEnvs
;
const
environmentThumbnail
=
this
.
_getEnvironmentThumbnail
(
environmentIndex
);
await
this
.
_preloadImage
(
environmentThumbnail
.
srcset
);
this
.
setState
({
environmentIndex
});
};
setToNextEnvironment
=
()
=>
{
...
...
@@ -88,6 +116,7 @@ class HubCreatePanel extends Component {
};
render
()
{
if
(
!
this
.
state
.
ready
)
return
null
;
const
{
formatMessage
}
=
this
.
props
.
intl
;
if
(
this
.
props
.
environments
.
length
==
0
)
{
...
...
@@ -99,9 +128,7 @@ class HubCreatePanel extends Component {
const
environmentTitle
=
meta
.
title
||
environment
.
name
;
const
environmentAuthor
=
(
meta
.
authors
||
[])[
0
];
const
environmentThumbnail
=
(
meta
.
images
||
[]).
find
(
i
=>
i
.
type
===
"
preview-thumbnail
"
)
||
{
srcset
:
deafault_scene_preview_thumbnail
};
const
environmentThumbnail
=
this
.
_getEnvironmentThumbnail
(
this
.
state
.
environmentIndex
);
const
formNameClassNames
=
classNames
(
"
create-panel__form__name
"
,
{
"
create-panel__form__name--expanded
"
:
this
.
state
.
expanded
...
...
@@ -118,10 +145,11 @@ class HubCreatePanel extends Component {
<
div
className
=
"
create-panel__form
"
>
<
div
className
=
"
create-panel__form__left-container
"
onClick
=
{()
=>
{
onClick
=
{
async
()
=>
{
if
(
this
.
state
.
expanded
)
{
this
.
shuffle
();
}
else
{
await
this
.
_preloadImage
(
this
.
_getEnvironmentThumbnail
(
this
.
state
.
environmentIndex
).
srcset
);
this
.
setState
({
expanded
:
true
});
}
}}
...
...
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