Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Self Service Frontend
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
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Fachschaften der Fakultät für Informatik
Identity Management
Self Service Frontend
Commits
ca558a5e
Verified
Commit
ca558a5e
authored
1 year ago
by
Adrian Paschkowski
Browse files
Options
Downloads
Patches
Plain Diff
Indicate if language change is loading
parent
433b7c0f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/components/i18n/AppIntlProvider.tsx
+12
-5
12 additions, 5 deletions
src/components/i18n/AppIntlProvider.tsx
src/components/widgets/Overlay.tsx
+25
-0
25 additions, 0 deletions
src/components/widgets/Overlay.tsx
src/constants.ts
+3
-1
3 additions, 1 deletion
src/constants.ts
with
40 additions
and
6 deletions
src/components/i18n/AppIntlProvider.tsx
+
12
−
5
View file @
ca558a5e
import
{
use
Ref
,
useState
}
from
"
react
"
;
import
{
use
Effect
,
useState
}
from
"
react
"
;
import
{
IntlProvider
}
from
"
react-intl
"
;
import
type
{
WithChildren
}
from
"
../../utils/types
"
;
import
Logger
from
"
../../Logger
"
;
...
...
@@ -7,6 +7,7 @@ import LoadingIndicator from "../widgets/LoadingIndicator";
import
Events
from
"
../../data/events/Events
"
;
import
{
EventTypes
}
from
"
../../data/events/eventTypes
"
;
import
useEvents
from
"
../../data/events/useEvents
"
;
import
Overlay
from
"
../widgets/Overlay
"
;
const
TAG
=
"
AppIntlProvider
"
;
...
...
@@ -14,21 +15,22 @@ export type IntlMessageMap = Record<string, string>;
export
default
function
AppIntlProvider
({
children
}:
WithChildren
)
{
const
language
=
useLanguageStore
(
s
=>
s
.
language
);
const
previousLanguage
=
useRef
<
string
|
null
>
(
null
);
const
[
messages
,
setMessages
]
=
useState
<
IntlMessageMap
|
null
>
(
null
);
const
[
isLoading
,
setLoading
]
=
useState
<
boolean
>
(
false
);
useEvents
(
data
=>
{
switch
(
data
.
type
)
{
case
EventTypes
.
LANGUAGE_LOAD_SUCCESS
:
setMessages
(
data
.
language
);
setLoading
(
false
);
break
;
}
});
if
(
language
!==
previousLanguage
.
current
)
{
previousLanguage
.
current
=
language
;
useEffect
(()
=>
{
loadLanguage
(
language
);
}
setLoading
(
true
);
},
[
language
]);
if
(
!
messages
)
{
return
<
LoadingIndicator
className
=
"font-bold text-2xl mt-16"
>
Loading…
</
LoadingIndicator
>;
...
...
@@ -37,6 +39,9 @@ export default function AppIntlProvider({ children }: WithChildren) {
return
(
<
IntlProvider
locale
=
{
language
}
messages
=
{
messages
}
>
{
children
}
<
Overlay
isVisible
=
{
isLoading
}
>
<
LoadingIndicator
className
=
"font-bold text-2xl"
>
Loading Language…
</
LoadingIndicator
>
</
Overlay
>
</
IntlProvider
>
);
}
...
...
@@ -47,6 +52,8 @@ export function preloadActiveLanguage() {
function
loadLanguage
(
lang
:
string
)
{
loadLanguageFile
(
lang
)
// TODO debug
// .then(l => new Promise<IntlMessageMap>(r => setTimeout(() => r(l), 2000)))
.
then
(
language
=>
Events
.
emit
(
EventTypes
.
LANGUAGE_LOAD_SUCCESS
,
{
language
}))
.
catch
(
error
=>
{
Events
.
emit
(
EventTypes
.
LANGUAGE_LOAD_FAIL
,
{
error
:
error
as
Error
});
...
...
This diff is collapsed.
Click to expand it.
src/components/widgets/Overlay.tsx
0 → 100644
+
25
−
0
View file @
ca558a5e
import
type
{
WithChildren
}
from
"
../../utils/types
"
;
import
classNames
from
"
classnames
"
;
import
{
Z_INDEXES
}
from
"
../../constants
"
;
interface
Props
{
isVisible
:
boolean
;
}
export
default
function
Overlay
({
isVisible
,
children
}:
WithChildren
<
Props
>
)
{
return
(
<
div
className
=
{
classNames
(
"
fixed inset-0 bg-black/75 text-white grid place-items-center transition-opacity text-2xl
"
,
{
"
opacity-0 pointer-events-none
"
:
!
isVisible
,
"
opacity-100
"
:
isVisible
,
}
)
}
style
=
{
{
zIndex
:
Z_INDEXES
.
GLOBAL_OVERLAY
,
}
}
>
{
children
}
</
div
>
);
}
This diff is collapsed.
Click to expand it.
src/constants.ts
+
3
−
1
View file @
ca558a5e
...
...
@@ -16,7 +16,9 @@ export const STYLES = {
export
const
NO_BREAK_SPACE
=
"
\
u00a0
"
;
export
const
Z_INDEXES
=
{};
export
const
Z_INDEXES
=
{
GLOBAL_OVERLAY
:
10000
,
};
export
const
API_OAUTH_AUTHORIZE_URL
=
(
type
:
string
)
=>
`
${
API_BASE_URL
}
/auth/
${
type
}
/authorize?redirect_uri=
${
encodeURIComponent
(
`
${
APP_BASE_URL
}
/auth/
${
type
}
/callback`
)}
`
;
...
...
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